./PaxHeaders.29769/statistics-1.4.10000644000000000000000000000013213444214613013546 xustar0030 mtime=1553013131.337844684 30 atime=1553013131.677852968 30 ctime=1553013131.677852968 statistics-1.4.1/0000755000175000017500000000000013444214613014177 5ustar00johndjohnd00000000000000statistics-1.4.1/PaxHeaders.29769/PKG_DEL0000644000000000000000000000006213443447555014534 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/PKG_DEL0000644000175000017500000000144413443447555015246 0ustar00johndjohnd00000000000000## three problems: ## - the directory returned by 'mfilename' must not be added also ## (endless loop) ## - 'genpath' of Octave 4.0 includes directories indiscriminately, ## e.g. 'private' directories ## - PKG_ADD (and PKG_DEL?) is run during installation, too, from the ## root directory of the package, where no such subdirectories ## exist. if exist ("isfolder") == 0 if (isdir (fullfile (fileparts (mfilename ("fullpath")), "base"))) rmpath (fullfile (fileparts (mfilename ("fullpath")), {"base", "distributions", "models", "tests"}){:}); endif else if (isfolder (fullfile (fileparts (mfilename ("fullpath")), "base"))) rmpath (fullfile (fileparts (mfilename ("fullpath")), {"base", "distributions", "models", "tests"}){:}); endif endif statistics-1.4.1/PaxHeaders.29769/DESCRIPTION0000644000000000000000000000006213443447555015212 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/DESCRIPTION0000644000175000017500000000051313443447555015720 0ustar00johndjohnd00000000000000Name: statistics Version: 1.4.1 Date: 2019-03-17 Author: various authors Maintainer: Octave-Forge community Title: Statistics Description: Additional statistics functions for Octave. Categories: Statistics Depends: octave (>= 4.0.0), io (>= 1.0.18) License: GPLv3+, public domain Url: http://octave.sf.net statistics-1.4.1/PaxHeaders.29769/Makefile0000644000000000000000000000006213443447555015144 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/Makefile0000644000175000017500000002143513443447555015660 0ustar00johndjohnd00000000000000## Copyright 2015-2016 Carnë Draug ## Copyright 2015-2016 Oliver Heimlich ## Copyright 2017 Julien Bect ## Copyright 2017 Olaf Till ## Copyright 2018 John Donoghue ## ## Copying and distribution of this file, with or without modification, ## are permitted in any medium without royalty provided the copyright ## notice and this notice are preserved. This file is offered as-is, ## without any warranty. TOPDIR := $(shell pwd) ## Some basic tools (can be overriden using environment variables) SED ?= sed TAR ?= tar GREP ?= grep CUT ?= cut TR ?= tr ## Note the use of ':=' (immediate set) and not just '=' (lazy set). ## http://stackoverflow.com/a/448939/1609556 package := $(shell $(GREP) "^Name: " DESCRIPTION | $(CUT) -f2 -d" " | \ $(TR) '[:upper:]' '[:lower:]') version := $(shell $(GREP) "^Version: " DESCRIPTION | $(CUT) -f2 -d" ") ## These are the paths that will be created for the releases. target_dir := target release_dir := $(target_dir)/$(package)-$(version) release_tarball := $(target_dir)/$(package)-$(version).tar.gz html_dir := $(target_dir)/$(package)-html html_tarball := $(target_dir)/$(package)-html.tar.gz ## Using $(realpath ...) avoids problems with symlinks due to bug ## #50994 in Octaves scripts/pkg/private/install.m. But at least the ## release directory above is needed in the relative form, for 'git ## archive --format=tar --prefix=$(release_dir). real_target_dir := $(realpath .)/$(target_dir) installation_dir := $(real_target_dir)/.installation package_list := $(installation_dir)/.octave_packages install_stamp := $(installation_dir)/.install_stamp ## These can be set by environment variables which allow to easily ## test with different Octave versions. ifndef OCTAVE OCTAVE := octave endif OCTAVE := $(OCTAVE) --no-gui --silent --no-history --norc MKOCTFILE ?= mkoctfile ## Command used to set permissions before creating tarballs FIX_PERMISSIONS ?= chmod -R a+rX,u+w,go-w,ug-s ## Detect which VCS is used vcs := $(if $(wildcard .hg),hg,$(if $(wildcard .git),git,unknown)) ifeq ($(vcs),hg) release_dir_dep := .hg/dirstate endif ifeq ($(vcs),git) release_dir_dep := .git/index endif ## .PHONY indicates targets that are not filenames ## (https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html) .PHONY: help ## make will display the command before runnning them. Use @command ## to not display it (makes specially sense for echo). help: @echo "Targets:" @echo " dist - Create $(release_tarball) for release." @echo " html - Create $(html_tarball) for release." @echo " release - Create both of the above and show md5sums." @echo " install - Install the package in $(installation_dir), where it is not visible in a normal Octave session." @echo " check - Execute package tests." @echo " doctest - Test the help texts with the doctest package." @echo " run - Run Octave with the package installed in $(installation_dir) in the path." @echo " clean - Remove everything made with this Makefile." ## ## Recipes for release tarballs (package + html) ## .PHONY: release dist html clean-tarballs clean-unpacked-release ## To make a release, build the distribution and html tarballs. release: dist html md5sum $(release_tarball) $(html_tarball) @echo "Upload @ https://sourceforge.net/p/octave/package-releases/new/" @echo " and note the changeset the release corresponds to" ## dist and html targets are only PHONY/alias targets to the release ## and html tarballs. dist: $(release_tarball) html: $(html_tarball) ## An implicit rule with a recipe to build the tarballs correctly. %.tar.gz: % $(TAR) -c -f - --posix -C "$(target_dir)/" "$(notdir $<)" | gzip -9n > "$@" clean-tarballs: @echo "## Cleaning release tarballs (package + html)..." -$(RM) $(release_tarball) $(html_tarball) @echo ## Create the unpacked package. ## ## Notes: ## * having ".hg/dirstate" (or ".git/index") as a prerequesite means it is ## only rebuilt if we are at a different commit. ## * the variable RM usually defaults to "rm -f" ## * having this recipe separate from the one that makes the tarball ## makes it easy to have packages in alternative formats (such as zip) ## * note that if a commands needs to be run in a specific directory, ## the command to "cd" needs to be on the same line. Each line restores ## the original working directory. $(release_dir): $(release_dir_dep) -$(RM) -r "$@" ifeq (${vcs},hg) hg archive --exclude ".hg*" --type files "$@" endif ifeq (${vcs},git) git archive --format=tar --prefix="$@/" HEAD | $(TAR) -x $(RM) "$@/.gitignore" endif ## Don't fall back to run the supposed necessary contents of ## 'bootstrap' here. Users are better off if they provide ## 'bootstrap'. Administrators, checking build reproducibility, can ## put in the missing 'bootstrap' file if they feel they know its ## necessary contents. ifneq (,$(wildcard src/bootstrap)) cd "$@/src" && ./bootstrap && $(RM) -r "autom4te.cache" endif ## Uncomment this if your src/Makefile.in has these targets for ## pre-building something for the release (e.g. documentation). # cd "$@/src" && ./configure && $(MAKE) prebuild && \ # $(MAKE) distclean && $(RM) Makefile ## ${FIX_PERMISSIONS} "$@" run_in_place = $(OCTAVE) --eval ' pkg ("local_list", "$(package_list)"); ' \ --eval ' pkg ("load", "$(package)"); ' html_options = --eval 'options = get_html_options ("octave-forge");' ## Uncomment this for package documentation. # html_options = --eval 'options = get_html_options ("octave-forge");' \ # --eval 'options.package_doc = "$(package).texi";' $(html_dir): $(install_stamp) $(RM) -r "$@"; $(run_in_place) \ --eval ' pkg load generate_html; ' \ $(html_options) \ --eval ' generate_package_html ("$(package)", "$@", options); '; $(FIX_PERMISSIONS) "$@"; clean-unpacked-release: @echo "## Cleaning unpacked release tarballs (package + html)..." -$(RM) -r $(release_dir) $(html_dir) @echo ## ## Recipes for installing the package. ## .PHONY: install clean-install octave_install_commands = \ ' llist_path = pkg ("local_list"); \ mkdir ("$(installation_dir)"); \ load (llist_path); \ local_packages(cellfun (@ (x) strcmp ("$(package)", x.name), local_packages)) = []; \ save ("$(package_list)", "local_packages"); \ pkg ("local_list", "$(package_list)"); \ pkg ("prefix", "$(installation_dir)", "$(installation_dir)"); \ pkg ("install", "-local", "-verbose", "$(release_tarball)"); ' ## Install unconditionally. Maybe useful for testing installation with ## different versions of Octave. install: $(release_tarball) @echo "Installing package under $(installation_dir) ..." $(OCTAVE) --eval $(octave_install_commands) touch $(install_stamp) ## Install only if installation (under target/...) is not current. $(install_stamp): $(release_tarball) @echo "Installing package under $(installation_dir) ..." $(OCTAVE) --eval $(octave_install_commands) touch $(install_stamp) clean-install: @echo "## Cleaning installation under $(installation_dir) ..." -$(RM) -r $(installation_dir) @echo ## ## Recipes for testing purposes ## .PHONY: run doctest check clean-check ## Start an Octave session with the package directories on the path for ## interactice test of development sources. run: $(install_stamp) $(run_in_place) --persist ## Test example blocks in the documentation. Needs doctest package ## https://octave.sourceforge.io/doctest/index.html doctest: $(install_stamp) $(run_in_place) --eval 'pkg load doctest;' \ --eval "targets = '$(shell (ls inst; ls src | $(GREP) .oct) | $(CUT) -f2 -d@ | $(CUT) -f1 -d.)';" \ --eval "targets = strsplit (targets, ' '); doctest (targets);" ## Test package. orig_octave_test_commands = \ ' dirs = {"inst", "src"}; \ dirs(cellfun (@ (x) ! isdir (x), dirs)) = []; \ if (isempty (dirs)) error ("no \"inst\" or \"src\" directory"); exit (1); \ else __run_test_suite__ (dirs, {}); endif ' octave_test_commands = \ ' pkgs = pkg("list", "$(package)"); \ dirs = {pkgs{1}.dir}; \ __run_test_suite__ (dirs, {}); ' ## the following works, too, but provides no overall summary output as ## __run_test_suite__ does: ## ## else cellfun (@runtests, horzcat (cellfun (@ (dir) ostrsplit (([~, dirs] = system (sprintf ("find %s -type d", dir))), "\n\r", true), dirs, "UniformOutput", false){:})); endif ' check: $(install_stamp) $(run_in_place) --eval $(octave_test_commands) clean-check: @echo "## Removing fntests.log ..." test -e $(target_dir)/fntests.log && rm -f $(target_dir)/fntests.log || true ## ## CLEAN ## .PHONY: clean clean: clean-tarballs clean-unpacked-release clean-install clean-check @echo "## Removing target directory (if empty)..." -rmdir $(target_dir) @echo @echo "## Cleaning done" @echo statistics-1.4.1/PaxHeaders.29769/inst0000644000000000000000000000013113444214613014365 xustar0029 mtime=1553013131.23384215 30 atime=1553013131.677852968 30 ctime=1553013131.677852968 statistics-1.4.1/inst/0000755000175000017500000000000013444214613015154 5ustar00johndjohnd00000000000000statistics-1.4.1/inst/PaxHeaders.29769/pcacov.m0000644000000000000000000000006213443447555016112 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/pcacov.m0000644000175000017500000000453513443447555016630 0ustar00johndjohnd00000000000000## Copyright (C) 2013-2019 Fernando Damian Nieuwveldt ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version 3 ## of the License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{COEFF}]} = pcacov(@var{X}) ## @deftypefnx {Function File} {[@var{COEFF},@var{latent}]} = pcacov(@var{X}) ## @deftypefnx {Function File} {[@var{COEFF},@var{latent},@var{explained}]} = pcacov(@var{X}) ## Perform principal component analysis on the nxn covariance matrix X ## ## @itemize @bullet ## @item ## @var{COEFF} : a nxn matrix with columns containing the principal component coefficients ## @item ## @var{latent} : a vector containing the principal component variances ## @item ## @var{explained} : a vector containing the percentage of the total variance explained by each principal component ## ## @end itemize ## ## @subheading References ## ## @enumerate ## @item ## Jolliffe, I. T., Principal Component Analysis, 2nd Edition, Springer, 2002 ## ## @end enumerate ## @end deftypefn ## Author: Fernando Damian Nieuwveldt ## Description: Principal Components Analysis using a covariance matrix function [COEFF, latent, explained] = pcacov(X) [U,S,V] = svd(X); if nargout == 1 COEFF = U; elseif nargout == 2 COEFF = U; latent = diag(S); else COEFF = U; latent = diag(S); explained = 100*latent./sum(latent); end endfunction %!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 %! ]; %! covx = cov(X); %! [COEFF,latent,explained] = pcacov(covx) statistics-1.4.1/inst/PaxHeaders.29769/normstat.m0000644000000000000000000000006213443447555016506 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/normstat.m0000644000175000017500000000611113443447555017214 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{mn}, @var{v}] =} normstat (@var{m}, @var{s}) ## Compute mean and variance of the normal distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{m} is the mean of the normal distribution ## ## @item ## @var{s} is the standard deviation of the normal distribution. ## @var{s} must be positive ## @end itemize ## @var{m} and @var{s} must be of common size or one of them must be ## scalar ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{mn} is the mean of the normal distribution ## ## @item ## @var{v} is the variance of the normal distribution ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## m = 1:6; ## s = 0:0.2:1; ## [mn, v] = normstat (m, s) ## @end group ## ## @group ## [mn, v] = normstat (0, s) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the normal distribution function [mn, v] = normstat (m, s) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (m) && ! ismatrix (m)) error ("normstat: m must be a numeric matrix"); endif if (! isempty (s) && ! ismatrix (s)) error ("normstat: s must be a numeric matrix"); endif if (! isscalar (m) || ! isscalar (s)) [retval, m, s] = common_size (m, s); if (retval > 0) error ("normstat: m and s must be of common size or scalar"); endif endif # Set moments mn = m; v = s .* s; # Continue argument check k = find (! (s > 0) | ! (s < Inf)); if (any (k)) mn(k) = NaN; v(k) = NaN; endif endfunction %!test %! m = 1:6; %! s = 0.2:0.2:1.2; %! [mn, v] = normstat (m, s); %! expected_v = [0.0400, 0.1600, 0.3600, 0.6400, 1.0000, 1.4400]; %! assert (mn, m); %! assert (v, expected_v, 0.001); %!test %! s = 0.2:0.2:1.2; %! [mn, v] = normstat (0, s); %! expected_mn = [0, 0, 0, 0, 0, 0]; %! expected_v = [0.0400, 0.1600, 0.3600, 0.6400, 1.0000, 1.4400]; %! assert (mn, expected_mn, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/fullfact.m0000644000000000000000000000006213443447555016437 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/fullfact.m0000644000175000017500000000140413443447555017145 0ustar00johndjohnd00000000000000## Author: Paul Kienzle ## This program is granted to the public domain. ## -*- texinfo -*- ## @deftypefn {Function File} fullfact (@var{N}) ## Full factorial design. ## ## If @var{N} is a scalar, return the full factorial design with @var{N} binary ## choices, 0 and 1. ## ## If @var{N} is a vector, return the full factorial design with choices 1 ## through @var{n_i} for each factor @var{i}. ## ## @end deftypefn function A = fullfact(n) if length(n) == 1 % combinatorial design with n either/or choices A = fullfact(2*ones(1,n))-1; else % combinatorial design with n(i) choices per level A = [1:n(end)]'; for i=length(n)-1:-1:1 A = [kron([1:n(i)]',ones(rows(A),1)), repmat(A,n(i),1)]; end end endfunction statistics-1.4.1/inst/PaxHeaders.29769/casewrite.m0000644000000000000000000000006213443447555016625 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/casewrite.m0000644000175000017500000000420113443447555017331 0ustar00johndjohnd00000000000000## Copyright (C) 2008 Bill Denney ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {} casewrite (@var{strmat}, @var{filename}) ## Write case names to an ascii file. ## ## Essentially, this writes all lines from @var{strmat} to ## @var{filename} (after deblanking them). ## @seealso{caseread, tblread, tblwrite, csv2cell, cell2csv, fopen} ## @end deftypefn ## Author: Bill Denney ## Description: Write strings from a file function names = casewrite (s="", f="") ## Check arguments if nargin != 2 print_usage (); endif if isempty (f) ## FIXME: open a file dialog box in this case when a file dialog box ## becomes available error ("casewrite: filename must be given") endif if isempty (s) error ("casewrite: strmat must be given") elseif ! ischar (s) error ("casewrite: strmat must be a character matrix") elseif ndims (s) != 2 error ("casewrite: strmat must be two dimensional") endif [fid msg] = fopen (f, "wt"); if fid < 0 || (! isempty (msg)) error ("casewrite: cannot open %s for writing: %s", f, msg); endif for i = 1:rows (s) status = fputs (fid, sprintf ("%s\n", deblank (s(i,:)))); endfor if (fclose (fid) < 0) error ("casewrite: error closing f") endif endfunction %!test %! fname = [tempname() ".dat"]; %! unwind_protect %! s = ["a ";"bcd";"ef "]; %! casewrite (s, fname) %! names = caseread (fname); %! unwind_protect_cleanup %! unlink (fname); %! end_unwind_protect %! assert(names, s); statistics-1.4.1/inst/PaxHeaders.29769/geostat.m0000644000000000000000000000006213443447555016305 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/geostat.m0000644000175000017500000000455013443447555017020 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} geostat (@var{p}) ## Compute mean and variance of the geometric distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{p} is the rate parameter of the geometric distribution. The ## elements of @var{p} must be probabilities ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the geometric distribution ## ## @item ## @var{v} is the variance of the geometric distribution ## @end itemize ## ## @subheading Example ## ## @example ## @group ## p = 1 ./ (1:6); ## [m, v] = geostat (p) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the geometric distribution function [m, v] = geostat (p) # Check arguments if (nargin != 1) print_usage (); endif if (! isempty (p) && ! ismatrix (p)) error ("geostat: p must be a numeric matrix"); endif # Calculate moments q = 1 - p; m = q ./ p; v = q ./ (p .^ 2); # Continue argument check k = find (! (p >= 0) | ! (p <= 1)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!test %! p = 1 ./ (1:6); %! [m, v] = geostat (p); %! assert (m, [0, 1, 2, 3, 4, 5], 0.001); %! assert (v, [0, 2, 6, 12, 20, 30], 0.001); statistics-1.4.1/inst/PaxHeaders.29769/nanmax.m0000644000000000000000000000006213443447555016121 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nanmax.m0000644000175000017500000000342313443447555016632 0ustar00johndjohnd00000000000000## Copyright (C) 2001 Paul Kienzle ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{v}, @var{idx}] =} nanmax (@var{X}) ## @deftypefnx{Function File} {[@var{v}, @var{idx}] =} nanmax (@var{X}, @var{Y}) ## Find the maximal element while ignoring NaN values. ## ## @code{nanmax} is identical to the @code{max} function except that NaN values ## are ignored. If all values in a column are NaN, the maximum is ## returned as NaN rather than []. ## ## @seealso{max, nansum, nanmin, nanmean, nanmedian} ## @end deftypefn function [v, idx] = nanmax (X, Y, DIM) if nargin < 1 || nargin > 3 print_usage; elseif nargin == 1 || (nargin == 2 && isempty(Y)) nanvals = isnan(X); X(nanvals) = -Inf; [v, idx] = max (X); v(all(nanvals)) = NaN; elseif (nargin == 3 && isempty(Y)) nanvals = isnan(X); X(nanvals) = -Inf; [v, idx] = max (X,[],DIM); v(all(nanvals,DIM)) = NaN; else Xnan = isnan(X); Ynan = isnan(Y); X(Xnan) = -Inf; Y(Ynan) = -Inf; if (nargin == 3) [v, idx] = max(X,Y,DIM); else [v, idx] = max(X,Y); endif v(Xnan & Ynan) = NaN; endif endfunction statistics-1.4.1/inst/PaxHeaders.29769/repanova.m0000644000000000000000000000006213443447555016452 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/repanova.m0000644000175000017500000001002613443447555017160 0ustar00johndjohnd00000000000000## Copyright (C) 2011 Kyle Winfree ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{pval}, @var{table}, @var{st}] =} repanova (@var{X}, @var{cond}) ## @deftypefnx {Function File} {[@var{pval}, @var{table}, @var{st}] =} repanova (@var{X}, @var{cond}, ['string' | 'cell']) ## Perform a repeated measures analysis of variance (Repeated ANOVA). ## X is formated such that each row is a subject and each column is a condition. ## ## condition is typically a point in time, say t=1 then t=2, etc ## condition can also be thought of as groups. ## ## The optional flag can be either 'cell' or 'string' and reflects ## the format of the table returned. Cell is the default. ## ## NaNs are ignored using nanmean and nanstd. ## ## This fuction does not currently support multiple columns of the same ## condition! ## @end deftypefn function [p, table, st] = repanova(varargin) switch nargin case 0 error('Too few inputs.'); case 1 X = varargin{1}; for c = 1:size(X, 2) condition{c} = ['time', num2str(c)]; end option = 'cell'; case 2 X = varargin{1}; condition = varargin{2}; option = 'cell'; case 3 X = varargin{1}; condition = varargin{2}; option = varargin{3}; otherwise error('Too many inputs.'); end % Find the means of the subjects and measures, ignoring any NaNs u_subjects = nanmean(X,2); u_measures = nanmean(X,1); u_grand = nansum(nansum(X)) / (size(X,1) * size(X,2)); % Differences between rows will be reflected in SS subjects, differences % between columns will be reflected in SS_within subjects. N = size(X,1); % number of subjects J = size(X,2); % number of samples per subject SS_measures = N * nansum((u_measures - u_grand).^2); SS_subjects = J * nansum((u_subjects - u_grand).^2); SS_total = nansum(nansum((X - u_grand).^2)); SS_error = SS_total - SS_measures - SS_subjects; df_measures = J - 1; df_subjects = N - 1; df_grand = (N*J) - 1; df_error = df_grand - df_measures - df_subjects; MS_measures = SS_measures / df_measures; MS_subjects = SS_subjects / df_subjects; MS_error = SS_error / df_error; % variation expected as a result of sampling error alone F = MS_measures / MS_error; p = 1 - fcdf(F, df_measures, df_error); % Probability of F given equal means. if strcmp(option, 'string') table = [sprintf('\nSource\tSS\tdf\tMS\tF\tProb > F'), ... sprintf('\nSubject\t%g\t%i\t%g', SS_subjects, df_subjects, MS_subjects), ... sprintf('\nMeasure\t%g\t%i\t%g\t%g\t%g', SS_measures, df_measures, MS_measures, F, p), ... sprintf('\nError\t%g\t%i\t%g', SS_error, df_error, MS_error), ... sprintf('\n')]; else table = {'Source', 'Partial SS', 'df', 'MS', 'F', 'Prob > F'; ... 'Subject', SS_subjects, df_subjects, MS_subjects, '', ''; ... 'Measure', SS_measures, df_measures, MS_measures, F, p}; end st.gnames = condition'; % this is the same struct format used in anova1 st.n = repmat(N, 1, J); st.source = 'anova1'; % it cannot be assumed that 'repanova' is a supported source for multcompare st.means = u_measures; st.df = df_error; st.s = sqrt(MS_error); end % This function was created with guidance from the following websites: % http://courses.washington.edu/stat217/rmANOVA.html % http://grants.hhp.coe.uh.edu/doconnor/PEP6305/Topic%20010%20Repeated%20Measures.htm statistics-1.4.1/inst/PaxHeaders.29769/tricdf.m0000644000000000000000000000006213443447555016112 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/tricdf.m0000644000175000017500000001027513443447555016626 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1997-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} tricdf (@var{x}, @var{a}, @var{b}, @var{c}) ## Compute the cumulative distribution function (CDF) at @var{x} of the ## triangular distribution with parameters @var{a}, @var{b}, and @var{c} ## on the interval [@var{a}, @var{b}]. ## @end deftypefn ## Author: Dag Lyberg ## Description: CDF of the triangle distribution function cdf = tricdf (x, a, b, c) if (nargin != 4) print_usage (); endif if (! isscalar (a) || ! isscalar (b) || ! isscalar (c)) [retval, x, a, b, c] = common_size (x, a, b, c); if (retval > 0) error ("tricdf: X, A, B, and C must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (a) || iscomplex (b) || iscomplex (c)) error ("tricdf: X, A, B, and C must not be complex"); endif if (isa (x, "single") || isa (a, "single") || isa (b, "single") || isa (c, "single")) cdf = zeros (size (x), "single"); else cdf = zeros (size (x)); endif k = isnan (x) | !(a < b) | !(c >= a) | !(c <= b) ; cdf(k) = NaN; k = (x > a) & (a < b) & (a <= c) & (c <= b); if (isscalar (a) && isscalar (b) && isscalar (c)) h = 2 / (b-a); k_temp = k & (c <= x); full_area = (c-a) * h / 2; cdf(k_temp) += full_area; k_temp = k & (a < x) & (x < c); area = (x(k_temp) - a).^2 * h; cdf(k_temp) += area; k_temp = k & (b <= x); full_area = (b-c) * h / 2; cdf(k_temp) += full_area; k_temp = k & (c < x) & (x < b); area = (b-x(k_temp)).^2 * h; cdf(k_temp) += full_area - area; else h = 2 ./ (b-a); k_temp = k & (c <= x); full_area = (c(k_temp)-a(k_temp)) .* h(k_temp) / 2; cdf(k_temp) += full_area; k_temp = k & (a <= x) & (x < c); area = (x(k_temp) - a(k_temp)).^2 .* h(k_temp); cdf(k_temp) += area; k_temp = k & (b <= x); full_area = (b(k_temp)-c(k_temp)) .* h(k_temp) / 2; cdf(k_temp) += full_area; k_temp = k & (c <= x) & (x < b); area = (b(k_temp)-x(k_temp)).^2 .* h(k_temp); cdf(k_temp) += full_area - area; endif endfunction %!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 (tricdf (x, ones (1,7), 2*ones (1,7), 1.5*ones (1,7)), y, eps) %!assert (tricdf (x, 1*ones (1,7), 2, 1.5), y, eps) %!assert (tricdf (x, 1, 2*ones (1,7), 1.5), y, eps) %!assert (tricdf (x, 1, 2, 1.5*ones (1,7)), y, eps) %!assert (tricdf (x, 1, 2, 1.5), y, eps) %!assert (tricdf (x, [1, 1, NaN, 1, 1, 1, 1], 2, 1.5), [y(1:2), NaN, y(4:7)], eps) %!assert (tricdf (x, 1, 2*[1, 1, NaN, 1, 1, 1, 1], 1.5), [y(1:2), NaN, y(4:7)], eps) %!assert (tricdf (x, 1, 2, 1.5*[1, 1, NaN, 1, 1, 1, 1]), [y(1:2), NaN, y(4:7)], eps) %!assert (tricdf ([x, NaN], 1, 2, 1.5), [y, NaN], eps) ## Test class of input preserved %!assert (tricdf (single ([x, NaN]), 1, 2, 1.5), single ([y, NaN]), eps('single')) %!assert (tricdf ([x, NaN], single (1), 2, 1.5), single ([y, NaN]), eps('single')) %!assert (tricdf ([x, NaN], 1, single (2), 1.5), single ([y, NaN]), eps('single')) %!assert (tricdf ([x, NaN], 1, 2, single (1.5)), single ([y, NaN]), eps('single')) ## Test input validation %!error tricdf () %!error tricdf (1) %!error tricdf (1,2) %!error tricdf (1,2,3) %!error tricdf (1,2,3,4,5) %!error tricdf (1, ones (3), ones (2), ones (2)) %!error tricdf (1, ones (2), ones (3), ones (2)) %!error tricdf (1, ones (2), ones (2), ones (3)) %!error tricdf (i, 2, 2, 2) %!error tricdf (2, i, 2, 2) %!error tricdf (2, 2, i, 2) %!error tricdf (2, 2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/vmrnd.m0000644000000000000000000000006213443447555015765 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/vmrnd.m0000644000175000017500000000474013443447555016501 0ustar00johndjohnd00000000000000## Copyright (C) 2009 Soren Hauberg ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} @var{theta} = vmrnd (@var{mu}, @var{k}) ## @deftypefnx{Function File} @var{theta} = vmrnd (@var{mu}, @var{k}, @var{sz}) ## Draw random angles from a Von Mises distribution with mean @var{mu} and ## concentration @var{k}. ## ## The Von Mises distribution has probability density function ## @example ## f (@var{x}) = exp (@var{k} * cos (@var{x} - @var{mu})) / @var{Z} , ## @end example ## where @var{Z} is a normalisation constant. ## ## The output, @var{theta}, is a matrix of size @var{sz} containing random angles ## drawn from the given Von Mises distribution. By default, @var{mu} is 0 ## and @var{k} is 1. ## @seealso{vmpdf} ## @end deftypefn function theta = vmrnd (mu = 0, k = 1, sz = 1) ## Check input if (!isreal (mu)) error ("vmrnd: first input must be a scalar"); endif if (!isreal (k) || k <= 0) error ("vmrnd: second input must be a real positive scalar"); endif if (isscalar (sz)) sz = [sz, sz]; elseif (!isvector (sz)) error ("vmrnd: third input must be a scalar or a vector"); endif ## Simulate! if (k < 1e-6) ## k is small: sample uniformly on circle theta = 2 * pi * rand (sz) - pi; else a = 1 + sqrt (1 + 4 * k.^2); b = (a - sqrt (2 * a)) / (2 * k); r = (1 + b^2) / (2 * b); N = prod (sz); notdone = true (N, 1); while (any (notdone)) u (:, notdone) = rand (3, N); z (notdone) = cos (pi * u (1, notdone)); f (notdone) = (1 + r * z (notdone)) ./ (r + z (notdone)); c (notdone) = k * (r - f (notdone)); notdone = (u (2, :) >= c .* (2 - c)) & (log (c) - log (u (2, :)) + 1 - c < 0); N = sum (notdone); endwhile theta = mu + sign (u (3, :) - 0.5) .* acos (f); theta = reshape (theta, sz); endif endfunction statistics-1.4.1/inst/PaxHeaders.29769/gevlike.m0000644000000000000000000000006213443447555016265 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gevlike.m0000644000175000017500000002722013443447555016777 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{nlogL}, @var{Grad}, @var{ACOV} =} gevlike (@var{params}, @var{data}) ## Compute the negative log-likelihood of data under the generalized extreme value (GEV) distribution with given parameter values. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{params} is the 3-parameter vector [@var{k}, @var{sigma}, @var{mu}], where @var{k} is the shape parameter of the GEV distribution, @var{sigma} is the scale parameter of the GEV distribution, and @var{mu} is the location parameter of the GEV distribution. ## @item ## @var{data} is the vector of given values. ## ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{nlogL} is the negative log-likelihood. ## @item ## @var{Grad} is the 3 by 1 gradient vector (first derivative of the negative log likelihood with respect to the parameter values) ## @item ## @var{ACOV} is the 3 by 3 Fisher information matrix (second derivative of the negative log likelihood with respect to the parameter values) ## ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = -5:-1; ## k = -0.2; ## sigma = 0.3; ## mu = 0.5; ## [L, ~, C] = gevlike ([k sigma mu], x); ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Rolf-Dieter Reiss and Michael Thomas. @cite{Statistical Analysis of Extreme Values with Applications to Insurance, Finance, Hydrology and Other Fields}. Chapter 1, pages 16-17, Springer, 2007. ## ## @end enumerate ## @seealso{gevcdf, gevfit, gevinv, gevpdf, gevrnd, gevstat} ## @end deftypefn ## Author: Nir Krakauer ## Description: Negative log-likelihood for the generalized extreme value distribution function [nlogL, Grad, ACOV] = gevlike (params, data) # Check arguments if (nargin != 2) print_usage; endif k = params(1); sigma = params(2); mu = params(3); #calculate negative log likelihood [nll, k_terms] = gevnll (data, k, sigma, mu); nlogL = sum(nll(:)); #optionally calculate the first and second derivatives of the negative log likelihood with respect to parameters if nargout > 1 [Grad, kk_terms] = gevgrad (data, k, sigma, mu, k_terms); if nargout > 2 ACOV = gevfim (data, k, sigma, mu, k_terms, kk_terms); endif endif endfunction function [nlogL, k_terms] = gevnll (x, k, sigma, mu) #internal function to calculate negative log likelihood for gevlike #no input checking done k_terms = []; a = (x - mu) ./ sigma; if all(k == 0) nlogL = exp(-a) + a + log(sigma); else aa = k .* a; if min(abs(aa)) < 1E-3 && max(abs(aa)) < 0.5 #use a series expansion to find the log likelihood more accurately when k is small k_terms = 1; sgn = 1; i = 0; while 1 sgn = -sgn; i++; newterm = (sgn / (i + 1)) * (aa .^ i); k_terms = k_terms + newterm; if max(abs(newterm)) <= eps break endif endwhile nlogL = exp(-a .* k_terms) + a .* (k + 1) .* k_terms + log(sigma); else b = 1 + aa; nlogL = b .^ (-1 ./ k) + (1 + 1 ./ k) .* log(b) + log(sigma); nlogL(b <= 0) = Inf; endif endif endfunction function [G, kk_terms] = gevgrad (x, k, sigma, mu, k_terms) #calculate the gradient of the negative log likelihood of data x with respect to the parameters of the generalized extreme value distribution for gevlike #no input checking done kk_terms = []; G = ones(3, 1); if k == 0 ##use the expressions for first derivatives that are the limits as k --> 0 a = (x - mu) ./ sigma; f = exp(-a) - 1; #k #g = -(2 * x .* (mu .* (1 - f) - sigma .* f) + 2 .* sigma .* mu .* f + (x.^2 + mu.^2).*(f - 1)) ./ (2 * f .* sigma .^ 2); g = a .* (1 + a .* f / 2); G(1) = sum(g(:)); #sigma g = (a .* f + 1) ./ sigma; G(2) = sum(g(:)); #mu g = f ./ sigma; G(3) = sum(g(:)); return endif a = (x - mu) ./ sigma; b = 1 + k .* a; if any (b <= 0) G(:) = 0; #negative log likelihood is locally infinite return endif #k c = log(b); d = 1 ./ k + 1; if nargin > 4 && ~isempty(k_terms) #use a series expansion to find the gradient more accurately when k is small aa = k .* a; f = exp(-a .* k_terms); kk_terms = 0.5; sgn = 1; i = 0; while 1 sgn = -sgn; i++; newterm = (sgn * (i + 1) / (i + 2)) * (aa .^ i); kk_terms = kk_terms + newterm; if max(abs(newterm)) <= eps break endif endwhile g = a .* ((a .* kk_terms) .* (f - 1 - k) + k_terms); else g = (c ./ k - a ./ b) ./ (k .* b .^ (1/k)) - c ./ (k .^ 2) + a .* d ./ b; endif %keyboard G(1) = sum(g(:)); #sigma if nargin > 4 && ~isempty(k_terms) #use a series expansion to find the gradient more accurately when k is small g = (1 - a .* (a .* k .* kk_terms - k_terms) .* (f - k - 1)) ./ sigma; else #g = (a .* b .^ (-d) - d .* k .* a ./ b + 1) ./ sigma; g = (a .* b .^ (-d) - (k + 1) .* a ./ b + 1) ./ sigma; endif G(2) = sum(g(:)); #mu if nargin > 4 && ~isempty(k_terms) #use a series expansion to find the gradient more accurately when k is small g = -(a .* k .* kk_terms - k_terms) .* (f - k - 1) ./ sigma; else #g = (b .^ (-d) - d .* k ./ b) ./ sigma; g = (b .^ (-d) - (k + 1) ./ b) ./ sigma; end G(3) = sum(g(:)); endfunction function ACOV = gevfim (x, k, sigma, mu, k_terms, kk_terms) #internal function to calculate the Fisher information matrix for gevlike #no input checking done #find the various second derivatives (used Maxima to help find the expressions) ACOV = ones(3); if k == 0 ##use the expressions for second derivatives that are the limits as k --> 0 #k, k a = (x - mu) ./ sigma; f = exp(-a); #der = (x .* (24 * mu .^ 2 .* sigma .* (f - 1) + 24 * mu .* sigma .^ 2 .* f - 12 * mu .^ 3) + x .^ 3 .* (8 * sigma .* (f - 1) - 12*mu) + x .^ 2 .* (-12 * sigma .^ 2 .* f + 24 * mu .* sigma .* (1 - f) + 18 * mu .^ 2) - 12 * mu .^ 2 .* sigma .^ 2 .* f + 8 * mu .^ 3 .* sigma .* (1 - f) + 3 * (x .^ 4 + mu .^ 4)) ./ (12 .* f .* sigma .^ 4); der = (a .^ 2) .* (a .* (a/4 - 2/3) .* f + 2/3 * a - 1); ACOV(1, 1) = sum(der(:)); #sigma, sigma der = (sigma .^ -2) .* (a .* ((a - 2) .* f + 2) - 1); ACOV(2, 2) = sum(der(:)); #mu, mu der = (sigma .^ -2) .* f; ACOV(3, 3) = sum(der(:)); #k, sigma #der = (x .^2 .* (2*sigma .* (f - 1) - 3*mu) + x .* (-2 * sigma .^ 2 .* f + 4 * mu .* sigma .* (1 - f) + 3 .* mu .^ 2) + 2 * mu .^ 2 .* sigma .* (f - 1) + 2 * mu * sigma .^ 2 * f + x .^ 3 - mu .^ 3) ./ (2 .* f .* sigma .^ 4); der = (-a ./ sigma) .* (a .* (1 - a/2) .* f - a + 1); ACOV(1, 2) = ACOV(2, 1) = sum(der(:)); #k, mu #der = (x .* (2*sigma .* (f - 1) - 2*mu) - 2 * f .* sigma .^ 2 + 2 .* mu .* sigma .* (1 - f) + x .^ 2 + mu .^ 2)./ (2 .* f .* sigma .^ 3); der = (-1 ./ sigma) .* (a .* (1 - a/2) .* f - a + 1); ACOV(1, 3) = ACOV(3, 1) = sum(der(:)); #sigma, mu der = (1 + (a - 1) .* f) ./ (sigma .^ 2); ACOV(2, 3) = ACOV(3, 2) = sum(der(:)); return endif #general case z = 1 + k .* (x - mu) ./ sigma; #k, k a = (x - mu) ./ sigma; b = k .* a + 1; c = log(b); d = 1 ./ k + 1; if nargin > 5 && ~isempty(kk_terms) #use a series expansion to find the derivatives more accurately when k is small aa = k .* a; f = exp(-a .* k_terms); kkk_terms = 2/3; sgn = 1; i = 0; while 1 sgn = -sgn; i++; newterm = (sgn * (i + 1) * (i + 2) / (i + 3)) * (aa .^ i); kkk_terms = kkk_terms + newterm; if max(abs(newterm)) <= eps break endif endwhile der = (a .^ 2) .* (a .* (a .* kk_terms .^ 2 - kkk_terms) .* f + a .* (1 + k) .* kkk_terms - 2 * kk_terms); else der = ((((c ./ k.^2) - (a ./ (k .* b))) .^ 2) ./ (b .^ (1 ./ k))) + ... ((-2*c ./ k.^3) + (2*a ./ (k.^2 .* b)) + ((a ./ b) .^ 2 ./ k)) ./ (b .^ (1 ./ k)) + ... 2*c ./ k.^3 - ... (2*a ./ (k.^2 .* b)) - (d .* (a ./ b) .^ 2); endif der(z <= 0) = 0; %no probability mass in this region ACOV(1, 1) = sum(der(:)); #sigma, sigma if nargin > 5 && ~isempty(kk_terms) #use a series expansion to find the derivatives more accurately when k is small der = ((-2*a .* k_terms + 4 * a .^ 2 .* k .* kk_terms - a .^ 3 .* (k .^ 2) .* kkk_terms) .* (f - k - 1) + f .* ((a .* (k_terms - a .* k .* kk_terms)) .^ 2) - 1) ./ (sigma .^ 2); else der = (sigma .^ -2) .* (... -2*a .* b .^ (-d) + ... d .* k .* a .^ 2 .* (b .^ (-d-1)) + ... 2 .* d .* k .* a ./ b - ... d .* (k .* a ./ b) .^ 2 - 1); end der(z <= 0) = 0; %no probability mass in this region ACOV(2, 2) = sum(der(:)); #mu, mu if nargin > 5 && ~isempty(kk_terms) #use a series expansion to find the derivatives involving k more accurately when k is small der = (f .* (a .* k .* kk_terms - k_terms) .^ 2 - a .* k .^ 2 .* kkk_terms .* (f - k - 1)) ./ (sigma .^ 2); else der = (d .* (sigma .^ -2)) .* (... k .* (b .^ (-d-1)) - ... (k ./ b) .^ 2); endif der(z <= 0) = 0; %no probability mass in this region ACOV(3, 3) = sum(der(:)); #k, mu if nargin > 5 && ~isempty(kk_terms) #use a series expansion to find the derivatives involving k more accurately when k is small der = 2 * a .* kk_terms .* (f - 1 - k) - a .^ 2 .* k_terms .* kk_terms .* f + k_terms; #k, a second derivative der = -der ./ sigma; else der = ( (b .^ (-d)) .* (c ./ k - a ./ b) ./ k - ... a .* (b .^ (-d-1)) + ... ((1 ./ k) - d) ./ b + a .* k .* d ./ (b .^ 2)) ./ sigma; endif der(z <= 0) = 0; %no probability mass in this region ACOV(1, 3) = ACOV(3, 1) = sum(der(:)); #k, sigma der = a .* der; der(z <= 0) = 0; %no probability mass in this region ACOV(1, 2) = ACOV(2, 1) = sum(der(:)); #sigma, mu if nargin > 5 && ~isempty(kk_terms) #use a series expansion to find the derivatives involving k more accurately when k is small der = ((-k_terms + 3 * a .* k .* kk_terms - (a .* k) .^ 2 .* kkk_terms) .* (f - k - 1) + a .* (k_terms - a .* k .* kk_terms) .^ 2 .* f) ./ (sigma .^ 2); else der = ( -(b .^ (-d)) + ... a .* k .* d .* (b .^ (-d-1)) + ... (d .* k ./ b) - a .* (k./b).^2 .* d) ./ (sigma .^ 2); end der(z <= 0) = 0; %no probability mass in this region ACOV(2, 3) = ACOV(3, 2) = sum(der(:)); endfunction %!test %! x = 1; %! k = 0.2; %! sigma = 0.3; %! mu = 0.5; %! [L, D, C] = gevlike ([k sigma mu], x); %! expected_L = 0.75942; %! expected_D = [0.53150; -0.67790; -2.40674]; %! expected_C = [-0.12547 1.77884 1.06731; 1.77884 16.40761 8.48877; 1.06731 8.48877 0.27979]; %! assert (L, expected_L, 0.001); %! assert (D, expected_D, 0.001); %! assert (C, expected_C, 0.001); %!test %! x = 1; %! k = 0; %! sigma = 0.3; %! mu = 0.5; %! [L, D, C] = gevlike ([k sigma mu], x); %! expected_L = 0.65157; %! expected_D = [0.54011; -1.17291; -2.70375]; %! expected_C = [0.090036 3.41229 2.047337; 3.412229 24.760027 12.510190; 2.047337 12.510190 2.098618]; %! assert (L, expected_L, 0.001); %! assert (D, expected_D, 0.001); %! assert (C, expected_C, 0.001); %!test %! x = -5:-1; %! k = -0.2; %! sigma = 0.3; %! mu = 0.5; %! [L, D, C] = gevlike ([k sigma mu], x); %! expected_L = 3786.4; %! expected_D = [6.4511e+04; -4.8194e+04; 3.0633e+03]; %! expected_C = -[-1.4937e+06 1.0083e+06 -6.1837e+04; 1.0083e+06 -8.1138e+05 4.0917e+04; -6.1837e+04 4.0917e+04 -2.0422e+03]; %! assert (L, expected_L, -0.001); %! assert (D, expected_D, -0.001); %! assert (C, expected_C, -0.001); statistics-1.4.1/inst/PaxHeaders.29769/grp2idx.m0000644000000000000000000000006213443447555016216 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/grp2idx.m0000644000175000017500000001135213443447555016727 0ustar00johndjohnd00000000000000## Copyright (C) 2015 Carnë Draug ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{g}, @var{gn}, @var{gl}] =} grp2idx (@var{s}) ## Get index for group variables. ## ## For variable @var{s}, returns the indices @var{g}, into the variable ## groups @var{gn} and @var{gl}. The first has a string representation of ## the groups while the later has its actual values. ## ## NaNs and empty strings in @var{s} appear as NaN in @var{g} and are ## not present on either @var{gn} and @var{gl}. ## ## @seealso{cellstr, num2str, unique} ## @end deftypefn function [g, gn, gl] = grp2idx (s) if (nargin != 1) print_usage (); endif s_was_char = false; if (ischar (s)) s_was_char = true; s = cellstr (s); elseif (! isvector (s)) error ("grp2idx: S must be a vector, cell array of strings, or char matrix"); endif ## FIXME once Octave core implements "sorted" and "stable" argument to ## unique(), we can use the following snippet so that we are fully ## Matlab compatible. # set_order = "sorted"; # if (iscellstr (s)) # set_order = "stable"; # endif # [gl, ~, g] = unique (s(:), set_order); [gl, ~, g] = unique (s(:)); ## handle NaNs and empty strings if (iscellstr (s)) ## FIXME empty strings appear at the front because unique is sorting ## them, so we only need to subtract one. However, when fix the ## order for strings (when core's unique has the stable option), ## then we'll have to come up with something clever. empties = cellfun (@isempty, s); if (any (empties)) g(empties) = NaN; g--; gl(1) = []; endif else ## This works fine because NaN come at the end after sorting, we don't ## have to worry about change on the indices. g(isnan (s)) = NaN; gl(isnan (gl)) = []; endif if (isargout (2)) if (iscellstr (gl)) gn = gl; elseif (iscell (gl)) gn = cellfun (@num2str, gl, "UniformOutput", false); else gn = arrayfun (@num2str, gl, "UniformOutput", false); endif endif if (isargout (3) && s_was_char) gl = char (gl); endif endfunction ## test boolean input and note that row or column vector makes no difference %!test %! in = [true false false true]; %! out = {[2; 1; 1; 2] {"0"; "1"} [false; true]}; %! assert (nthargout (1:3, @grp2idx, in), out) %! assert (nthargout (1:3, @grp2idx, in), nthargout (1:3, @grp2idx, in')) ## test that groups are ordered in boolean %!test %! assert (nthargout (1:3, @grp2idx, [false true]), %! {[1; 2] {"0"; "1"} [false; true]}); %! assert (nthargout (1:3, @grp2idx, [true false]), %! {[2; 1] {"0"; "1"} [false; true]}); ## test char matrix and cell array of strings %!assert (nthargout (1:3, @grp2idx, ["oct"; "sci"; "oct"; "oct"; "sci"]), %! {[1; 2; 1; 1; 2] {"oct"; "sci"} ["oct"; "sci"]}); ## and cell array of strings %!assert (nthargout (1:3, @grp2idx, {"oct"; "sci"; "oct"; "oct"; "sci"}), %! {[1; 2; 1; 1; 2] {"oct"; "sci"} {"oct"; "sci"}}); ## test numeric arrays %!assert (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 for NaN and empty strings %!assert (nthargout (1:3, @grp2idx, [2 2 3 NaN 2 3]), %! {[1; 1; 2; NaN; 1; 2] {"2"; "3"} [2; 3]}) %!assert (nthargout (1:3, @grp2idx, {"et" "sa" "sa" "" "et"}), %! {[1; 2; 2; NaN; 1] {"et"; "sa"} {"et"; "sa"}}) ## FIXME this fails because unique() in core does not yet have set_order ## option implemented. See code for code to uncomment once it is ## implemented in core. ## Test that order when handling strings is by order of appearance %!xtest <51928> assert (nthargout (1:3, @grp2idx, ["sci"; "oct"; "sci"; "oct"; "oct"]), %! {[1; 2; 1; 2; 2] {"sci"; "oct"} ["sci"; "oct"]}); %!xtest <51928> assert (nthargout (1:3, @grp2idx, {"sci"; "oct"; "sci"; "oct"; "oct"}), %! {[1; 2; 1; 2; 2] {"sci"; "oct"} {"sci"; "oct"}}); %!xtest <51928> assert (nthargout (1:3, @grp2idx, {"sa" "et" "et" "" "sa"}), %! {[1; 2; 2; NaN; 1] {"sa"; "et"} {"sa"; "et"}}) statistics-1.4.1/inst/PaxHeaders.29769/fisheriris.txt0000644000000000000000000000006213443447555017371 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/fisheriris.txt0000644000175000017500000000414213443447555020101 0ustar00johndjohnd00000000000000#Fisher iris data set #cf. https://en.wikipedia.org/wiki/Iris_flower_data_set #Type PW PL SW SL 0 2 14 33 50 1 24 56 31 67 1 23 51 31 69 0 2 10 36 46 1 20 52 30 65 1 19 51 27 58 2 13 45 28 57 2 16 47 33 63 1 17 45 25 49 2 14 47 32 70 0 2 16 31 48 1 19 50 25 63 0 1 14 36 49 0 2 13 32 44 2 12 40 26 58 1 18 49 27 63 2 10 33 23 50 0 2 16 38 51 0 2 16 30 50 1 21 56 28 64 0 4 19 38 51 0 2 14 30 49 2 10 41 27 58 2 15 45 29 60 0 2 14 36 50 1 19 51 27 58 0 4 15 34 54 1 18 55 31 64 2 10 33 24 49 0 2 14 42 55 1 15 50 22 60 2 14 39 27 52 0 2 14 29 44 2 12 39 27 58 1 23 57 32 69 2 15 42 30 59 1 20 49 28 56 1 18 58 25 67 2 13 44 23 63 2 15 49 25 63 2 11 30 25 51 1 21 54 31 69 1 25 61 36 72 2 13 36 29 56 1 21 55 30 68 0 1 14 30 48 0 3 17 38 57 2 14 44 30 66 0 4 15 37 51 2 17 50 30 67 1 22 56 28 64 1 15 51 28 63 2 15 45 22 62 2 14 46 30 61 2 11 39 25 56 1 23 59 32 68 1 23 54 34 62 1 25 57 33 67 0 2 13 35 55 2 15 45 32 64 1 18 51 30 59 1 23 53 32 64 2 15 45 30 54 1 21 57 33 67 0 2 13 30 44 0 2 16 32 47 1 18 60 32 72 1 18 49 30 61 0 2 12 32 50 0 1 11 30 43 2 14 44 31 67 0 2 14 35 51 0 4 16 34 50 2 10 35 26 57 1 23 61 30 77 2 13 42 26 57 0 1 15 41 52 1 18 48 30 60 2 13 42 27 56 0 2 15 31 49 0 4 17 39 54 2 16 45 34 60 2 10 35 20 50 0 2 13 32 47 2 13 54 29 62 0 2 15 34 51 2 10 50 22 60 0 1 15 31 49 0 2 15 37 54 2 12 47 28 61 2 13 41 28 57 0 4 13 39 54 1 20 51 32 65 2 15 49 31 69 2 13 40 25 55 0 3 13 23 45 0 3 15 38 51 2 14 48 28 68 0 2 15 35 52 1 25 60 33 63 2 15 46 28 65 0 3 14 34 46 2 18 48 32 59 2 16 51 27 60 1 18 55 30 65 0 5 17 33 51 1 22 67 38 77 1 21 66 30 76 1 13 52 30 67 2 13 40 28 61 2 11 38 24 55 0 2 14 34 52 1 20 64 38 79 0 6 16 35 50 1 20 67 28 77 2 12 44 26 55 0 3 14 30 48 0 2 19 34 48 1 14 56 26 61 0 2 12 40 58 1 18 48 28 62 2 15 45 30 56 0 2 14 32 46 0 4 15 44 57 1 24 56 34 63 1 16 58 30 72 1 21 59 30 71 1 18 56 29 63 2 12 42 30 57 1 23 69 26 77 2 13 56 29 66 0 2 15 34 52 2 10 37 24 55 0 2 15 31 46 1 19 61 28 74 0 3 13 35 50 1 18 63 29 73 2 15 47 31 67 2 13 41 30 56 2 13 43 29 64 1 22 58 30 65 0 3 14 35 51 2 14 47 29 61 1 19 53 27 64 0 2 16 34 48 1 20 50 25 57 2 13 40 23 55 0 2 17 34 54 1 24 51 28 58 0 2 15 37 53 statistics-1.4.1/inst/PaxHeaders.29769/histfit.m0000644000000000000000000000006213443447555016311 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/histfit.m0000644000175000017500000000422613443447555017024 0ustar00johndjohnd00000000000000## Copyright (C) 2003 Alberto Terruzzi ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} histfit (@var{data}, @var{nbins}) ## ## Plot histogram with superimposed fitted normal density. ## ## @code{histfit (@var{data}, @var{nbins})} plots a histogram of the values in ## the vector @var{data} using @var{nbins} bars in the histogram. With one input ## argument, @var{nbins} is set to the square root of the number of elements in ## data. ## ## Example ## ## @example ## histfit (randn (100, 1)) ## @end example ## ## @seealso{bar,hist, pareto} ## @end deftypefn ## Author: Alberto Terruzzi ## Version: 1.0 ## Created: 3 March 2004 function histfit (data,nbins) if nargin < 1 || nargin > 2 print_usage; endif if isvector (data) != 1 error ("data must be a vector."); endif row = sum(~isnan(data)); if nargin < 2 nbins = ceil(sqrt(row)); endif [n,xbin]=hist(data,nbins); if any(abs(diff(xbin,2)) > 10*max(abs(xbin))*eps) error("histfit bins must be uniform width"); endif mr = nanmean(data); ## Estimates the parameter, MU, of the normal distribution. sr = nanstd(data); ## Estimates the parameter, SIGMA, of the normal distribution. x=(-3*sr+mr:0.1*sr:3*sr+mr)';## Evenly spaced samples of the expected data range. [xb,yb] = bar(xbin,n); y = normpdf(x,mr,sr); binwidth = xbin(2)-xbin(1); y = row*y*binwidth; ## Normalization necessary to overplot the histogram. plot(xb,yb,";;b",x,y,";;r-"); ## Plots density line over histogram. endfunction statistics-1.4.1/inst/PaxHeaders.29769/raylcdf.m0000644000000000000000000000006213443447555016263 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/raylcdf.m0000644000175000017500000000617413443447555017002 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{p} =} raylcdf (@var{x}, @var{sigma}) ## Compute the cumulative distribution function of the Rayleigh ## distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} is the support. The elements of @var{x} must be non-negative. ## ## @item ## @var{sigma} is the parameter of the Rayleigh distribution. The elements ## of @var{sigma} must be positive. ## @end itemize ## @var{x} and @var{sigma} must be of common size or one of them must be ## scalar. ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{p} is the cumulative distribution of the Rayleigh distribution at ## each element of @var{x} and corresponding parameter @var{sigma}. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = 0:0.5:2.5; ## sigma = 1:6; ## p = raylcdf (x, sigma) ## @end group ## ## @group ## p = raylcdf (x, 0.5) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. pages 104 and 148, McGraw-Hill, New York, second edition, ## 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: CDF of the Rayleigh distribution function p = raylcdf (x, sigma) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (x) && ! ismatrix (x)) error ("raylcdf: x must be a numeric matrix"); endif if (! isempty (sigma) && ! ismatrix (sigma)) error ("raylcdf: sigma must be a numeric matrix"); endif if (! isscalar (x) || ! isscalar (sigma)) [retval, x, sigma] = common_size (x, sigma); if (retval > 0) error ("raylcdf: x and sigma must be of common size or scalar"); endif endif # Calculate cdf p = 1 - exp ((-x .^ 2) ./ (2 * sigma .^ 2)); # Continue argument check k = find (! (x >= 0) | ! (x < Inf) | ! (sigma > 0)); if (any (k)) p(k) = NaN; endif endfunction %!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 (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 (p, expected_p, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/monotone_smooth.m0000644000000000000000000000006213443447555020066 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/monotone_smooth.m0000644000175000017500000001246113443447555020601 0ustar00johndjohnd00000000000000## Copyright (C) 2011 Nir Krakauer ## Copyright (C) 2011 Carnë Draug ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{yy} =} monotone_smooth (@var{x}, @var{y}, @var{h}) ## Produce a smooth monotone increasing approximation to a sampled functional ## dependence ## ## A kernel method is used (an Epanechnikov smoothing kernel is ## applied to y(x); this is integrated to yield the monotone increasing form. ## See Reference 1 for details.) ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} is a vector of values of the independent variable. ## ## @item ## @var{y} is a vector of values of the dependent variable, of the same size as ## @var{x}. For best performance, it is recommended that the @var{y} already be ## fairly smooth, e.g. by applying a kernel smoothing to the original values if ## they are noisy. ## ## @item ## @var{h} is the kernel bandwidth to use. If @var{h} is not given, a "reasonable" ## value is computed. ## ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{yy} is the vector of smooth monotone increasing function values at @var{x}. ## ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = 0:0.1:10; ## y = (x .^ 2) + 3 * randn(size(x)); %typically non-monotonic from the added noise ## ys = ([y(1) y(1:(end-1))] + y + [y(2:end) y(end)])/3; %crudely smoothed via ## moving average, but still typically non-monotonic ## yy = monotone_smooth(x, ys); %yy is monotone increasing in x ## plot(x, y, '+', x, ys, x, yy) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Holger Dette, Natalie Neumeyer and Kay F. Pilz (2006), A simple nonparametric ## estimator of a strictly monotone regression function, @cite{Bernoulli}, 12:469-490 ## @item ## Regine Scheder (2007), R Package 'monoProc', Version 1.0-6, ## @url{http://cran.r-project.org/web/packages/monoProc/monoProc.pdf} (The ## implementation here is based on the monoProc function mono.1d) ## @end enumerate ## @end deftypefn ## Author: Nir Krakauer ## Description: Nonparametric monotone increasing regression function yy = monotone_smooth (x, y, h) if (nargin < 2 || nargin > 3) print_usage (); elseif (!isnumeric (x) || !isvector (x)) error ("first argument x must be a numeric vector") elseif (!isnumeric (y) || !isvector (y)) error ("second argument y must be a numeric vector") elseif (numel (x) != numel (y)) error ("x and y must have the same number of elements") elseif (nargin == 3 && (!isscalar (h) || !isnumeric (h))) error ("third argument 'h' (kernel bandwith) must a numeric scalar") endif n = numel(x); %set filter bandwidth at a reasonable default value, if not specified if (nargin != 3) s = std(x); h = s / (n^0.2); end x_min = min(x); x_max = max(x); y_min = min(y); y_max = max(y); %transform range of x to [0, 1] xl = (x - x_min) / (x_max - x_min); yy = ones(size(y)); %Epanechnikov smoothing kernel (with finite support) %K_epanech_kernel = @(z) (3/4) * ((1 - z).^2) .* (abs(z) < 1); K_epanech_int = @(z) mean(((abs(z) < 1)/2) - (3/4) * (z .* (abs(z) < 1) - (1/3) * (z.^3) .* (abs(z) < 1)) + (z < -1)); %integral of kernels up to t monotone_inverse = @(t) K_epanech_int((y - t) / h); %find the value of the monotone smooth function at each point in x niter_max = 150; %maximum number of iterations for estimating each value (should not be reached in most cases) for l = 1:n tmax = y_max; tmin = y_min; wmin = monotone_inverse(tmin); wmax = monotone_inverse(tmax); if (wmax == wmin) yy(l) = tmin; else wt = xl(l); iter_max_reached = 1; for i = 1:niter_max wt_scaled = (wt - wmin) / (wmax - wmin); tn = tmin + wt_scaled * (tmax - tmin) ; wn = monotone_inverse(tn); wn_scaled = (wn - wmin) / (wmax - wmin); %if (abs(wt-wn) < 1E-4) || (tn < (y_min-0.1)) || (tn > (y_max+0.1)) %% criterion for break in the R code -- replaced by the following line to %% hopefully be less dependent on the scale of y if (abs(wt_scaled-wn_scaled) < 1E-4) || (wt_scaled < -0.1) || (wt_scaled > 1.1) iter_max_reached = 0; break endif if wn > wt tmax = tn; wmax = wn; else tmin = tn; wmin = wn; endif endfor if iter_max_reached warning("at x = %g, maximum number of iterations %d reached without convergence; approximation may not be optimal", x(l), niter_max) endif yy(l) = tmin + (wt - wmin) * (tmax - tmin) / (wmax - wmin); endif endfor endfunction statistics-1.4.1/inst/PaxHeaders.29769/kmeans.m0000644000000000000000000000006213443447555016115 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/kmeans.m0000644000175000017500000004132713443447555016633 0ustar00johndjohnd00000000000000## Copyright (C) 2011 Soren Hauberg ## Copyright (C) 2012 Daniel Ward ## Copyright (C) 2015-2016 Lachlan Andrew ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {} {[@var{idx}, @var{centers}, @var{sumd}, @var{dist}] =} kmeans (@var{data}, @var{k}, @var{param1}, @var{value1}, @dots{}) ## Perform a @var{k}-means clustering of the @var{N}x@var{D} table @var{data}. ## If parameter @qcode{start} is specified, then @var{k} may be empty ## in which case @var{k} is set to the number of rows of @var{start}. ## ## The outputs are: ## @table @code ## @item @var{idx} ## An @var{N}x1 vector whose @var{i}th element is the class to which row @var{i} ## of @var{data} is assigned. ## ## @item @var{centers} ## A @var{K}x@var{D} array whose @var{i}th row is the centroid of cluster ## @var{i}. ## ## @item @var{sumd} ## A @var{k}x1 vector whose @var{i}th entry is the sum of the distances ## from samples in cluster @var{i} to centroid @var{i}. ## ## @item @var{dist} ## An @var{N}x@var{k} matrix whose @var{i}@var{j}th element is ## the distance from sample @var{i} to centroid @var{j}. ## @end table ## ## The following parameters may be placed in any order. Each parameter ## must be followed by its value. ## @table @code ## @item @var{Start} ## The initialization method for the centroids. ## @table @code ## @item @code{plus} ## (Default) The k-means++ algorithm. ## @item @code{sample} # A subset of @var{k} rows from @var{data}, ## sampled uniformly without replacement. ## @item @code{cluster} ## Perform a pilot clustering on 10% of the rows of @var{data}. ## @item @code{uniform} ## Each component of each centroid is drawn uniformly ## from the interval between the maximum and minimum values of that ## component within @var{data}. ## This performs poorly and is implemented only for Matlab compatibility. ## @item A ## A @var{k}x@var{D}x@var{r} matrix, where @var{r} is the number of ## replicates. ## @end table ## ## @item @var{Replicates} ## An positive integer specifying the number of independent clusterings to ## perform. ## The output values are the values for the best clustering, i.e., ## the one with the smallest value of @var{sumd}. ## If @var{Start} is numeric, then @var{Replicates} defaults to # (and must equal) the size of the third dimension of @var{Start}. ## Otherwise it defaults to 1. ## ## @item @var{MaxIter} ## The maximum number of iterations to perform for each replicate. ## If the maximum change of any centroid is less than 0.001, then ## the replicate terminates even if @var{MaxIter} iterations have no occurred. ## The default is 100. ## ## @item @var{Distance} ## The distance measure used for partitioning and calculating centroids. ## @table @code ## @item @qcode{sqeuclidean} ## The squared Euclidean distance, i.e., ## the sum of the squares of the differences between corresponding components. ## In this case, the centroid is the arithmetic mean of all samples in ## its cluster. ## This is the only distance for which this algorithm is truly "k-means". ## ## @item @qcode{cityblock} ## The sum metric, or L1 distance, i.e., ## the sum of the absolute differences between corresponding components. ## In this case, the centroid is the median of all samples in its cluster. ## This gives the k-medians algorithm. ## ## @item @qcode{cosine} ## (Documentation incomplete.) ## ## @item @qcode{correlation} ## (Documentation incomplete.) ## ## @item @qcode{hamming} ## The number of components in which the sample and the centroid differ. ## In this case, the centroid is the median of all samples in its cluster. ## Unlike Matlab, Octave allows non-logical @var{data}. ## ## @end table ## ## @item @var{EmptyAction} ## What to do when a centroid is not the closest to any data sample. ## @table @code ## @item @qcode{error} ## (Default) Throw an error. ## @item @qcode{singleton} ## Select the row of @var{data} that has the highest error and ## use that as the new centroid. ## @item @qcode{drop} ## Remove the centroid, and continue computation with one fewer centroid. ## The dimensions of the outputs @var{centroids} and @var{d} ## are unchanged, with values for omitted centroids replaced by NA. ## ## @end table ## @end table ## ## Example: ## ## [~,c] = kmeans (rand(10, 3), 2, "emptyaction", "singleton"); ## ## @seealso{linkage} ## @end deftypefn function [classes, centers, sumd, D] = kmeans (data, k, varargin) [reg, prop] = parseparams (varargin); ## defaults for options emptyaction = "error"; start = "plus"; replicates = 1; max_iter = 100; distance = "sqeuclidean"; replicates_set_explicitly = false; ## Remove rows containing NaN / NA, but record which rows are used data_idx = ! any (isnan (data), 2); original_rows = rows (data); data = data(data_idx,:); #used for getting the number of samples n_rows = rows (data); #used for convergence of the centroids err = 1; ## Input checking, validate the matrix if (! isnumeric (data) || ! ismatrix (data) || ! isreal (data)) error ("kmeans: first input argument must be a DxN real data matrix"); elseif (! isnumeric (k)) error ("kmeans: second argument must be numeric"); endif ## Parse options while (length (prop) > 0) if (length (prop) < 2) error ("kmeans: Option '%s' has no argument", prop{1}); endif switch (lower (prop{1})) case "emptyaction" emptyaction = prop{2}; case "start" start = prop{2}; case "maxiter" max_iter = prop{2}; case "distance" distance = prop{2}; case "replicates" replicates = prop{2}; replicates_set_explicitly = true; case {"display", "onlinephase", "options"} warning ("kmeans: Ignoring unimplemented option '%s'", prop{1}); otherwise error ("kmeans: Unknown option %s", prop{1}); endswitch prop = {prop{3:end}}; endwhile ## Process options ## check for the 'emptyaction' property switch (emptyaction) case {"singleton", "error", "drop"} ; otherwise d = [", " disp(emptyaction)] (1:end-1); # strip trailing \n if (length (d) > 20) d = ""; endif error ("kmeans: unsupported empty cluster action parameter%s", d); endswitch ## check for the 'replicates' property if (! isnumeric (replicates) || ! isscalar (replicates) || ! isreal (replicates) || replicates < 1) d = [", " disp(replicates)] (1:end-1); # strip trailing \n if (length (d) > 20) d = ""; endif error ("kmeans: invalid number of replicates%s", d); endif ## check for the 'MaxIter' property if (! isnumeric (max_iter) || ! isscalar (max_iter) || ! isreal (max_iter) || max_iter < 1) d = [", " disp(max_iter)] (1:end-1); # strip trailing \n if (length (d) > 20) d = ""; endif error ("kmeans: invalid MaxIter%s", d); endif ## check for the 'start' property switch (lower (start)) case {"sample", "plus", "cluster"} start = lower (start); case {"uniform"} start = "uniform"; min_data = min (data); range = max (data) - min_data; otherwise if (! isnumeric (start)) d = [", " disp(start)] (1:end-1); # strip trailing \n if (length (d) > 20) d = ""; endif error ("kmeans: invalid start parameter%s", d); endif if (isempty (k)) k = rows (start); elseif (rows (start) != k) error ("kmeans: Number of initializers (%d) should match number of centroids (%d)", rows (start), k); endif if (replicates_set_explicitly) if (replicates != size (start, 3)) error ("kmeans: The third dimension of the initializer (%d) should match the number of replicates (%d)", size (start, 3), replicates); endif else replicates = size (start, 3); endif endswitch ## check for the 'distance' property ## dist returns the distance btwn each row of matrix x and a row vector c switch (lower (distance)) case "sqeuclidean" dist = @(x, c) (sumsq (bsxfun (@minus, x, c), 2)); centroid = @(x) (mean (x,1)); case "cityblock" dist = @(x, c) (sum (abs (bsxfun (@minus, x, c)), 2)); centroid = @(x) (median (x,1)); case "cosine" ## Pre-normalize all data. ## (when Octave implements normr, will use data = normr (data) ) for i = 1:rows (data) data(i,:) = data(i,:) / sqrt (sumsq (data(i,:))); endfor dist = @(x, c) (1 - (x * c') ./ sqrt (sumsq (c))); centroid = @(x) (mean (x,1)); ## already normalized case "correlation" ## Pre-normalize all data. data = data - mean (data, 2); ## (when Octave implements normr, will use data = normr (data) ) for i = 1:rows (data) data(i,:) = data(i,:) / sqrt (sumsq (data(i,:))); endfor dist = @(x, c) (1 - (x * (c-mean (c))') ./ sqrt (sumsq (c-mean (c)))); centroid = @(x) (mean (x,1)); ## already normalized case "hamming" dist = @(x, c) (sum (bsxfun (@ne, x, c), 2)); centroid = @(x) (median (x,1)); otherwise error ("kmeans: unsupported distance parameter %s", distance); endswitch ## Done processing options ######################################## ## Now that k has been set (possibly by 'replicates' option), check/use it. if (! isscalar (k)) error ("kmeans: second input argument must be a scalar"); endif ## used to hold the distances from each sample to each class D = zeros (n_rows, k); best = Inf; best_centers = []; for rep = 1:replicates ## check for the 'start' property switch (lower (start)) case "sample" idx = randperm (n_rows, k); centers = data(idx, :); case "plus" # k-means++, by Arthur and Vassilios(?) centers(1,:) = data(randi (n_rows),:); d = inf (n_rows, 1); # Distance to nearest centroid so far for i = 2:k d = min (d, dist (data, centers(i-1, :))); centers(i,:) = data(find (cumsum (d) > rand * sum (d), 1), :); endfor case "cluster" idx = randperm (n_rows, max (k, ceil (n_rows/10))); [~, centers] = kmeans (data(idx,:), k, "start", "sample", "distance", distance); case "uniform" # vectorised 'min_data + range .* rand' centers = bsxfun (@plus, min_data, bsxfun (@times, range, rand (k, columns (data)))); otherwise centers = start(:,:,rep); endswitch ## Run the algorithm iter = 1; ## Classify once before the loop; to set sumd, and if max_iter == 0 ## Compute distances and classify for i = 1:k D (:, i) = dist (data, centers(i, :)); endfor [~, classes] = min (D, [], 2); sumd = obj_cost (D, classes); while (err > 0.001 && iter++ <= max_iter) ## Calculate new centroids replaced_centroids = []; ## Used by "emptyaction = singleton" for i = 1:k ## Get binary vector indicating membership in cluster i membership = (classes == i); ## Check for empty clusters if (! any (membership)) switch emptyaction ## if 'singleton', then find the point that is the ## farthest from any centroid (and not replacing an empty cluster ## from earlier in this pass) and add it to the empty cluster case 'singleton' available = setdiff(1:n_rows, replaced_centroids); [~, idx] = max (min (D(available,:)')); idx = available(idx); replaced_centroids = [replaced_centroids, idx]; classes(idx) = i; membership(idx)=1; ## if 'drop' then set C and D to NA case 'drop' centers(i,:) = NA; D(i,:) = NA; ## if 'error' then throw the error otherwise error ("kmeans: empty cluster created"); endswitch endif ## end check for empty clusters ## update the centroids if (any (membership)) ## if we didn't "drop" the cluster centers(i, :) = centroid (data(membership, :)); endif endfor ## Compute distances for i = 1:k D (:, i) = dist (data, centers(i, :)); endfor ## Classify [~, classes] = min (D, [], 2); ## calculate the difference in the sum of distances new_sumd = obj_cost (D, classes); err = sum (sumd - new_sumd); ## update the current sum of distances sumd = new_sumd; endwhile if (sum (sumd) < sum (best) || isinf (best)) best = sumd; best_centers = centers; endif endfor centers = best_centers; sumd = best'; final_classes = NA (original_rows,1); final_classes(data_idx) = classes; ## other positions already NaN / NA classes = final_classes; endfunction ## calculate the sum of within-class distances function obj = obj_cost (D, classes) obj = zeros (1,columns (D)); for i = 1:columns (D) idx = (classes == i); obj(i) = sum (D(idx,i)); end endfunction ## Test input parsing %!error kmeans (rand (3,2), 4); %!test %! samples = 4; %! dims = 3; %! k = 2; %! [cls, c, d, z] = kmeans (rand (samples,dims), k, "start", rand (k,dims, 5), %! "emptyAction", "singleton"); %! assert (size (cls), [samples, 1]); %! assert (size (c), [k, dims]); %! assert (size (d), [k, 1]); %! assert (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 (size (cls), [samples, 1]); %! assert (size (c), [k, dims]); %! assert (size (d), [k, 1]); %! assert (size (z), [samples, k]); %!test %! kmeans (rand (4,3), 2, "start", rand (2,3, 5), "replicates", 5, %! "emptyAction", "singleton"); %!error kmeans (rand (4,3), 2, "start", rand (2,3, 5), "replicates", 1); %!error kmeans (rand (4,3), 2, "start", rand (2,2)); %!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"); %!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", []); %!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", []); %!error kmeans (rand (4,3), 2, "maxiter", [1 2]); %!error kmeans (rand (4,3), 2, "maxiter", "one"); %!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"); %!error kmeans (rand (4,3), 2, "distance", "manhattan"); %!error kmeans ([1 0; 1.1 0], 2, "start", eye(2), "emptyaction", "error"); %!test %! kmeans ([1 0; 1.1 0], 2, "start", eye(2), "emptyaction", "singleton"); %!test %! [cls, c] = kmeans ([1 0; 2 0], 2, "start", [8,0;0,8], "emptyaction", "drop"); %! assert (cls, [1; 1]); %! assert (c, [1.5, 0; NA, NA]); %!error kmeans ([1 0; 1.1 0], 2, "start", eye(2), "emptyaction", "panic"); %!demo %! ## Generate a two-cluster problem %! 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); %! hold off; statistics-1.4.1/inst/PaxHeaders.29769/squareform.m0000644000000000000000000000006213443447555017023 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/squareform.m0000644000175000017500000001033413443447555017533 0ustar00johndjohnd00000000000000## Copyright (C) 2015 Carnë Draug ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{z} =} squareform (@var{y}) ## @deftypefnx {Function File} {@var{y} =} squareform (@var{z}) ## @deftypefnx {Function File} {@var{z} =} squareform (@var{y}, @qcode{"tovector"}) ## @deftypefnx {Function File} {@var{y} =} squareform (@var{z}, @qcode{"tomatrix"}) ## Interchange between distance matrix and distance vector formats. ## ## Converts between an hollow (diagonal filled with zeros), square, and ## symmetric matrix and a vector with of the lower triangular part. ## ## Its target application is the conversion of the vector returned by ## @code{pdist} into a distance matrix. It performs the opposite operation ## if input is a matrix. ## ## If @var{x} is a vector, its number of elements must fit into the ## triangular part of a matrix (main diagonal excluded). In other words, ## @code{numel (@var{x}) = @var{n} * (@var{n} - 1) / 2} for some integer ## @var{n}. The resulting matrix will be @var{n} by @var{n}. ## ## If @var{x} is a distance matrix, it must be square and the diagonal entries ## of @var{x} must all be zeros. @code{squareform} will generate a warning if ## @var{x} is not symmetric. ## ## The second argument is used to specify the output type in case there ## is a single element. It will defaults to @qcode{"tomatrix"} otherwise. ## ## @seealso{pdist} ## @end deftypefn ## Author: Carnë Draug function y = squareform (x, method) if (nargin < 1 || nargin > 2) print_usage (); elseif (! isnumeric (x) || ! ismatrix (x)) error ("squareform: Y or Z must be a numeric matrix or vector"); endif if (nargin == 1) ## This is ambiguous when numel (x) == 1, but that's the whole reason ## why the "method" option exists. if (isvector (x)) method = "tomatrix"; else method = "tovector"; endif endif switch (tolower (method)) case "tovector" if (! issquare (x)) error ("squareform: Z is not a square matrix"); elseif (any (diag (x) != 0)) error ("squareform: Z is not a hollow matrix, i.e., with diagonal entries all zero"); elseif (! issymmetric(x)) warning ("squareform:symmetric", "squareform: Z is not a symmetric matrix"); endif y = vec (tril (x, -1, "pack"), 2); case "tomatrix" ## the dimensions of y are the solution to the quadratic formula for: ## length (x) = (sy - 1) * (sy / 2) sy = (1 + sqrt (1 + 8 * numel (x))) / 2; if (fix (sy) != sy) error ("squareform: the numel of Y cannot form a square matrix"); endif y = zeros (sy, class (x)); y(tril (true (sy), -1)) = x; # fill lower triangular part y += y.'; # and then the upper triangular part otherwise error ("squareform: invalid METHOD '%s'", method); endswitch endfunction %!shared v, m %! v = 1:6; %! m = [0 1 2 3;1 0 4 5;2 4 0 6;3 5 6 0]; ## make sure that it can go both directions automatically %!assert (squareform (v), m) %!assert (squareform (squareform (v)), v) %!assert (squareform (m), v) ## treat row and column vectors equally %!assert (squareform (v'), m) ## handle 1 element input properly %!assert (squareform (1), [0 1;1 0]) %!assert (squareform (1, "tomatrix"), [0 1; 1 0]) %!assert (squareform (0, "tovector"), zeros (1, 0)) %!warning squareform ([0 1 2; 3 0 4; 5 6 0]); ## confirm that it respects input class %!test %! for c = {@single, @double, @uint8, @uint32, @uint64} %! f = c{1}; %! assert (squareform (f (v)), f (m)) %! assert (squareform (f (m)), f (v)) %! endfor statistics-1.4.1/inst/PaxHeaders.29769/wishrnd.m0000644000000000000000000000006213443447555016315 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/wishrnd.m0000644000175000017500000000645713443447555017040 0ustar00johndjohnd00000000000000## Copyright (C) 2013-2019 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along with Octave; see the file COPYING. If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {} [@var{W}[, @var{D}]] = wishrnd (@var{Sigma}, @var{df}[, @var{D}][, @var{n}=1]) ## Return a random matrix sampled from the Wishart distribution with given parameters ## ## Inputs: the @var{p} x @var{p} positive definite matrix @var{Sigma} (or the lower-triangular Cholesky factor @var{D} of @var{Sigma}) and scalar degrees of freedom parameter @var{df}. ## @var{df} can be non-integer as long as @var{df} > @var{p} ## ## Output: a random @var{p} x @var{p} matrix @var{W} from the Wishart(@var{Sigma}, @var{df}) distribution. If @var{n} > 1, then @var{W} is @var{p} x @var{p} x @var{n} and holds @var{n} such random matrices. (Optionally, the lower-triangular Cholesky factor @var{D} of @var{Sigma} is also returned.) ## ## Averaged across many samples, the mean of @var{W} should approach @var{df}*@var{Sigma}, and the variance of each element @var{W}_ij should approach @var{df}*(@var{Sigma}_ij^2 + @var{Sigma}_ii*@var{Sigma}_jj) ## ## Reference: Yu-Cheng Ku and Peter Bloomfield (2010), Generating Random Wishart Matrices with Fractional Degrees of Freedom in OX, http://www.gwu.edu/~forcpgm/YuChengKu-030510final-WishartYu-ChengKu.pdf ## ## @seealso{iwishrnd, wishpdf} ## @end deftypefn ## Author: Nir Krakauer ## Description: Sample from the Wishart distribution function [W, D] = wishrnd(Sigma, df, D, n=1) if (nargin < 2) print_usage (); endif if nargin < 3 || isempty(D) try D = chol(Sigma, 'lower'); catch error('wishrnd: Cholesky decomposition failed; Sigma probably not positive definite') end_try_catch endif p = size(D, 1); if df < p df = floor(df); #distribution not defined for small noninteger df df_isint = 1; else #check for integer degrees of freedom df_isint = (df == floor(df)); endif if ~df_isint [ii, jj] = ind2sub([p, p], 1:(p*p)); endif if n > 1 W = nan(p, p, n); endif for i = 1:n if df_isint Z = D * randn(p, df); else Z = diag(sqrt(chi2rnd(df - (0:(p-1))))); #fill diagonal #note: chi2rnd(x) is equivalent to 2*randg(x/2), but the latter seems to offer no performance advantage Z(ii > jj) = randn(p*(p-1)/2, 1); #fill lower triangle with normally distributed variates Z = D * Z; endif W(:, :, i) = Z*Z'; endfor endfunction %!assert(size (wishrnd (1,2)), [1, 1]); %!assert(size (wishrnd (1,2,[])), [1, 1]); %!assert(size (wishrnd (1,2,1)), [1, 1]); %!assert(size (wishrnd ([],2,1)), [1, 1]); %!assert(size (wishrnd ([3 1; 1 3], 2.00001, [], 1)), [2, 2]); %!assert(size (wishrnd (eye(2), 2, [], 3)), [2, 2, 3]); %% Test input validation %!error wishrnd () %!error wishrnd (1) %!error wishrnd ([1; 1], 2) statistics-1.4.1/inst/PaxHeaders.29769/combnk.m0000644000000000000000000000006213443447555016110 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/combnk.m0000644000175000017500000000466713443447555016634 0ustar00johndjohnd00000000000000## Copyright (C) 2010 Soren Hauberg ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{c} =} combnk (@var{data}, @var{k}) ## Return all combinations of @var{k} elements in @var{data}. ## @end deftypefn function retval = combnk (data, k) ## Check input if (nargin != 2) print_usage; elseif (! isvector (data)) error ("combnk: first input argument must be a vector"); elseif (!isreal (k) || k != round (k) || k < 0) error ("combnk: second input argument must be a non-negative integer"); endif ## Simple checks n = numel (data); if (k == 0 || k > n) retval = resize (data, 0, k); elseif (k == n) retval = data (:).'; else retval = __combnk__ (data, k); endif ## For some odd reason Matlab seems to treat strings differently compared to other data-types... if (ischar (data)) retval = flipud (retval); endif endfunction function retval = __combnk__ (data, k) ## Recursion stopping criteria if (k == 1) retval = data (:); else ## Process data n = numel (data); if iscell (data) retval = {}; else retval = []; endif for j = 1:n C = __combnk__ (data ((j+1):end), k-1); C = cat (2, repmat (data (j), rows (C), 1), C); if (!isempty (C)) if (isempty (retval)) retval = C; else retval = [retval; C]; endif endif endfor endif endfunction %!demo %! c = combnk (1:5, 2); %! disp ("All pairs of integers between 1 and 5:"); %! disp (c); %!test %! c = combnk (1:3, 2); %! assert (c, [1, 2; 1, 3; 2, 3]); %!test %! c = combnk (1:3, 6); %! assert (isempty (c)); %!test %! c = combnk ({1, 2, 3}, 2); %! assert (c, {1, 2; 1, 3; 2, 3}); %!test %! c = combnk ("hello", 2); %! assert (c, ["lo"; "lo"; "ll"; "eo"; "el"; "el"; "ho"; "hl"; "hl"; "he"]); statistics-1.4.1/inst/PaxHeaders.29769/unidstat.m0000644000000000000000000000006213443447555016472 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/unidstat.m0000644000175000017500000000501613443447555017203 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} unidstat (@var{n}) ## Compute mean and variance of the discrete uniform distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{n} is the parameter of the discrete uniform distribution. The elements ## of @var{n} must be positive natural numbers ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the discrete uniform distribution ## ## @item ## @var{v} is the variance of the discrete uniform distribution ## @end itemize ## ## @subheading Example ## ## @example ## @group ## n = 1:6; ## [m, v] = unidstat (n) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the discrete uniform distribution function [m, v] = unidstat (n) # Check arguments if (nargin != 1) print_usage (); endif if (! isempty (n) && ! ismatrix (n)) error ("unidstat: n must be a numeric matrix"); endif # Calculate moments m = (n + 1) ./ 2; v = ((n .^ 2) - 1) ./ 12; # Continue argument check k = find (! (n > 0) | ! (n < Inf) | ! (n == round (n))); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!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 (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/mvncdf.m0000644000000000000000000000006213443447555016114 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/mvncdf.m0000644000175000017500000001115013443447555016621 0ustar00johndjohnd00000000000000## Copyright (C) 2008 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{p} =} mvncdf (@var{x}, @var{mu}, @var{sigma}) ## @deftypefnx {Function File} {} mvncdf (@var{a}, @var{x}, @var{mu}, @var{sigma}) ## @deftypefnx {Function File} {[@var{p}, @var{err}] =} mvncdf (@dots{}) ## Compute the cumulative distribution function of the multivariate ## normal distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} is the upper limit for integration where each row corresponds ## to an observation. ## ## @item ## @var{mu} is the mean. ## ## @item ## @var{sigma} is the correlation matrix. ## ## @item ## @var{a} is the lower limit for integration where each row corresponds ## to an observation. @var{a} must have the same size as @var{x}. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{p} is the cumulative distribution at each row of @var{x} and ## @var{a}. ## ## @item ## @var{err} is the estimated error. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = [1 2]; ## mu = [0.5 1.5]; ## sigma = [1.0 0.5; 0.5 1.0]; ## p = mvncdf (x, mu, sigma) ## @end group ## ## @group ## a = [-inf 0]; ## p = mvncdf (a, x, mu, sigma) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Alan Genz and Frank Bretz. Numerical Computation of Multivariate ## t-Probabilities with Application to Power Calculation of Multiple ## Constrasts. @cite{Journal of Statistical Computation and Simulation}, ## 63, pages 361-378, 1999. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: CDF of the multivariate normal distribution function [p, err] = mvncdf (varargin) # Monte-Carlo confidence factor for the standard error: 99 % gamma = 2.5; # Tolerance err_eps = 1e-3; if (length (varargin) == 1) x = varargin{1}; mu = []; sigma = eye (size (x, 2)); a = -Inf .* ones (size (x)); elseif (length (varargin) == 3) x = varargin{1}; mu = varargin{2}; sigma = varargin{3}; a = -Inf .* ones (size (x)); elseif (length (varargin) == 4) a = varargin{1}; x = varargin{2}; mu = varargin{3}; sigma = varargin{4}; else print_usage (); endif # Dimension q = size (sigma, 1); cases = size (x, 1); # Default value for mu if (isempty (mu)) mu = zeros (1, q); endif # Check parameters if (size (x, 2) != q) error ("mvncdf: x must have the same number of columns as sigma"); endif if (any (size (x) != size (a))) error ("mvncdf: a must have the same size as x"); endif if (isscalar (mu)) mu = ones (1, q) .* mu; elseif (! isvector (mu) || size (mu, 2) != q) error ("mvncdf: mu must be a scalar or a vector with the same number of columns as x"); endif x = x - repmat (mu, cases, 1); if (q < 1 || size (sigma, 2) != q || any (any (sigma != sigma')) || min (eig (sigma)) <= 0) error ("mvncdf: sigma must be nonempty symmetric positive definite"); endif c = chol (sigma)'; # Number of integral transformations n = 1; p = zeros (cases, 1); varsum = zeros (cases, 1); err = ones (cases, 1) .* err_eps; # Apply crude Monte-Carlo estimation while any (err >= err_eps) # Sample from q-1 dimensional unit hypercube w = rand (cases, q - 1); # Transformation of the multivariate normal integral dvev = normcdf ([a(:, 1) / c(1, 1), x(:, 1) / c(1, 1)]); dv = dvev(:, 1); ev = dvev(:, 2); fv = ev - dv; y = zeros (cases, q - 1); for i = 1:(q - 1) y(:, i) = norminv (dv + w(:, i) .* (ev - dv)); dvev = normcdf ([(a(:, i + 1) - c(i + 1, 1:i) .* y(:, 1:i)) ./ c(i + 1, i + 1), (x(:, i + 1) - c(i + 1, 1:i) .* y(:, 1:i)) ./ c(i + 1, i + 1)]); dv = dvev(:, 1); ev = dvev(:, 2); fv = (ev - dv) .* fv; endfor n++; # Estimate standard error varsum += (n - 1) .* ((fv - p) .^ 2) ./ n; err = gamma .* sqrt (varsum ./ (n .* (n - 1))); p += (fv - p) ./ n; endwhile endfunction statistics-1.4.1/inst/PaxHeaders.29769/expstat.m0000644000000000000000000000006213443447555016327 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/expstat.m0000644000175000017500000000450113443447555017036 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} expstat (@var{l}) ## Compute mean and variance of the exponential distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{l} is the parameter of the exponential distribution. The ## elements of @var{l} must be positive ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the exponential distribution ## ## @item ## @var{v} is the variance of the exponential distribution ## @end itemize ## ## @subheading Example ## ## @example ## @group ## l = 1:6; ## [m, v] = expstat (l) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the exponential distribution function [m, v] = expstat (l) # Check arguments if (nargin != 1) print_usage (); endif if (! isempty (l) && ! ismatrix (l)) error ("expstat: l must be a numeric matrix"); endif # Calculate moments m = l; v = m .^ 2; # Continue argument check k = find (! (l > 0) | ! (l < Inf)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!test %! l = 1:6; %! [m, v] = expstat (l); %! assert (m, [1, 2, 3, 4, 5, 6], 0.001); %! assert (v, [1, 4, 9, 16, 25, 36], 0.001); statistics-1.4.1/inst/PaxHeaders.29769/nanmedian.m0000644000000000000000000000006213443447555016571 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nanmedian.m0000644000175000017500000000522513443447555017304 0ustar00johndjohnd00000000000000## Copyright (C) 2001 Paul Kienzle ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} @var{v} = nanmedian (@var{x}) ## @deftypefnx{Function File} @var{v} = nanmedian (@var{x}, @var{dim}) ## Compute the median of data while ignoring NaN values. ## ## This function is identical to the @code{median} function except that NaN values ## are ignored. If all values are NaN, the median is returned as NaN. ## ## @seealso{median, nanmin, nanmax, nansum, nanmean} ## @end deftypefn function v = nanmedian (X, varargin) if nargin < 1 || nargin > 2 print_usage; endif if nargin < 2 dim = min(find(size(X)>1)); if isempty(dim), dim=1; endif; else dim = varargin{:}; endif sz = size (X); if (prod (sz) > 1) ## Find lengths of datasets after excluding NaNs; valid datasets ## are those that are not empty after you remove all the NaNs n = sz(dim) - sum (isnan(X),varargin{:}); ## When n is equal to zero, force it to one, so that median ## picks up a NaN value below n (n==0) = 1; ## Sort the datasets, with the NaN going to the end of the data X = sort (X, varargin{:}); ## Determine the offset for each column in single index mode colidx = reshape((0:(prod(sz) / sz(dim) - 1)), size(n)); colidx = floor(colidx / prod(sz(1:dim-1))) * prod(sz(1:dim)) + ... mod(colidx,prod(sz(1:dim-1))); stride = prod(sz(1:dim-1)); ## Average the two central values of the sorted list to compute ## the median, but only do so for valid rows. If the dataset ## is odd length, the single central value will be used twice. ## E.g., ## for n==5, ceil(2.5+0.5) is 3 and floor(2.5+0.5) is also 3 ## for n==6, ceil(3.0+0.5) is 4 and floor(3.0+0.5) is 3 ## correction made for stride of data "stride*ceil(2.5-0.5)+1" v = (X(colidx + stride*ceil(n./2-0.5) + 1) + ... X(colidx + stride*floor(n./2-0.5) + 1)) ./ 2; else error ("nanmedian: invalid matrix argument"); endif endfunction statistics-1.4.1/inst/PaxHeaders.29769/gmdistribution.m0000644000000000000000000000006213443447555017702 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gmdistribution.m0000644000175000017500000003120213443447555020407 0ustar00johndjohnd00000000000000## Copyright (C) 2015 Lachlan Andrew ## Copyright (C) 2018 John Donoghue ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## ## -*- texinfo -*- ## @deftypefn {Function File} {@var{GMdist} =} gmdistribution (@var{mu}, @var{Sigma}) ## @deftypefnx {Function File} {@var{GMdist} =} gmdistribution (@var{mu}, @var{Sigma}, @var{p}) ## @deftypefnx {Function File} {@var{GMdist} =} gmdistribution (@var{mu}, @var{Sigma}, @var{p}, @var{extra}) ## Create an object of the gmdistribution class which represents a Gaussian ## mixture model with k components of n-dimensional Gaussians. ## ## Input @var{mu} is a k-by-n matrix specifying the n-dimensional mean of each ## of the k components of the distribution. ## ## Input @var{Sigma} is an array that specifies the variances of the ## distributions, in one of four forms depending on its dimension. ## @itemize ## @item n-by-n-by-k: Slice @var{Sigma}(:,:,i) is the variance of the ## i'th component ## @item 1-by-n-by-k: Slice diag(@var{Sigma}(1,:,i)) is the variance of the ## i'th component ## @item n-by-n: @var{Sigma} is the variance of every component ## @item 1-by-n-by-k: Slice diag(@var{Sigma}) is the variance of every ## component ## @end itemize ## ## If @var{p} is specified, it is a vector of length k specifying the proportion ## of each component. If it is omitted or empty, each component has an equal ## proportion. ## ## Input @var{extra} is used by fitgmdist to indicate the parameters of the ## fitting process. ## @seealso{fitgmdist} ## @end deftypefn classdef gmdistribution properties mu ## means Sigma ## covariances ComponentProportion ## mixing proportions DistributionName ## "gaussian mixture distribution" NumComponents ## Number of mixture components NumVariables ## Dimension d of each Gaussian component CovarianceType ## 'diagonal' if DiagonalCovariance, 'full' othw SharedCovariance ## true if all components have equal covariance ## Set by a call to gmdistribution.fit or fitgmdist AIC ## Akaike Information Criterion BIC ## Bayes Information Criterion Converged ## true if algorithm converged by MaxIter NegativeLogLikelihood ## Negative of log-likelihood NlogL ## Negative of log-likelihood NumIterations ## Number of iterations RegularizationValue ## const added to diag of cov to make +ve def endproperties properties (Access = private) DiagonalCovariance ## bool summary of "CovarianceType" endproperties methods ######################################## ## Constructor function obj = gmdistribution (mu,sigma,p = [],extra = []) obj.DistributionName = "gaussian mixture distribution"; obj.mu = mu; obj.Sigma = sigma; obj.NumComponents = rows (mu); obj.NumVariables = columns (mu); if (isempty (p)) obj.ComponentProportion = ones (1,obj.NumComponents) / obj.NumComponents; else if any (p < 0) error ("gmmdistribution: component weights must be non-negative"); endif s = sum(p); if (s == 0) error ("gmmdistribution: component weights must not be all zero"); elseif (s != 1) p = p / s; endif obj.ComponentProportion = p(:)'; endif if (length (size (sigma)) == 3) obj.SharedCovariance = false; else obj.SharedCovariance = true; endif if (rows (sigma) == 1 && columns (mu) > 1) obj.DiagonalCovariance = true; obj.CovarianceType = 'diagonal'; else obj.DiagonalCovariance = false; ## full obj.CovarianceType = 'full'; endif if (!isempty (extra)) obj.AIC = extra.AIC; obj.BIC = extra.BIC; obj.Converged = extra.Converged; obj.NegativeLogLikelihood = extra.NegativeLogLikelihood; obj.NlogL = extra.NegativeLogLikelihood; obj.NumIterations = extra.NumIterations; obj.RegularizationValue = extra.RegularizationValue; endif endfunction ######################################## ## Cumulative distribution function for Gaussian mixture distribution function c = cdf (obj, X) X = checkX (obj, X, "cdf"); p_x_l = zeros (rows (X), obj.NumComponents); if (obj.SharedCovariance) if (obj.DiagonalCovariance) sig = diag (obj.Sigma); else sig = obj.Sigma; endif endif for i = 1:obj.NumComponents if (!obj.SharedCovariance) if (obj.DiagonalCovariance) sig = diag (obj.Sigma(:,:,i)); else sig = obj.Sigma(:,:,i); endif endif p_x_l(:,i) = mvncdf (X,obj.mu(i,:),sig)*obj.ComponentProportion(i); endfor c = sum (p_x_l, 2); endfunction ######################################## ## Construct clusters from Gaussian mixture distribution ## function [idx,nlogl,P,logpdf,M] = cluster (obj,X) X = checkX (obj, X, "cluster"); [p_x_l, M] = componentProb (obj, X); [~, idx] = max (p_x_l, [], 2); if (nargout >= 2) PDF = sum (p_x_l, 2); logpdf = log (PDF); nlogl = -sum (logpdf); if (nargout >= 3) P = bsxfun (@rdivide, p_x_l, PDF); endif endif endfunction ######################################## ## Display Gaussian mixture distribution object function c = disp (obj) fprintf("Gaussian mixture distribution with %d components in %d dimension(s)\n", obj.NumComponents, columns (obj.mu)); for i = 1:obj.NumComponents fprintf("Clust %d: weight %d\n\tMean: ", i, obj.ComponentProportion(i)); fprintf("%g ", obj.mu(i,:)); fprintf("\n"); if (!obj.SharedCovariance) fprintf("\tVariance:"); if (!obj.DiagonalCovariance) if columns (obj.mu) > 1 fprintf("\n"); endif disp(squeeze(obj.Sigma(:,:,i))) else fprintf(" diag("); fprintf("%g ", obj.Sigma(:,:,i)); fprintf(")\n"); endif endif endfor if (obj.SharedCovariance) fprintf("Shared variance\n"); if (!obj.DiagonalCovariance) obj.Sigma else fprintf(" diag("); fprintf("%g ", obj.Sigma); fprintf(")\n"); endif endif if (!isempty (obj.AIC)) fprintf("AIC=%g BIC=%g NLogL=%g Iter=%d Cged=%d Reg=%g\n", ... obj.AIC, obj.BIC, obj.NegativeLogLikelihood, ... obj.NumIterations, obj.Converged, obj.RegularizationValue); endif endfunction ######################################## ## Display Gaussian mixture distribution object function c = display (obj) disp(obj); endfunction ######################################## ## Mahalanobis distance to component means function D = mahal (obj,X) X = checkX (obj, X, "mahal"); [~, D] = componentProb (obj,X); endfunction ######################################## ## Probability density function for Gaussian mixture distribution function c = pdf (obj,X) X = checkX (obj, X, "pdf"); p_x_l = componentProb (obj, X); c = sum (p_x_l, 2); endfunction ######################################## ## Posterior probabilities of components function c = posterior (obj,X) X = checkX (obj, X, "posterior"); p_x_l = componentProb (obj, X); c = bsxfun(@rdivide, p_x_l, sum (p_x_l, 2)); endfunction ######################################## ## Random numbers from Gaussian mixture distribution function c = random (obj,n) if nargin == 1 n = 1; endif c = zeros (n, obj.NumVariables); classes = randsample (obj.NumComponents, n, true, obj.ComponentProportion); if (obj.SharedCovariance) if (obj.DiagonalCovariance) sig = diag (obj.Sigma); else sig = obj.Sigma; endif endif for i = 1:obj.NumComponents idx = (classes == i); k = sum(idx); if k > 0 if (!obj.SharedCovariance) if (obj.DiagonalCovariance) sig = diag (obj.Sigma(:,:,i)); else sig = obj.Sigma(:,:,i); endif endif # [sig] forces [sig] not to have class "diagonal", # since mvnrnd uses automatic broadcast, # which fails on structured matrices c(idx,:) = mvnrnd ([obj.mu(i,:)], [sig], k); endif endfor endfunction endmethods ######################################## methods (Static) ## Gaussian mixture parameter estimates function c = fit (X,k,varargin) c = fitgmdist (X,k,varargin{:}); endfunction endmethods ######################################## methods (Access = private) ## Probability density of (row of) X *and* component l ## Second argument is an array of the Mahalonis distances function [p_x_l, M] = componentProb (obj, X) M = zeros (rows (X), obj.NumComponents); dets = zeros (1, obj.NumComponents); % sqrt(determinant) if (obj.SharedCovariance) if (obj.DiagonalCovariance) r = diag (sqrt(obj.Sigma)); else r = chol (obj.Sigma); endif endif for i = 1:obj.NumComponents dev = bsxfun (@minus, X, obj.mu(i,:)); if (!obj.SharedCovariance) if (obj.DiagonalCovariance) r = diag (sqrt (obj.Sigma(:,:,i))); else r = chol (obj.Sigma(:,:,i)); endif endif M(:,i) = sumsq (dev / r, 2); dets(i) = prod (diag (r)); endfor p_x_l = exp (-M/2); coeff = obj.ComponentProportion ./ ((2*pi)^(obj.NumVariables/2).*dets); p_x_l = bsxfun (@times, p_x_l, coeff); endfunction ######################################## ## Check format of argument X function X = checkX (obj, X, name) if (columns (X) != obj.NumVariables) if (columns (X) == 1 && rows (X) == obj.NumVariables) X = X'; else error ("gmdistribution.%s: X has %d columns instead of %d\n", ... name, columns (X), obj.NumVariables); end endif endfunction endmethods endclassdef %!test %! mu = eye(2); %! Sigma = eye(2); %! GM = gmdistribution (mu, Sigma); %! density = GM.pdf ([0 0; 1 1]); %! assert (density(1) - density(2), 0, 1e-6); %! %! [idx, nlogl, P, logpdf,M] = cluster (GM, eye(2)); %! assert (idx, [1; 2]); %! [idx2,nlogl2,P2,logpdf2] = GM.cluster (eye(2)); %! assert (nlogl - nlogl2, 0, 1e-6); %! [idx3,nlogl3,P3] = cluster (GM, eye(2)); %! assert (P - P3, zeros (2), 1e-6); %! [idx4,nlogl4] = cluster (GM, eye(2)); %! assert (size (nlogl4), [1 1]); %! idx5 = cluster (GM, eye(2)); %! assert (idx - idx5, zeros (2,1)); %! %! D = GM.mahal ([1;0]); %! assert (D - M(1,:), zeros (1,2), 1e-6); %! %! P = GM.posterior ([0 1]); %! assert (P - P2(2,:), zeros (1,2), 1e-6); %! %! R = GM.random(20); %! assert (size(R), [20, 2]); %! %! R = GM.random(); %! assert (size(R), [1, 2]); statistics-1.4.1/inst/PaxHeaders.29769/cl_multinom.m0000644000000000000000000000006213443447555017161 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/cl_multinom.m0000644000175000017500000001201113443447555017663 0ustar00johndjohnd00000000000000## Copyright (C) 2009 Levente Torok ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## ## @deftypefn {Function File} {@var{CL} =} cl_multinom (@var{x}, @var{N}, @var{b}, @var{calculation_type} ) - Confidence level of multinomial portions ## Returns confidence level of multinomial parameters estimated @math{ p = x / sum(x) } with predefined confidence interval @var{b}. ## Finite population is also considered. ## ## This function calculates the level of confidence at which the samples represent the true distribution ## given that there is a predefined tolerance (confidence interval). ## This is the upside down case of the typical excercises at which we want to get the confidence interval ## given the confidence level (and the estimated parameters of the underlying distribution). ## But once we accept (lets say at elections) that we have a standard predefined ## maximal acceptable error rate (e.g. @var{b}=0.02 ) in the estimation and we just want to know that how sure we ## can be that the measured proportions are the same as in the ## entire population (ie. the expected value and mean of the samples are roghly the same) we need to use this function. ## ## @subheading Arguments ## @itemize @bullet ## @item @var{x} : int vector : sample frequencies bins ## @item @var{N} : int : Population size that was sampled by x. If N 4) print_usage; elseif (!ischar (calculation_type)) error ("Argument calculation_type must be a string"); endif k = rows(x); nn = sum(x); p = x / nn; if (isscalar( b )) if (b==0) b=0.02; endif b = ones( rows(x), 1 ) * b; if (b<0) b=1 ./ max( x, 1 ); endif endif bb = b .* b; if (N==nn) CL = 1; return; endif if (N ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{d}, @var{err}] = } tbl_delim (@var{d}) ## Return the delimiter for tblread or tblwrite. ## ## The delimeter, @var{d} may be any single character or ## @itemize ## @item "space" " " (default) ## @item "tab" "\t" ## @item "comma" "," ## @item "semi" ";" ## @item "bar" "|" ## @end itemize ## ## @var{err} will be empty if there is no error, and @var{d} will be NaN ## if there is an error. You MUST check the value of @var{err}. ## @seealso{tblread, tblwrite} ## @end deftypefn function [d, err] = tbl_delim (d) ## Check arguments if nargin != 1 print_usage (); endif err = ""; ## Format the delimiter if ischar (d) ## allow for escape characters d = sprintf (d); if numel (d) > 1 ## allow the word forms s.space = " "; s.tab = "\t"; s.comma = ","; s.semi = ";"; s.bar = "|"; if ! ismember (d, fieldnames (s)) err = ["tblread: delimiter must be either a single " ... "character or one of\n" ... sprintf("%s, ", fieldnames (s){:})(1:end-2)]; d = NaN; else d = s.(d); endif endif else err = "delimiter must be a character"; d = NaN; endif if isempty (d) err = "the delimiter may not be empty"; d = NaN; endif endfunction ## Tests ## The defaults ## NOTE: currently commented out as cant run private tests %!notest %! [d err] = tbl_delim (" "); %! assert (d, " "); %! assert (err, ""); ## Named delimiters %!notest %! [d err] = tbl_delim ("space"); %! assert (d, " "); %! assert (err, ""); %!notest %! [d err] = tbl_delim ("tab"); %! assert (d, sprintf ("\t")); %! assert (err, ""); %!notest %! [d err] = tbl_delim ("comma"); %! assert (d, ","); %! assert (err, ""); %!notest %! [d err] = tbl_delim ("semi"); %! assert (d, ";"); %! assert (err, ""); %!notest %! [d err] = tbl_delim ("bar"); %! assert (d, "|"); %! assert (err, ""); ## An arbitrary character %!notest %! [d err] = tbl_delim ("x"); %! assert (d, "x"); %! assert (err, ""); ## An arbitrary escape string %!notest %! [d err] = tbl_delim ('\r'); %! assert (d, sprintf ('\r')) %! assert (err, ""); ## Errors %!notest %! [d err] = tbl_delim ("bars"); %! assert (isnan (d)); %! assert (! isempty (err)); %!notest %! [d err] = tbl_delim (""); %! assert (isnan (d)); %! assert (! isempty (err)); %!notest %! [d err] = tbl_delim (5); %! assert (isnan (d)); %! assert (! isempty (err)); %!notest %! [d err] = tbl_delim ({"."}); %! assert (isnan (d)); %! assert (! isempty (err)); statistics-1.4.1/inst/PaxHeaders.29769/caseread.m0000644000000000000000000000006213443447555016406 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/caseread.m0000644000175000017500000000352113443447555017116 0ustar00johndjohnd00000000000000## Copyright (C) 2008 Bill Denney ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{names} =} caseread (@var{filename}) ## Read case names from an ascii file. ## ## Essentially, this reads all lines from a file as text and returns ## them in a string matrix. ## @seealso{casewrite, tblread, tblwrite, csv2cell, cell2csv, fopen} ## @end deftypefn ## Author: Bill Denney ## Description: Read strings from a file function names = caseread (f="") ## Check arguments if nargin != 1 print_usage (); endif if isempty (f) ## FIXME: open a file dialog box in this case when a file dialog box ## becomes available error ("caseread: filename must be given") endif [fid msg] = fopen (f, "rt"); if fid < 0 || (! isempty (msg)) error ("caseread: cannot open %s: %s", f, msg); endif names = {}; t = fgetl (fid); while ischar (t) names{end+1} = t; t = fgetl (fid); endwhile if (fclose (fid) < 0) error ("caseread: error closing f") endif names = strvcat (names); endfunction ## Tests %!shared n, casereadfile %! n = ["a ";"bcd";"ef "]; %! casereadfile = file_in_loadpath("test/caseread.dat"); %!assert (caseread (casereadfile), n); statistics-1.4.1/inst/PaxHeaders.29769/regress_gp.m0000644000000000000000000000006213443447555016777 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/regress_gp.m0000644000175000017500000001065013443447555017510 0ustar00johndjohnd00000000000000## Copyright (c) 2012 Juan Pablo Carbajal ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{K}] =} regress_gp (@var{x}, @var{y}, @var{Sp}) ## @deftypefnx {Function File} {[@dots{} @var{yi} @var{dy}] =} regress_gp (@dots{}, @var{xi}) ## Linear scalar regression using gaussian processes. ## ## It estimates the model @var{y} = @var{x}'*m for @var{x} R^D and @var{y} in R. ## The information about errors of the predictions (interpolation/extrapolation) is given ## by the covarianve matrix @var{K}. If D==1 the inputs must be column vectors, ## if D>1 then @var{x} is n-by-D, with n the number of data points. @var{Sp} defines ## the prior covariance of @var{m}, it should be a (D+1)-by-(D+1) positive definite matrix, ## if it is empty, the default is @code{Sp = 100*eye(size(x,2)+1)}. ## ## If @var{xi} inputs are provided, the model is evaluated and returned in @var{yi}. ## The estimation of the variation of @var{yi} are given in @var{dy}. ## ## Run @code{demo regress_gp} to see an examples. ## ## The function is a direc implementation of the formulae in pages 11-12 of ## Gaussian Processes for Machine Learning. Carl Edward Rasmussen and @ ## Christopher K. I. Williams. The MIT Press, 2006. ISBN 0-262-18253-X. ## available online at @url{http://gaussianprocess.org/gpml/}. ## ## @seealso{regress} ## @end deftypefn function [wm K yi dy] = regress_gp (x,y,Sp=[],xi=[]) if isempty(Sp) Sp = 100*eye(size(x,2)+1); end x = [ones(1,size(x,1)); x']; ## Juan Pablo Carbajal ## Note that in the book the equation (below 2.11) for the A reads ## A = (1/sy^2)*x*x' + inv (Vp); ## where sy is the scalar variance of the of the residuals (i.e y = x' * w + epsilon) ## and epsilon is drawn from N(0,sy^2). Vp is the variance of the parameters w. ## Note that ## (sy^2 * A)^{-1} = (1/sy^2)*A^{-1} = (x*x' + sy^2 * inv(Vp))^{-1}; ## and that the formula for the w mean is ## (1/sy^2)*A^{-1}*x*y ## Then one obtains ## inv(x*x' + sy^2 * inv(Vp))*x*y ## Looking at the formula bloew we see that Sp = (1/sy^2)*Vp ## making the regression depend on only one parameter, Sp, and not two. A = x*x' + inv (Sp); K = inv (A); wm = K*x*y; yi =[]; dy =[]; if !isempty (xi); xi = [ones(size(xi,1),1) xi]; yi = xi*wm; dy = diag (xi*K*xi'); end endfunction %!demo %! % 1D Data %! x = 2*rand (5,1)-1; %! y = 2*x -1 + 0.3*randn (5,1); %! %! % Points for interpolation/extrapolation %! xi = linspace (-2,2,10)'; %! %! [m K yi dy] = regress_gp (x,y,[],xi); %! %! plot (x,y,'xk',xi,yi,'r-',xi,bsxfun(@plus, yi, [-dy +dy]),'b-'); %!demo %! % 2D Data %! x = 2*rand (4,2)-1; %! y = 2*x(:,1)-3*x(:,2) -1 + 1*randn (4,1); %! %! % Mesh for interpolation/extrapolation %! [xi yi] = meshgrid (linspace (-1,1,10)); %! %! [m K zi dz] = regress_gp (x,y,[],[xi(:) yi(:)]); %! zi = reshape (zi, 10,10); %! dz = reshape (dz,10,10); %! %! plot3 (x(:,1),x(:,2),y,'.g','markersize',8); %! hold on; %! h = mesh (xi,yi,zi,zeros(10,10)); %! set(h,'facecolor','none'); %! h = mesh (xi,yi,zi+dz,ones(10,10)); %! set(h,'facecolor','none'); %! h = mesh (xi,yi,zi-dz,ones(10,10)); %! set(h,'facecolor','none'); %! hold off %! axis tight %! view(80,25) %!demo %! % Projection over basis function %! 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 %! xi = linspace (-1,1,100)'; %! pxi = [sqrt(abs(xi)) xi xi.^2 xi.^3]; %! %! Sp = 100*eye(size(px,2)+1); %! Sp(2,2) = 1; # We don't believe the sqrt is present %! [m K yi dy] = regress_gp (px,y,Sp,pxi); %! disp(m) %! %! plot (x,y,'xk;Data;',xi,yi,'r-;Estimation;',xi,polyval(pp,xi),'g-;True;'); %! axis tight %! axis manual %! hold on %! plot (xi,bsxfun(@plus, yi, [-dy +dy]),'b-'); %! hold off statistics-1.4.1/inst/PaxHeaders.29769/linkage.m0000644000000000000000000000006213443447555016251 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/linkage.m0000644000175000017500000002301213443447555016756 0ustar00johndjohnd00000000000000## Copyright (C) 2008 Francesco Potortì ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} linkage (@var{d}) ## @deftypefnx {Function File} {@var{y} =} linkage (@var{d}, @var{method}) ## @deftypefnx {Function File} @ ## {@var{y} =} linkage (@var{x}, @var{method}, @var{metric}) ## @deftypefnx {Function File} @ ## {@var{y} =} linkage (@var{x}, @var{method}, @var{arglist}) ## ## Produce a hierarchical clustering dendrogram ## ## @var{d} is the dissimilarity matrix relative to n observations, ## formatted as a @math{(n-1)*n/2}x1 vector as produced by @code{pdist}. ## Alternatively, @var{x} contains data formatted for input to ## @code{pdist}, @var{metric} is a metric for @code{pdist} and ## @var{arglist} is a cell array containing arguments that are passed to ## @code{pdist}. ## ## @code{linkage} starts by putting each observation into a singleton ## cluster and numbering those from 1 to n. Then it merges two ## clusters, chosen according to @var{method}, to create a new cluster ## numbered n+1, and so on until all observations are grouped into ## a single cluster numbered 2(n-1). Row k of the ## (m-1)x3 output matrix relates to cluster n+k: the first ## two columns are the numbers of the two component clusters and column ## 3 contains their distance. ## ## @var{method} defines the way the distance between two clusters is ## computed and how they are recomputed when two clusters are merged: ## ## @table @samp ## @item "single" (default) ## Distance between two clusters is the minimum distance between two ## elements belonging each to one cluster. Produces a cluster tree ## known as minimum spanning tree. ## ## @item "complete" ## Furthest distance between two elements belonging each to one cluster. ## ## @item "average" ## Unweighted pair group method with averaging (UPGMA). ## The mean distance between all pair of elements each belonging to one ## cluster. ## ## @item "weighted" ## Weighted pair group method with averaging (WPGMA). ## When two clusters A and B are joined together, the new distance to a ## cluster C is the mean between distances A-C and B-C. ## ## @item "centroid" ## Unweighted Pair-Group Method using Centroids (UPGMC). ## Assumes Euclidean metric. The distance between cluster centroids, ## each centroid being the center of mass of a cluster. ## ## @item "median" ## Weighted pair-group method using centroids (WPGMC). ## Assumes Euclidean metric. Distance between cluster centroids. When ## two clusters are joined together, the new centroid is the midpoint ## between the joined centroids. ## ## @item "ward" ## Ward's sum of squared deviations about the group mean (ESS). ## Also known as minimum variance or inner squared distance. ## Assumes Euclidean metric. How much the moment of inertia of the ## merged cluster exceeds the sum of those of the individual clusters. ## @end table ## ## @strong{Reference} ## Ward, J. H. Hierarchical Grouping to Optimize an Objective Function ## J. Am. Statist. Assoc. 1963, 58, 236-244, ## @url{http://iv.slis.indiana.edu/sw/data/ward.pdf}. ## @end deftypefn ## ## @seealso{pdist,squareform} ## Author: Francesco Potortì function dgram = linkage (d, method = "single", distarg) ## check the input if (nargin < 1) || (nargin > 3) print_usage (); endif if (isempty (d)) error ("linkage: d cannot be empty"); elseif ( nargin < 3 && ~ isvector (d)) error ("linkage: d must be a vector"); endif methods = struct ... ("name", { "single"; "complete"; "average"; "weighted"; "centroid"; "median"; "ward" }, "distfunc", {(@(x) min(x)) # single (@(x) max(x)) # complete (@(x,i,j,w) sum(diag(q=w([i,j]))*x)/sum(q)) # average (@(x) mean(x)) # weighted (@massdist) # centroid (@(x,i) massdist(x,i)) # median (@inertialdist) # ward }); mask = strcmp (lower (method), {methods.name}); if (! any (mask)) error ("linkage: %s: unknown method", method); endif dist = {methods.distfunc}{mask}; if (nargin == 3) if (ischar (distarg)) d = pdist (d, distarg); elseif (iscell (distarg)) d = pdist (d, distarg{:}); else print_usage (); endif endif d = squareform (d, "tomatrix"); # dissimilarity NxN matrix n = rows (d); # the number of observations diagidx = sub2ind ([n,n], 1:n, 1:n); # indices of diagonal elements d(diagidx) = Inf; # consider a cluster as far from itself ## For equal-distance nodes, the order in which clusters are ## merged is arbitrary. Rotating the initial matrix produces an ## ordering similar to Matlab's. cname = n:-1:1; # cluster names in d d = rot90 (d, 2); # exchange low and high cluster numbers weight = ones (1, n); # cluster weights dgram = zeros (n-1, 3); # clusters from n+1 to 2*n-1 for cluster = n+1:2*n-1 ## Find the two nearest clusters [m midx] = min (d(:)); [r, c] = ind2sub (size (d), midx); ## Here is the new cluster dgram(cluster-n, :) = [cname(r) cname(c) d(r, c)]; ## Put it in place of the first one and remove the second cname(r) = cluster; cname(c) = []; ## Compute the new distances newd = dist (d([r c], :), r, c, weight); newd(r) = Inf; # take care of the diagonal element ## Put distances in place of the first ones, remove the second ones d(r,:) = newd; d(:,r) = newd'; d(c,:) = []; d(:,c) = []; ## The new weight is the sum of the components' weights weight(r) += weight(c); weight(c) = []; endfor ## Sort the cluster numbers, as Matlab does dgram(:,1:2) = sort (dgram(:,1:2), 2); ## Check that distances are monotonically increasing if (any (diff (dgram(:,3)) < 0)) warning ("clustering", "linkage: cluster distances do not monotonically increase\n\ you should probably use a method different from \"%s\"", method); endif endfunction ## Take two row vectors, which are the Euclidean distances of clusters I ## and J from the others. Column I of second row contains the distance ## between clusters I and J. The centre of gravity of the new cluster ## is on the segment joining the old ones. W are the weights of all ## clusters. Use the law of cosines to find the distances of the new ## cluster from all the others. function y = massdist (x, i, j, w) x .^= 2; # squared Euclidean distances if (nargin == 2) # median distance qi = 0.5; # equal weights ("weighted") else # centroid distance qi = 1 / (1 + w(j) / w(i)); # proportional weights ("unweighted") endif y = sqrt (qi*x(1,:) + (1-qi)*(x(2,:) - qi*x(2,i))); endfunction ## Take two row vectors, which are the inertial distances of clusters I ## and J from the others. Column I of second row contains the inertial ## distance between clusters I and J. The centre of gravity of the new ## cluster K is on the segment joining I and J. W are the weights of ## all clusters. Convert inertial to Euclidean distances, then use the ## law of cosines to find the Euclidean distances of K from all the ## other clusters, convert them back to inertial distances and return ## them. function y = inertialdist (x, i, j, w) wi = w(i); wj = w(j); # the cluster weights s = [wi + w; wj + w]; # sum of weights for all cluster pairs p = [wi * w; wj * w]; # product of weights for all cluster pairs x = x.^2 .* s ./ p; # convert inertial dist. to squared Eucl. sij = wi + wj; # sum of weights of I and J qi = wi/sij; # normalise the weight of I ## Squared Euclidean distances between all clusters and new cluster K x = qi*x(1,:) + (1-qi)*(x(2,:) - qi*x(2,i)); y = sqrt (x * sij .* w ./ (sij + w)); # convert Eucl. dist. to inertial endfunction %!shared x, t %! x = reshape(mod(magic(6),5),[],3); %! t = 1e-6; %!assert (cond (linkage (pdist (x))), 34.119045,t); %!assert (cond (linkage (pdist (x), "complete")), 21.793345,t); %!assert (cond (linkage (pdist (x), "average")), 27.045012,t); %!assert (cond (linkage (pdist (x), "weighted")), 27.412889,t); %! lastwarn(); # Clear last warning before the test %!warning linkage (pdist (x), "centroid"); %!test warning off clustering %! assert (cond (linkage (pdist (x), "centroid")), 27.457477,t); %! warning on clustering %!warning linkage (pdist (x), "median"); %!test warning off clustering %! assert (cond (linkage (pdist (x), "median")), 27.683325,t); %! warning on clustering %!assert (cond (linkage (pdist (x), "ward")), 17.195198,t); %!assert (cond (linkage(x,"ward","euclidean")), 17.195198,t); %!assert (cond (linkage(x,"ward",{"euclidean"})), 17.195198,t); %!assert (cond (linkage(x,"ward",{"minkowski",2})),17.195198,t); statistics-1.4.1/inst/PaxHeaders.29769/dendrogram.m0000644000000000000000000000006213443447555016761 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/dendrogram.m0000644000175000017500000000641613443447555017477 0ustar00johndjohnd00000000000000%% Copyright (c) 2012 Juan Pablo Carbajal %% %% This program is free software: you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published by %% the Free Software Foundation, either version 3 of the License, or %% any later version. %% %% This program is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty of %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %% GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public License %% along with this program. If not, see . %% -*- texinfo -*- %% @deftypefn {Function File} {@var{p} = } dendrogram (@var{tree}) %% @deftypefnx {Function File} {@var{p, t} = } dendrogram (@var{tree}) %% @deftypefnx {Function File} {@var{p, t, perm} = } dendrogram (@var{tree}) %% Plots a dendrogram using the output of function @command{linkage}. %% %% t is a vector containing the leaf node number for each object in the %% original dataset. For now, all objects are leaf nodes. %% %% perm is the permutation of the input objects used to display the %% dendrogram, in left-to-right order. %% %% TODO: Return handle to lines to set properties %% TODO: Rescale the plot automatically based on data. %% %% @seealso{linkage} %% @end deftypefn function [p, t, perm] = dendrogram (tree) [m d] = size (tree); if d != 3 error ("Input data must be a tree as returned by function linkage.") end n = m + 1; % t is the leaf node number for all objects in the original dataset. % TODO: Add support for collapsing the tree. % For now, we always display all objects, so this is the identity map. t = (1:m)'; nc = max(tree(:,1:2)(:)); % Vector with the horizontal and vertical position of each cluster p = zeros (nc,2); perm = zeros (n,1); %% Ordering by depth-first search nodecount = 0; nodes_to_visit = nc+1; while !isempty(nodes_to_visit) currentnode = nodes_to_visit(1); nodes_to_visit(1) = []; if currentnode > n node = currentnode - n; nodes_to_visit = [tree(node,[2 1]) nodes_to_visit]; end if currentnode <= n && p(currentnode,1) == 0 nodecount +=1; p(currentnode,1) = nodecount; perm(nodecount) = currentnode; end end % Compute the horizontal position, begin-end % and vertical position of all clusters. for i = 1:m p(n+i,1) = mean (p(tree(i,1:2),1)); p(n+i,2) = tree(i,3); x(i,1:2) = p(tree(i,1:2),1); end figure(gcf) % plot horizontal lines tmp = line (x', tree(:,[3 3])'); % plot vertical lines [~,tf] = ismember (1:nc, tree(:,1:2)); [ind,~] = ind2sub (size (tree(:,1:2)), tf); y = [p(1:nc,2) tree(ind,3)]; tmp = line ([p(1:nc,1) p(1:nc,1)]',y'); xticks = 1:n; xl_txt = arrayfun (@num2str, perm,"uniformoutput",false); set (gca,"xticklabel",xl_txt,"xtick",xticks); axis ([0.5 n+0.5 0 max(tree(:,3))+0.1*min(tree(:,3))]); endfunction %!demo %! y = [4 5; 2 6; 3 7; 8 9; 1 10]; %! y(:,3) = 1:5; %! figure(gcf); clf; %! dendrogram(y); %!demo %! v = 2*rand(30,1)-1; %! d = abs(bsxfun(@minus, v(:,1), v(:,1)')); %! y = linkage (squareform(d,"tovector")); %! figure(gcf); clf; %! dendrogram(y); statistics-1.4.1/inst/PaxHeaders.29769/bbsrnd.m0000644000000000000000000000006213443447555016111 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/bbsrnd.m0000644000175000017500000001244113443447555016622 0ustar00johndjohnd00000000000000## Copyright (C) 2018 John Donoghue ## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} bbsrnd (@var{shape}, @var{scale}, @var{location}) ## @deftypefnx {} {} bbsrnd (@var{shape}, @var{scale}, @var{location}, @var{r}) ## @deftypefnx {} {} bbsrnd (@var{shape}, @var{scale}, @var{location}, @var{r}, @var{c}, @dots{}) ## @deftypefnx {} {} bbsrnd (@var{shape}, @var{scale}, @var{location}, [@var{sz}]) ## Return a matrix of random samples from the Birnbaum-Saunders ## distribution with parameters @var{location}, @var{scale} and @var{shape}. ## ## When called with a single size argument, return a square matrix with ## the dimension specified. When called with more than one scalar argument the ## first two arguments are taken as the number of rows and columns and any ## further arguments specify additional matrix dimensions. The size may also ## be specified with a vector of dimensions @var{sz}. ## ## If no size arguments are given then the result matrix is the common size of ## @var{location}, @var{scale} and @var{shape}. ## @end deftypefn ## Author: Dag Lyberg ## Description: Random deviates from the Birnbaum-Saunders distribution function rnd = bbsrnd (shape, scale, location, varargin) if (nargin < 3) print_usage (); endif if (! isscalar (location) || ! isscalar (scale) || ! isscalar (shape)) [retval, location, scale, shape] = common_size (location, scale, shape); if (retval > 0) error ("bbsrnd: LOCATION, SCALE and SHAPE must be of common size or scalars"); endif endif if (iscomplex (location) || iscomplex (scale) || iscomplex (shape)) error ("bbsrnd: LOCATION, SCALE and SHAPE must not be complex"); endif if (nargin == 3) sz = size (location); elseif (nargin == 4) if (isscalar (varargin{1}) && varargin{1} >= 0) sz = [varargin{1}, varargin{1}]; elseif (isrow (varargin{1}) && all (varargin{1} >= 0)) sz = varargin{1}; else error ("bbsrnd: dimension vector must be row vector of non-negative integers"); endif elseif (nargin > 3) if (any (cellfun (@(x) (! isscalar (x) || x < 0), varargin))) error ("bbsrnd: dimensions must be non-negative integers"); endif sz = [varargin{:}]; endif if (! isscalar (location) && ! isequal (size (location), sz)) error ("bbsrnd: LOCATION, SCALE and SHAPE must be scalar or of size SZ"); endif if (isa (location, "single") || isa (scale, "single") || isa (shape, "single")) cls = "single"; else cls = "double"; endif if (isscalar (location) && isscalar (scale) && isscalar (shape)) if ((-Inf < location) && (location < Inf) ... && (0 < scale) && (scale < Inf) ... && (0 < shape) && (shape < Inf)) rnd = rand(sz,cls); y = shape * norminv (rnd); rnd = location + scale * (y + sqrt (4 + y.^2)).^2 / 4; else rnd = NaN (sz, cls); endif else rnd = NaN (sz, cls); k = (-Inf < location) & (location < Inf) ... & (0 < scale) & (scale < Inf) ... & (0 < shape) & (shape < Inf); rnd(k) = rand(sum(k(:)),1); y = shape(k) .* norminv (rnd(k)); rnd(k) = location(k) + scale(k) .* (y + sqrt (4 + y.^2)).^2 / 4; endif endfunction %!assert (size (bbsrnd (1, 1, 0)), [1 1]) %!assert (size (bbsrnd (1, 1, zeros (2,1))), [2, 1]) %!assert (size (bbsrnd (1, 1, zeros (2,2))), [2, 2]) %!assert (size (bbsrnd (1, ones (2,1), 0)), [2, 1]) %!assert (size (bbsrnd (1, ones (2,2), 0)), [2, 2]) %!assert (size (bbsrnd (ones (2,1), 1, 0)), [2, 1]) %!assert (size (bbsrnd (ones (2,2), 1, 0)), [2, 2]) %!assert (size (bbsrnd (1, 1, 0, 3)), [3, 3]) %!assert (size (bbsrnd (1, 1, 0, [4 1])), [4, 1]) %!assert (size (bbsrnd (1, 1, 0, 4, 1)), [4, 1]) ## Test class of input preserved %!assert (class (bbsrnd (1,1,0)), "double") %!assert (class (bbsrnd (1, 1, single (0))), "single") %!assert (class (bbsrnd (1, 1, single ([0 0]))), "single") %!assert (class (bbsrnd (1, single (1), 0)), "single") %!assert (class (bbsrnd (1, single ([1 1]), 0)), "single") %!assert (class (bbsrnd (single (1), 1, 0)), "single") %!assert (class (bbsrnd (single ([1 1]), 1, 0)), "single") ## Test input validation %!error bbsrnd () %!error bbsrnd (1) %!error bbsrnd (1,2) %!error bbsrnd (ones (3), ones (2), ones (2), 2) %!error bbsrnd (ones (2), ones (3), ones (2), 2) %!error bbsrnd (ones (2), ones (2), ones (3), 2) %!error bbsrnd (i, 2, 3) %!error bbsrnd (1, i, 3) %!error bbsrnd (1, 2, i) %!error bbsrnd (1,2,3, -1) %!error bbsrnd (1,2,3, ones (2)) %!error bbsrnd (1,2,3, [2 -1 2]) %!error bbsrnd (2, 1, ones (2), 3) %!error bbsrnd (2, 1, ones (2), [3, 2]) %!error bbsrnd (2, 1, ones (2), 3, 2) statistics-1.4.1/inst/PaxHeaders.29769/mvtcdf.m0000644000000000000000000000006213443447555016122 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/mvtcdf.m0000644000175000017500000001123413443447555016632 0ustar00johndjohnd00000000000000## Copyright (C) 2008 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{p} =} mvtcdf (@var{x}, @var{sigma}, @var{nu}) ## @deftypefnx {Function File} {} mvtcdf (@var{a}, @var{x}, @var{sigma}, @var{nu}) ## @deftypefnx {Function File} {[@var{p}, @var{err}] =} mvtcdf (@dots{}) ## Compute the cumulative distribution function of the multivariate ## Student's t distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} is the upper limit for integration where each row corresponds ## to an observation. ## ## @item ## @var{sigma} is the correlation matrix. ## ## @item ## @var{nu} is the degrees of freedom. ## ## @item ## @var{a} is the lower limit for integration where each row corresponds ## to an observation. @var{a} must have the same size as @var{x}. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{p} is the cumulative distribution at each row of @var{x} and ## @var{a}. ## ## @item ## @var{err} is the estimated error. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = [1 2]; ## sigma = [1.0 0.5; 0.5 1.0]; ## nu = 4; ## p = mvtcdf (x, sigma, nu) ## @end group ## ## @group ## a = [-inf 0]; ## p = mvtcdf (a, x, sigma, nu) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Alan Genz and Frank Bretz. Numerical Computation of Multivariate ## t-Probabilities with Application to Power Calculation of Multiple ## Constrasts. @cite{Journal of Statistical Computation and Simulation}, ## 63, pages 361-378, 1999. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: CDF of the multivariate Student's t distribution function [p, err] = mvtcdf (varargin) # Monte-Carlo confidence factor for the standard error: 99 % gamma = 2.5; # Tolerance err_eps = 1e-3; if (length (varargin) == 3) x = varargin{1}; sigma = varargin{2}; nu = varargin{3}; a = -Inf .* ones (size (x)); elseif (length (varargin) == 4) a = varargin{1}; x = varargin{2}; sigma = varargin{3}; nu = varargin{4}; else print_usage (); endif # Dimension q = size (sigma, 1); cases = size (x, 1); # Check parameters if (size (x, 2) != q) error ("mvtcdf: x must have the same number of columns as sigma"); endif if (any (size (x) != size (a))) error ("mvtcdf: a must have the same size as x"); endif if (! isscalar (nu) && (! isvector (nu) || length (nu) != cases)) error ("mvtcdf: nu must be a scalar or a vector with the same number of rows as x"); endif # Convert to correlation matrix if necessary if (any (diag (sigma) != 1)) svar = repmat (diag (sigma), 1, q); sigma = sigma ./ sqrt (svar .* svar'); endif if (q < 1 || size (sigma, 2) != q || any (any (sigma != sigma')) || min (eig (sigma)) <= 0) error ("mvtcdf: sigma must be nonempty symmetric positive definite"); endif nu = nu(:); c = chol (sigma)'; # Number of integral transformations n = 1; p = zeros (cases, 1); varsum = zeros (cases, 1); err = ones (cases, 1) .* err_eps; # Apply crude Monte-Carlo estimation while any (err >= err_eps) # Sample from q-1 dimensional unit hypercube w = rand (cases, q - 1); # Transformation of the multivariate t-integral dvev = tcdf ([a(:, 1) / c(1, 1), x(:, 1) / c(1, 1)], nu); dv = dvev(:, 1); ev = dvev(:, 2); fv = ev - dv; y = zeros (cases, q - 1); for i = 1:(q - 1) y(:, i) = tinv (dv + w(:, i) .* (ev - dv), nu + i - 1) .* sqrt ((nu + sum (y(:, 1:(i-1)) .^ 2, 2)) ./ (nu + i - 1)); tf = (sqrt ((nu + i) ./ (nu + sum (y(:, 1:i) .^ 2, 2)))) ./ c(i + 1, i + 1); dvev = tcdf ([(a(:, i + 1) - c(i + 1, 1:i) .* y(:, 1:i)) .* tf, (x(:, i + 1) - c(i + 1, 1:i) .* y(:, 1:i)) .* tf], nu + i); dv = dvev(:, 1); ev = dvev(:, 2); fv = (ev - dv) .* fv; endfor n++; # Estimate standard error varsum += (n - 1) .* ((fv - p) .^ 2) ./ n; err = gamma .* sqrt (varsum ./ (n .* (n - 1))); p += (fv - p) ./ n; endwhile endfunction statistics-1.4.1/inst/PaxHeaders.29769/random.m0000644000000000000000000000006213443447555016117 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/random.m0000644000175000017500000001546213443447555016636 0ustar00johndjohnd00000000000000## Copyright (C) 2007 Soren Hauberg ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} @var{r} = random(@var{name}, @var{arg1}) ## @deftypefnx{Function File} @var{r} = random(@var{name}, @var{arg1}, @var{arg2}) ## @deftypefnx{Function File} @var{r} = random(@var{name}, @var{arg1}, @var{arg2}, @var{arg3}) ## @deftypefnx{Function File} @var{r} = random(@var{name}, ..., @var{s1}, ...) ## Generates pseudo-random numbers from a given one-, two-, or three-parameter ## distribution. ## ## The variable @var{name} must be a string that names the distribution from ## which to sample. If this distribution is a one-parameter distribution @var{arg1} ## should be supplied, if it is a two-paramter distribution @var{arg2} must also ## be supplied, and if it is a three-parameter distribution @var{arg3} must also ## be present. Any arguments following the distribution paramters will determine ## the size of the result. ## ## As an example, the following code generates a 10 by 20 matrix containing ## random numbers from a normal distribution with mean 5 and standard deviation ## 2. ## @example ## R = random("normal", 5, 2, [10, 20]); ## @end example ## ## The variable @var{name} can be one of the following strings ## ## @table @asis ## @item "beta" ## @itemx "beta distribution" ## Samples are drawn from the Beta distribution. ## @item "bino" ## @itemx "binomial" ## @itemx "binomial distribution" ## Samples are drawn from the Binomial distribution. ## @item "chi2" ## @itemx "chi-square" ## @itemx "chi-square distribution" ## Samples are drawn from the Chi-Square distribution. ## @item "exp" ## @itemx "exponential" ## @itemx "exponential distribution" ## Samples are drawn from the Exponential distribution. ## @item "f" ## @itemx "f distribution" ## Samples are drawn from the F distribution. ## @item "gam" ## @itemx "gamma" ## @itemx "gamma distribution" ## Samples are drawn from the Gamma distribution. ## @item "geo" ## @itemx "geometric" ## @itemx "geometric distribution" ## Samples are drawn from the Geometric distribution. ## @item "hyge" ## @itemx "hypergeometric" ## @itemx "hypergeometric distribution" ## Samples are drawn from the Hypergeometric distribution. ## @item "logn" ## @itemx "lognormal" ## @itemx "lognormal distribution" ## Samples are drawn from the Log-Normal distribution. ## @item "nbin" ## @itemx "negative binomial" ## @itemx "negative binomial distribution" ## Samples are drawn from the Negative Binomial distribution. ## @item "norm" ## @itemx "normal" ## @itemx "normal distribution" ## Samples are drawn from the Normal distribution. ## @item "poiss" ## @itemx "poisson" ## @itemx "poisson distribution" ## Samples are drawn from the Poisson distribution. ## @item "rayl" ## @itemx "rayleigh" ## @itemx "rayleigh distribution" ## Samples are drawn from the Rayleigh distribution. ## @item "t" ## @itemx "t distribution" ## Samples are drawn from the T distribution. ## @item "unif" ## @itemx "uniform" ## @itemx "uniform distribution" ## Samples are drawn from the Uniform distribution. ## @item "unid" ## @itemx "discrete uniform" ## @itemx "discrete uniform distribution" ## Samples are drawn from the Uniform Discrete distribution. ## @item "wbl" ## @itemx "weibull" ## @itemx "weibull distribution" ## Samples are drawn from the Weibull distribution. ## @end table ## @seealso{rand, betarnd, binornd, chi2rnd, exprnd, frnd, gamrnd, geornd, hygernd, ## lognrnd, nbinrnd, normrnd, poissrnd, raylrnd, trnd, unifrnd, unidrnd, wblrnd} ## @end deftypefn function retval = random(name, varargin) ## General input checking if (nargin < 2) print_usage(); endif if (!ischar(name)) error("random: first input argument must be a string"); endif ## Select distribution switch (lower(name)) case {"beta", "beta distribution"} retval = betarnd(varargin{:}); case {"bino", "binomial", "binomial distribution"} retval = binornd(varargin{:}); case {"chi2", "chi-square", "chi-square distribution"} retval = chi2rnd(varargin{:}); case {"exp", "exponential", "exponential distribution"} retval = exprnd(varargin{:}); case {"ev", "extreme value", "extreme value distribution"} error("random: distribution type '%s' is not yet implemented", name); case {"f", "f distribution"} retval = frnd(varargin{:}); case {"gam", "gamma", "gamma distribution"} retval = gamrnd(varargin{:}); case {"gev", "generalized extreme value", "generalized extreme value distribution"} error("random: distribution type '%s' is not yet implemented", name); case {"gp", "generalized pareto", "generalized pareto distribution"} error("random: distribution type '%s' is not yet implemented", name); case {"geo", "geometric", "geometric distribution"} retval = geornd(varargin{:}); case {"hyge", "hypergeometric", "hypergeometric distribution"} retval = hygernd(varargin{:}); case {"logn", "lognormal", "lognormal distribution"} retval = lognrnd(varargin{:}); case {"nbin", "negative binomial", "negative binomial distribution"} retval = nbinrnd(varargin{:}); case {"ncf", "noncentral f", "noncentral f distribution"} error("random: distribution type '%s' is not yet implemented", name); case {"nct", "noncentral t", "noncentral t distribution"} error("random: distribution type '%s' is not yet implemented", name); case {"ncx2", "noncentral chi-square", "noncentral chi-square distribution"} error("random: distribution type '%s' is not yet implemented", name); case {"norm", "normal", "normal distribution"} retval = normrnd(varargin{:}); case {"poiss", "poisson", "poisson distribution"} retval = poissrnd(varargin{:}); case {"rayl", "rayleigh", "rayleigh distribution"} retval = raylrnd(varargin{:}); case {"t", "t distribution"} retval = trnd(varargin{:}); case {"unif", "uniform", "uniform distribution"} retval = unifrnd(varargin{:}); case {"unid", "discrete uniform", "discrete uniform distribution"} retval = unidrnd(varargin{:}); case {"wbl", "weibull", "weibull distribution"} retval = wblrnd(varargin{:}); otherwise error("random: unsupported distribution type '%s'", name); endswitch endfunction statistics-1.4.1/inst/PaxHeaders.29769/trimmean.m0000644000000000000000000000006213443447555016453 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/trimmean.m0000644000175000017500000000317613443447555017171 0ustar00johndjohnd00000000000000## Copyright (C) 2001 Paul Kienzle ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{a} =} trimmean (@var{x}, @var{p}) ## ## Compute the trimmed mean. ## ## The trimmed mean of @var{x} is defined as the mean of @var{x} excluding the ## highest and lowest @var{p} percent of the data. ## ## For example ## ## @example ## mean ([-inf, 1:9, inf]) ## @end example ## ## is NaN, while ## ## @example ## trimmean ([-inf, 1:9, inf], 10) ## @end example ## ## excludes the infinite values, which make the result 5. ## ## @seealso{mean} ## @end deftypefn function a = trimmean(x, p, varargin) if (nargin != 2 && nargin != 3) print_usage; endif y = sort(x, varargin{:}); sz = size(x); if nargin < 3 dim = min(find(sz>1)); if isempty(dim), dim=1; endif; else dim = varargin{1}; endif idx = cell (0); for i=1:length(sz), idx{i} = 1:sz(i); end; trim = round(sz(dim)*p*0.01); idx{dim} = 1+trim : sz(dim)-trim; a = mean (y (idx{:}), varargin{:}); endfunction statistics-1.4.1/inst/PaxHeaders.29769/nbinstat.m0000644000000000000000000000006213443447555016461 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nbinstat.m0000644000175000017500000000643013443447555017173 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} nbinstat (@var{n}, @var{p}) ## Compute mean and variance of the negative binomial distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{n} is the first parameter of the negative binomial distribution. The elements ## of @var{n} must be natural numbers ## ## @item ## @var{p} is the second parameter of the negative binomial distribution. The ## elements of @var{p} must be probabilities ## @end itemize ## @var{n} and @var{p} must be of common size or one of them must be scalar ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the negative binomial distribution ## ## @item ## @var{v} is the variance of the negative binomial distribution ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## n = 1:4; ## p = 0.2:0.2:0.8; ## [m, v] = nbinstat (n, p) ## @end group ## ## @group ## [m, v] = nbinstat (n, 0.5) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the negative binomial distribution function [m, v] = nbinstat (n, p) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (n) && ! ismatrix (n)) error ("nbinstat: n must be a numeric matrix"); endif if (! isempty (p) && ! ismatrix (p)) error ("nbinstat: p must be a numeric matrix"); endif if (! isscalar (n) || ! isscalar (p)) [retval, n, p] = common_size (n, p); if (retval > 0) error ("nbinstat: n and p must be of common size or scalar"); endif endif # Calculate moments q = 1 - p; m = n .* q ./ p; v = n .* q ./ (p .^ 2); # Continue argument check k = find (! (n > 0) | ! (n < Inf) | ! (p > 0) | ! (p < 1)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!test %! n = 1:4; %! p = 0.2:0.2:0.8; %! [m, v] = nbinstat (n, p); %! expected_m = [ 4.0000, 3.0000, 2.0000, 1.0000]; %! expected_v = [20.0000, 7.5000, 3.3333, 1.2500]; %! assert (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); %!test %! n = 1:4; %! [m, v] = nbinstat (n, 0.5); %! expected_m = [1, 2, 3, 4]; %! expected_v = [2, 4, 6, 8]; %! assert (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/gppdf.m0000644000000000000000000000006213443447555015737 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gppdf.m0000644000175000017500000001427513443447555016457 0ustar00johndjohnd00000000000000## Copyright (C) 2018 John Donoghue ## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1997-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} gppdf (@var{x}, @var{shape}, @var{scale}, @var{location}) ## Compute the probability density function (PDF) at @var{x} of the ## generalized Pareto distribution with parameters @var{location}, @var{scale}, ## and @var{shape}. ## @end deftypefn ## Author: Dag Lyberg ## Description: PDF of the generalized Pareto distribution function pdf = gppdf (x, shape, scale, location) if (nargin != 4) print_usage (); endif if (! isscalar (location) || ! isscalar (scale) || ! isscalar (shape)) [retval, x, location, scale, shape] = ... common_size (x, location, scale, shape); if (retval > 0) error ("gppdf: X, LOCATION, SCALE and SHAPE must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (location) || iscomplex (scale) ... || iscomplex (shape)) error ("gppdf: X, LOCATION, SCALE and SHAPE must not be complex"); endif if (isa (x, "single") || isa (location, "single") || isa (scale, "single") ... || isa (shape, "single")) pdf = zeros (size (x), "single"); else pdf = zeros (size (x)); endif k = isnan (x) | ! (-Inf < location) | ! (location < Inf) | ... ! (scale > 0) | ! (scale < Inf) | ! (-Inf < shape) | ! (shape < Inf); pdf(k) = NaN; k = (-Inf < x) & (x < Inf) & (-Inf < location) & (location < Inf) & ... (scale > 0) & (scale < Inf) & (-Inf < shape) & (shape < Inf); if (isscalar (location) && isscalar (scale) && isscalar (shape)) z = (x - location) / scale; j = k & (shape == 0) & (z >= 0); if (any (j)) pdf(j) = exp (-z(j)); endif j = k & (shape > 0) & (z >= 0); if (any (j)) pdf(j) = (shape * z(j) + 1).^(-(shape + 1) / shape) ./ scale; endif if (shape < 0) j = k & (shape < 0) & (0 <= z) & (z <= -1. / shape); if (any (j)) pdf(j) = (shape * z(j) + 1).^(-(shape + 1) / shape) ./ scale; endif endif else z = (x - location) ./ scale; j = k & (shape == 0) & (z >= 0); if (any (j)) pdf(j) = exp( -z(j)); endif j = k & (shape > 0) & (z >= 0); if (any (j)) pdf(j) = (shape(j) .* z(j) + 1).^(-(shape(j) + 1) ./ shape(j)) ./ scale(j); endif if (any (shape < 0)) j = k & (shape < 0) & (0 <= z) & (z <= -1 ./ shape); if (any (j)) pdf(j) = (shape(j) .* z(j) + 1).^(-(shape(j) + 1) ./ shape(j)) ./ scale(j); endif endif endif endfunction %!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 (gppdf (x, zeros (1,6), ones (1,6), zeros (1,6)), y1, eps) %!assert (gppdf (x, 0, 1, zeros (1,6)), y1, eps) %!assert (gppdf (x, 0, ones (1,6), 0), y1, eps) %!assert (gppdf (x, zeros (1,6), 1, 0), y1, eps) %!assert (gppdf (x, 0, 1, 0), y1, eps) %!assert (gppdf (x, 0, 1, [0, 0, 0, NaN, 0, 0]), [y1(1:3), NaN, y1(5:6)]) %!assert (gppdf (x, 0, [1, 1, 1, NaN, 1, 1], 0), [y1(1:3), NaN, y1(5:6)]) %!assert (gppdf (x, [0, 0, 0, NaN, 0, 0], 1, 0), [y1(1:3), NaN, y1(5:6)]) %!assert (gppdf ([x(1:3), NaN, x(5:6)], 0, 1, 0), [y1(1:3), NaN, y1(5:6)]) %!assert (gppdf (x, ones (1,6), ones (1,6), zeros (1,6)), y2, eps) %!assert (gppdf (x, 1, 1, zeros (1,6)), y2, eps) %!assert (gppdf (x, 1, ones (1,6), 0), y2, eps) %!assert (gppdf (x, ones (1,6), 1, 0), y2, eps) %!assert (gppdf (x, 1, 1, 0), y2, eps) %!assert (gppdf (x, 1, 1, [0, 0, 0, NaN, 0, 0]), [y2(1:3), NaN, y2(5:6)]) %!assert (gppdf (x, 1, [1, 1, 1, NaN, 1, 1], 0), [y2(1:3), NaN, y2(5:6)]) %!assert (gppdf (x, [1, 1, 1, NaN, 1, 1], 1, 0), [y2(1:3), NaN, y2(5:6)]) %!assert (gppdf ([x(1:3), NaN, x(5:6)], 1, 1, 0), [y2(1:3), NaN, y2(5:6)]) %!assert (gppdf (x, -ones (1,6), ones (1,6), zeros (1,6)), y3, eps) %!assert (gppdf (x, -1, 1, zeros (1,6)), y3, eps) %!assert (gppdf (x, -1, ones (1,6), 0), y3, eps) %!assert (gppdf (x, -ones (1,6), 1, 0), y3, eps) %!assert (gppdf (x, -1, 1, 0), y3, eps) %!assert (gppdf (x, -1, 1, [0, 0, 0, NaN, 0, 0]), [y3(1:3), NaN, y3(5:6)]) %!assert (gppdf (x, -1, [1, 1, 1, NaN, 1, 1], 0), [y3(1:3), NaN, y3(5:6)]) %!assert (gppdf (x, [-1, -1, -1, NaN, -1, -1], 1, 0), [y3(1:3), NaN, y3(5:6)]) %!assert (gppdf ([x(1:3), NaN, x(5:6)], -1, 1, 0), [y3(1:3), NaN, y3(5:6)]) ## Test class of input preserved %!assert (gppdf (single ([x, NaN]), 0, 1, 0), single ([y1, NaN])) %!assert (gppdf ([x, NaN], 0, 1, single (0)), single ([y1, NaN])) %!assert (gppdf ([x, NaN], 0, single (1), 0), single ([y1, NaN])) %!assert (gppdf ([x, NaN], single (0), 1, 0), single ([y1, NaN])) %!assert (gppdf (single ([x, NaN]), 1, 1, 0), single ([y2, NaN])) %!assert (gppdf ([x, NaN], 1, 1, single (0)), single ([y2, NaN])) %!assert (gppdf ([x, NaN], 1, single (1), 0), single ([y2, NaN])) %!assert (gppdf ([x, NaN], single (1), 1, 0), single ([y2, NaN])) %!assert (gppdf (single ([x, NaN]), -1, 1, 0), single ([y3, NaN])) %!assert (gppdf ([x, NaN], -1, 1, single (0)), single ([y3, NaN])) %!assert (gppdf ([x, NaN], -1, single (1), 0), single ([y3, NaN])) %!assert (gppdf ([x, NaN], single (-1), 1, 0), single ([y3, NaN])) ## Test input validation %!error gppdf () %!error gppdf (1) %!error gppdf (1,2) %!error gppdf (1,2,3) %!error gppdf (1,2,3,4,5) %!error gppdf (1, ones (2), ones (2), ones (3)) %!error gppdf (1, ones (2), ones (3), ones (2)) %!error gppdf (1, ones (3), ones (2), ones (2)) %!error gppdf (i, 2, 2, 2) %!error gppdf (2, i, 2, 2) %!error gppdf (2, 2, i, 2) %!error gppdf (2, 2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/nakapdf.m0000644000000000000000000000006213443447555016243 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nakapdf.m0000644000175000017500000000611713443447555016757 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} nakapdf (@var{x}, @var{m}, @var{w}) ## For each element of @var{x}, compute the probability density function (PDF) ## at @var{x} of the Nakagami distribution with shape parameter @var{m} and ## scale parameter @var{w}. ## @end deftypefn ## Author: Dag Lyberg ## Description: PDF of the Nakagami distribution function pdf = nakapdf (x, m, w) if (nargin != 3) print_usage (); endif if (! isscalar (m) || ! isscalar (w)) [retval, x, m, w] = common_size (x, m, w); if (retval > 0) error ("nakapdf: X, M and W must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (m) || iscomplex (w)) error ("nakapdf: X, M and W must not be complex"); endif if (isa (x, "single") || isa (m, "single") || isa (w, "single")) pdf = zeros (size (x), "single"); else pdf = zeros (size (x)); endif k = isnan (x) | ! (m > 0.5) | ! (w > 0); pdf(k) = NaN; k = (0 < x) & (x < Inf) & (0 < m) & (m < Inf) & (0 < w) & (w < Inf); if (isscalar (m) && isscalar(w)) pdf(k) = exp (log (2) + m*log (m) - log (gamma (m)) - ... m*log (w) + (2*m-1) * ... log (x(k)) - (m/w) * x(k).^2); else pdf(k) = exp(log(2) + m(k).*log (m(k)) - log (gamma (m(k))) - ... m(k).*log (w(k)) + (2*m(k)-1) ... .* log (x(k)) - (m(k)./w(k)) .* x(k).^2); endif endfunction %!shared x,y %! x = [-1, 0, 1, 2, Inf]; %! y = [0, 0, 0.73575888234288467, 0.073262555554936715, 0]; %!assert (nakapdf (x, ones (1,5), ones (1,5)), y, eps) %!assert (nakapdf (x, 1, 1), y, eps) %!assert (nakapdf (x, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)], eps) %!assert (nakapdf (x, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)], eps) %!assert (nakapdf ([x, NaN], 1, 1), [y, NaN], eps) ## Test class of input preserved %!assert (nakapdf (single ([x, NaN]), 1, 1), single ([y, NaN])) %!assert (nakapdf ([x, NaN], single (1), 1), single ([y, NaN])) %!assert (nakapdf ([x, NaN], 1, single (1)), single ([y, NaN])) ## Test input validation %!error nakapdf () %!error nakapdf (1) %!error nakapdf (1,2) %!error nakapdf (1,2,3,4) %!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 (i, 2, 2) %!error nakapdf (2, i, 2) %!error nakapdf (2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/mnpdf.m0000644000000000000000000000006213443447555015743 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/mnpdf.m0000644000175000017500000000776613443447555016472 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Arno Onken ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} mnpdf (@var{x}, @var{p}) ## Compute the probability density function of the multinomial distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} is vector with a single sample of a multinomial distribution with ## parameter @var{p} or a matrix of random samples from multinomial ## distributions. In the latter case, each row of @var{x} is a sample from a ## multinomial distribution with the corresponding row of @var{p} being its ## parameter. ## ## @item ## @var{p} is a vector with the probabilities of the categories or a matrix ## with each row containing the probabilities of a multinomial sample. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{y} is a vector of probabilites of the random samples @var{x} from the ## multinomial distribution with corresponding parameter @var{p}. The parameter ## @var{n} of the multinomial distribution is the sum of the elements of each ## row of @var{x}. The length of @var{y} is the number of columns of @var{x}. ## If a row of @var{p} does not sum to @code{1}, then the corresponding element ## of @var{y} will be @code{NaN}. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = [1, 4, 2]; ## p = [0.2, 0.5, 0.3]; ## y = mnpdf (x, p); ## @end group ## ## @group ## x = [1, 4, 2; 1, 0, 9]; ## p = [0.2, 0.5, 0.3; 0.1, 0.1, 0.8]; ## y = mnpdf (x, p); ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, 2001. ## ## @item ## Merran Evans, Nicholas Hastings and Brian Peacock. @cite{Statistical ## Distributions}. pages 134-136, Wiley, New York, third edition, 2000. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: PDF of the multinomial distribution function y = mnpdf (x, p) # Check arguments if (nargin != 2) print_usage (); endif if (! ismatrix (x) || any (x(:) < 0 | round (x(:) != x(:)))) error ("mnpdf: x must be a matrix of non-negative integer values"); endif if (! ismatrix (p) || any (p(:) < 0)) error ("mnpdf: p must be a non-empty matrix with rows of probabilities"); endif # Adjust input sizes if (! isvector (x) || ! isvector (p)) if (isvector (x)) x = x(:)'; endif if (isvector (p)) p = p(:)'; endif if (size (x, 1) == 1 && size (p, 1) > 1) x = repmat (x, size (p, 1), 1); elseif (size (x, 1) > 1 && size (p, 1) == 1) p = repmat (p, size (x, 1), 1); endif endif # Continue argument check if (any (size (x) != size (p))) error ("mnpdf: x and p must have compatible sizes"); endif # Count total number of elements of each multinomial sample n = sum (x, 2); # Compute probability density function of the multinomial distribution t = x .* log (p); t(x == 0) = 0; y = exp (gammaln (n+1) - sum (gammaln (x+1), 2) + sum (t, 2)); # Set invalid rows to NaN k = (abs (sum (p, 2) - 1) > 1e-6); y(k) = NaN; endfunction %!test %! x = [1, 4, 2]; %! p = [0.2, 0.5, 0.3]; %! y = mnpdf (x, p); %! assert (y, 0.11812, 0.001); %!test %! x = [1, 4, 2; 1, 0, 9]; %! p = [0.2, 0.5, 0.3; 0.1, 0.1, 0.8]; %! y = mnpdf (x, p); %! assert (y, [0.11812; 0.13422], 0.001); statistics-1.4.1/inst/PaxHeaders.29769/jsupdf.m0000644000000000000000000000006213443447555016132 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/jsupdf.m0000644000175000017500000000414713443447555016647 0ustar00johndjohnd00000000000000## Copyright (C) 2006 Frederick (Rick) A Niles ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {} jsupdf (@var{x}, @var{alpha1}, @var{alpha2}) ## For each element of @var{x}, compute the probability density function ## (PDF) at @var{x} of the Johnson SU distribution with shape parameters @var{alpha1} ## and @var{alpha2}. ## ## Default values are @var{alpha1} = 1, @var{alpha2} = 1. ## @end deftypefn ## Author: Frederick (Rick) A Niles ## Description: PDF of Johnson SU distribution ## This function is derived from normpdf.m ## This is the TeX equation of this function: ## ## \[ f(x) = \frac{\alpha_2}{\sqrt{x^2+1}} \phi\left(\alpha_1+\alpha_2 ## \log{\left(x+\sqrt{x^2+1}\right)}\right) \] ## ## where \[ -\infty < x < \infty ; \alpha_2 > 0 \] and $\phi$ is the ## standard normal probability distribution function. $\alpha_1$ and ## $\alpha_2$ are shape parameters. function pdf = jsupdf (x, alpha1, alpha2) if (nargin != 1 && nargin != 3) print_usage; endif if (nargin == 1) alpha1 = 1; alpha2 = 1; endif if (!isscalar (alpha1) || !isscalar(alpha2)) [retval, x, alpha1, alpha2] = common_size (x, alpha1, alpha2); if (retval > 0) error ("normpdf: x, alpha1 and alpha2 must be of common size or scalars"); endif endif one = ones(size(x)); sr = sqrt(x.*x + one); pdf = (alpha2 ./ sr) .* stdnormal_pdf (alpha1 .* one + alpha2 .* log (x + sr)); endfunction statistics-1.4.1/inst/PaxHeaders.29769/fitgmdist.m0000644000000000000000000000006213443447555016631 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/fitgmdist.m0000644000175000017500000004377013443447555017353 0ustar00johndjohnd00000000000000## Copyright (C) 2018 John Donoghue ## Copyright (C) 2015 Lachlan Andrew ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{GMdist} =} fitgmdist (@var{data}, @var{k}, @var{param1}, @var{value1}, @dots{}) ## Fit a Gaussian mixture model with @var{k} components to @var{data}. ## Each row of @var{data} is a data sample. Each column is a variable. ## ## Optional parameters are: ## @itemize ## @item 'start': initialization conditions. Possible values are: ## @itemize ## @item 'randSample' (default) takes means uniformly from rows of data ## @item 'plus' use k-means++ to initialize means ## @item 'cluster' Performs an initial clustering with 10% of the data ## @item vector A vector whose length is the number of rows in data, ## and whose values are 1 to k specify the components ## each row is initially allocated to. The mean, variance ## and weight of each component is calculated from that ## @item structure with elements mu, Sigma ComponentProportion ## @end itemize ## For 'randSample', 'plus' and 'cluster', the initial variance of each ## component is the variance of the entire data sample. ## ## @item 'Replicates' Number of random restarts to perform ## ## @item 'RegularizationValue' ## @item 'Regularize' A small number added to the diagonal entries ## of the covariance to prevent singular covariances ## ## @item 'SharedCovariance' ## @item 'SharedCov' (logical) True if all components must share the ## same variance, to reduce the number of free parameters ## ## @item 'CovarianceType' ## @item 'CovType' (string). Possible values are: ## @itemize ## @item 'full' (default) Allow arbitrary covariance matrices ## @item 'diagonal' Force covariances to be diagonal, to reduce the ## number of free parameters. ## @end itemize ## ## @item 'Option' A structure with all of the following fields: ## @itemize ## @item 'MaxIter' Maximum number of EM iterations (default 100) ## @item 'TolFun' Threshold increase in likelihood to terminate EM ## (default 1e-6) ## @item 'Display' ## @itemize ## @item 'off' (default): display nothing ## @item 'final': display the number of iterations and likelihood ## once execution completes ## @item 'iter': display the above after each iteration ## @end itemize ## @end itemize ## @item 'Weight' A column vector or n-by-2 matrix. The first column ## consists of non-negative weights given to the ## samples. ## If these are all integers, this is equivalent ## to specifying @var{weight}(i) copies of row i of ## @var{data}, but potentially faster. ## ## If a row of @var{data} is used to represent samples ## that are similar but not identical, then the second ## column of @var{weight} indicates the variance of ## those original samples. Specifically, in the EM ## algorithm, the contribution of row i towards the ## variance is set to at least @var{weight}(i,2), to ## prevent spurious components with zero variance. ## @end itemize ## ## @seealso{gmdistribution, kmeans} ## @end deftypefn function obj = fitgmdist(data, k, varargin) if nargin < 2 || mod (nargin, 2) == 1 print_usage; endif [~, prop] = parseparams (varargin); ## defaults for options diagonalCovar = false; # "full". (true is "diagonal") sharedCovar = false; start = "randSample"; replicates = 1; option.MaxIter= 100; option.TolFun = 1e-6; option.Display= "off"; # "off" (1 is "final", 2 is "iter") Regularizer = 0; weights = []; # Each row i counts as "weights(i,1)" rows # Remove rows containing NaN / NA data = data(!any (isnan (data), 2),:); # used for getting the number of samples nRows = rows (data); nCols = columns (data); # Parse options while (!isempty (prop)) try switch (lower (prop{1})) case {"sharedcovariance",... "sharedcov"}, sharedCovar = prop{2}; case {"covariancetype",... "covartype"}, diagonalCovar = prop{2}; case {"regularizationvalue",... "regularize"}, Regularizer = prop{2}; case "replicates", replicates = prop{2}; case "start", start = prop{2}; case "weights", weights = prop{2}; case "option" option.MaxIter = prop{2}.MaxIter; option.TolFun = prop{2}.TolFun; option.Display = prop{2}.Display; otherwise error ("fitgmdist: Unknown option %s", prop{1}); endswitch catch ME if (length (prop) < 2) error ("fitgmdist: Option '%s' has no argument", prop{1}); else rethrow (ME) endif end_try_catch prop = prop(3:end); endwhile # Process options # check for the "replicates" property try if isempty (1:replicates) error ("fitgmdist: replicates must be positive"); endif catch error ("fitgmdist: invalid number of replicates"); end_try_catch # check for the "option" property MaxIter = option.MaxIter; TolFun = option.TolFun; switch (lower (option.Display)) case "off", Display = 0; case "final", Display = 1; case "iter", Display = 2; case "notify", Display = 0; otherwise, error ("fitgmdist: Unknown Display option %s", option.Display); endswitch try p = ones(1, k) / k; # Default is uniform component proportions catch ME if (!isscalar (k) || !isnumeric (k)) error ("fitgmdist: The second argument must be a numeric scalar"); else rethrow (ME) endif end_try_catch # check for the "start" property if (ischar (start)) start = lower (start); switch (start) case {"randsample", "plus", "cluster", "randsamplep", "plusp", "clusterp"} otherwise error ("fitgmdist: Unknown Start value %s\n", start); endswitch component_order_free = true; else component_order_free = false; if (!ismatrix (start) || !isnumeric (start)) try mu = start.mu; Sigma = start.Sigma; if (isfield (start, 'ComponentProprition')) p = start.ComponentProportion(:)'; end if (any (size (data, 2) ~= [size(mu,2), size(Sigma)]) || ... any (k ~= [size(mu,1), size(p,2)])) error ('fitgmdist: Start parameter has mismatched dimensions'); endif catch error ("fitgmdist: invalid start parameter"); end_try_catch if (isfield (start, "ComponentProprition")) p = start.ComponentProportion(:)'; endif else validIndices = 0; mu = zeros (k, nRows); Sigma = zeros (nRows, nRows, k); for i = 1:k idx = (start == i); validIndices = validIndices + sum (idx); mu(i,:) = mean (data(idx,:)); Sigma(:,:,i) = cov (data(idx,:)) + Regularizer*eye (nCols); endfor if (validIndices < nRows) error ("fitgmdist: Start is numeric, but is not integers between 1 and k"); endif endif start = []; # so that variance isn't recalculated later replicates = 1; # Will be the same each time anyway endif # check for the "SharedCovariance" property if (!islogical (sharedCovar)) error ("fitgmdist: SharedCoveriance must be logical true or false"); endif # check for the "CovarianceType" property if (!islogical (diagonalCovar)) try if (strcmpi (diagonalCovar, "diagonal")) diagonalCovar = true; elseif (strcmpi (diagonalCovar, "full")) diagonalCovar = false; else error ("fitgmdist: CovarianceType must be Full or Diagonal"); endif catch error ("fitgmdist: CovarianceType must be 'Full' or 'Diagonal'"); end_try_catch endif # check for the "Regularizer" property try if (Regularizer < 0) error ("fitgmdist: Regularizer must be non-negative"); endif catch ME if (!isscalar (Regularizer) || !isnumeric (Regularizer)) error ("fitgmdist: Regularizer must be a numeric scalar"); else rethrow (ME) endif end_try_catch # check for the "Weights" property and the matrix try if (!isempty (weights)) if (columns (weights) > 2 || any (weights(:) < 0)) error ("fitgmdist: weights must be a nonnegative numeric dx1 or dx2 matrix"); endif if (rows (weights) != nRows) error ("fitgmdist: number of weights %d must match number of samples %d",... rows (weights), nRows) endif non_zero = (weights(:,1) > 0); weights = weights(non_zero,:); data = data (non_zero,:); nRows = rows (data); raw_samples = sum (weights(:,1)); else raw_samples = nRows; endif # Validate the matrix if (!isreal (data(k,1))) error ("fitgmdist: first input argument must be a DxN real data matrix"); endif catch ME if (!isnumeric (data) || !ismatrix (data) || !isreal (data)) error ("fitgmdist: first input argument must be a DxN real data matrix"); elseif (k > nRows || k < 0) if (exists("non_zero", "var") && k <= length(non_zero)) error ("fitgmdist: The number of non-zero weights (%d) must be at least the number of components (%d)", nRows, k); else error ("fitgmdist: The number of components (%d) must be a positive number less than the number of data rows (%d)", k, nRows); endif elseif (!ismatrix (weights) || !isnumeric (weights)) error ("fitgmdist: weights must be a nonnegative numeric dx1 or dx2 matrix"); else rethrow (ME) endif end_try_catch #if k == 1 # replicates = 1; #endif # Done processing options ####################################### # used to hold the probability of each class, given each data vector try p_x_l = zeros (nRows, k); # probability of observation x given class l best = -realmax; best_params = []; diag_slice = 1:(nCols+1):(nCols)^2; # Create index slices to calculate symmetric completion of upper triangular Mx lower_half = zeros(nCols*(nCols-1)/2,1); upper_half = zeros(nCols*(nCols-1)/2,1); i = 1; for rw = 1:nCols for cl = rw+1:nCols upper_half(i) = sub2ind([nCols, nCols], rw, cl); lower_half(i) = sub2ind([nCols, nCols], cl, rw); i = i + 1; endfor endfor for rep = 1:replicates if (!isempty (start)) # Initialize the means switch (start) case {"randsample"} if (isempty (weights)) idx = randperm (nRows, k); else idx = randsample (nRows, k, false, weights); endif mu = data(idx, :); case {"plus"} # k-means++, by Arthur and Vassilios mu(1,:) = data(randi (nRows),:); d = inf (nRows, 1); # Distance to nearest centroid so far for i = 2:k d = min (d, sum (bsxfun (@minus, data, mu(i-1, :)).^2, 2)); # pick next sample with prob. prop to dist.*weights if (isempty (weights)) cs = cumsum (d); else cs = cumsum (d .* weights(:,1)); endif mu(i,:) = data(find (cs > rand * cs(end), 1), :); endfor case {"cluster"} subsamp = max (k, ceil (nRows/10)); if (isempty (weights)) idx = randperm (nRows, subsamp); else idx = randsample (nRows, subsamp, false, weights); endif [~, mu] = kmeans (data(idx), k, "start", "sample"); endswitch # Initialize the variance, unless set explicitly # Sigma = var (data) + Regularizer; if (!diagonalCovar) Sigma = diag (Sigma); endif if (!sharedCovar) Sigma = repmat (Sigma, [1, 1, k]); endif endif # Run the algorithm iter = 1; log_likeli = -inf; incr = 1; while (incr > TolFun && iter <= MaxIter) iter = iter + 1; ####################################### # "E step" # Calculate probability of class l given observations for i = 1:k if (sharedCovar) sig = Sigma; else sig = Sigma(:,:,i); endif if (diagonalCovar) sig = diag(sig); endif try p_x_l (:, i) = mvnpdf (data, mu(i, :), sig); catch ME if (strfind (ME.message, "positive definite")) error ("fitgmdist: Covariance is not positive definite. Increase RegularizationValue"); else rethrow (ME) endif end_try_catch endfor # Bayes' rule p_x_l = bsxfun (@times, p_x_l, p); # weight by priors p_l_x = bsxfun (@rdivide, p_x_l, sum (p_x_l, 2)); # Normalize ####################################### # "M step" # Calculate new parameters if (!isempty (weights)) p_l_x = bsxfun (@times, p_l_x, weights(:,1)); endif sum_p_l_x = sum(p_l_x); # row vec of \sum_{data} p(class|data,params) p = sum_p_l_x / raw_samples; # new proportions mu = bsxfun(@rdivide, p_l_x' * data, sum_p_l_x'); # new means if (sharedCovar) sumSigma = zeros (size (Sigma(:,:,1))); # diagonalCovar gives size endif for i = 1:k # Sigma deviation = bsxfun(@minus, data, mu(i,:)); lhs = bsxfun(@times, p_l_x(:,i), deviation); # Calculate covariance # Iterate either over elements of the covariance matrix, since # there should be fewer of those than rows of data. for rw = 1:nCols for cl = rw:nCols sig(rw,cl) = lhs(:,rw)' * deviation(:,cl); endfor endfor sig(lower_half) = sig(upper_half); sig = sig/sum_p_l_x(i) + Regularizer*eye (nCols); if (columns (weights) > 1) # don't give "singleton" clusters low var sig(diag_slice) = max (sig(diag_slice), weights(i,2)); endif if (diagonalCovar) sig = diag(sig)'; endif if (sharedCovar) sumSigma = sumSigma + sig * p(i); # Heuristic. Should it use else # old p? Something else? Sigma(:,:,i) = sig; endif endfor if (sharedCovar) Sigma = sumSigma; endif ####################################### # calculate the new (and relative change in) log-likelihood if (isempty (weights)) new_log_likeli = sum (log (sum (p_x_l, 2))); else new_log_likeli = sum (weights(:,1) .* log (sum (p_x_l, 2))); endif incr = (new_log_likeli - log_likeli)/max(1,abs(new_log_likeli)); if Display == 2 fprintf("iter %d log-likelihood %g\n", iter-1, new_log_likeli); %disp(mu); endif log_likeli = new_log_likeli; endwhile if (log_likeli > best) best = log_likeli; best_params.mu = mu; best_params.Sigma = Sigma; best_params.p = p; endif endfor catch ME try if (1 < MaxIter), end catch error ("fitgmdist: invalid MaxIter"); end_try_catch rethrow (ME) end_try_catch # List components in descending order of proportion, # unless the order was implicitly specified by "start" if (component_order_free) [~, idx] = sort (-best_params.p); best_params.p = best_params.p (idx); best_params.mu = best_params.mu(idx,:); if (!sharedCovar) best_params.Sigma = best_params.Sigma(:,:,idx); endif endif # Calculate number of parameters if (diagonalCovar) params = nCols; else params = nCols * (nCols+1) / 2; endif params = params*size (Sigma, 3) + 2*rows (mu) - 1; extra.NegativeLogLikelihood = -best; extra.AIC = -2*(best - params); extra.BIC = -2*best + params * log (raw_samples); extra.Converged = (incr <= TolFun); extra.NumIterations = iter-1; extra.RegularizationValue = Regularizer; # This works in Octave, but not in Matlab #obj = gmdistribution (best_params.mu, best_params.Sigma, best_params.p', extra); obj = gmdistribution (best_params.mu, best_params.Sigma, best_params.p'); if (Display == 1) fprintf (" %d iterations log-likelihood = %g\n", ... extra.NumIterations, -extra.NegativeLogLikelihood); endif endfunction %!xdemo <50286> %! ## Generate a two-cluster problem %! C1 = randn (100, 2) + 1; %! C2 = randn (100, 2) - 1; %! 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), heights)); %! hold on %! plot (centers (:, 1), centers (:, 2), "kv", "markersize", 10); %! hold off statistics-1.4.1/inst/PaxHeaders.29769/burrrnd.m0000644000000000000000000000006213443447555016315 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/burrrnd.m0000644000175000017500000001203013443447555017020 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} burrrnd (@var{alpha}, @var{c}, @var{k}) ## @deftypefnx {} {} burrrnd (@var{alpha}, @var{c}, @var{k}, @var{r}) ## @deftypefnx {} {} burrrnd (@var{alpha}, @var{c}, @var{k}, @var{r}, @var{c}, @dots{}) ## @deftypefnx {} {} burrrnd (@var{alpha}, @var{c}, @var{k}, [@var{sz}]) ## Return a matrix of random samples from the generalized Pareto distribution ## with scale parameter @var{alpha} and shape parameters @var{c} and @var{k}. ## ## When called with a single size argument, return a square matrix with ## the dimension specified. When called with more than one scalar argument the ## first two arguments are taken as the number of rows and columns and any ## further arguments specify additional matrix dimensions. The size may also ## be specified with a vector of dimensions @var{sz}. ## ## If no size arguments are given then the result matrix is the common size of ## @var{alpha}, @var{c} and @var{k}. ## @end deftypefn ## Author: Dag Lyberg ## Description: Random deviates from the generalized extreme value (GEV) distribution function rnd = burrrnd (alpha, c, k, varargin) if (nargin < 3) print_usage (); endif if (! isscalar (alpha) || ! isscalar (c) || ! isscalar (k)) [retval, alpha, c, k] = common_size (alpha, c, k); if (retval > 0) error ("burrrnd: ALPHA, C and K must be of common size or scalars"); endif endif if (iscomplex (alpha) || iscomplex (c) || iscomplex (k)) error ("burrrnd: ALPHA, C and K must not be complex"); endif if (nargin == 3) sz = size (alpha); elseif (nargin == 4) if (isscalar (varargin{1}) && varargin{1} >= 0) sz = [varargin{1}, varargin{1}]; elseif (isrow (varargin{1}) && all (varargin{1} >= 0)) sz = varargin{1}; else error ("burrrnd: dimension vector must be row vector of non-negative integers"); endif elseif (nargin > 4) if (any (cellfun (@(x) (! isscalar (x) || x < 0), varargin))) error ("burrrnd: dimensions must be non-negative integers"); endif sz = [varargin{:}]; endif if (! isscalar (alpha) && ! isequal (size (c), sz) && ! isequal (size (k), sz)) error ("burrrnd: ALPHA, C and K must be scalar or of size SZ"); endif if (isa (alpha, "single") || isa (c, "single") || isa (k, "single")) cls = "single"; else cls = "double"; endif if (isscalar (alpha) && isscalar (c) && isscalar(k)) if ((0 < alpha) && (alpha < Inf) && (0 < c) && (c < Inf) ... && (0 < k) && (k < Inf)) rnd = rand (sz, cls); rnd(:) = ((1 - rnd(:) / alpha).^(-1 / k) - 1).^(1 / c); else rnd = NaN (sz, cls); endif else rnd = NaN (sz, cls); j = (0 < alpha) && (alpha < Inf) && (0 < c) && (c < Inf) ... && (0 < k) && (k < Inf); rnd(k) = rand(sum(j(:)),1); rnd(k) = ((1 - rnd(j) / alpha(j)).^(-1 ./ k(j)) - 1).^(1 ./ c(j)); endif endfunction %!assert (size (burrrnd (1, 1, 1)), [1 1]) %!assert (size (burrrnd (ones (2,1), 1, 1)), [2, 1]) %!assert (size (burrrnd (ones (2,2), 1, 1)), [2, 2]) %!assert (size (burrrnd (1, ones (2,1), 1)), [2, 1]) %!assert (size (burrrnd (1, ones (2,2), 1)), [2, 2]) %!assert (size (burrrnd (1, 1, ones (2,1))), [2, 1]) %!assert (size (burrrnd (1, 1, ones (2,2))), [2, 2]) %!assert (size (burrrnd (1, 1, 1, 3)), [3, 3]) %!assert (size (burrrnd (1, 1, 1, [4 1])), [4, 1]) %!assert (size (burrrnd (1, 1, 1, 4, 1)), [4, 1]) ## Test class of input preserved %!assert (class (burrrnd (1,1,1)), "double") %!assert (class (burrrnd (single (1),1,1)), "single") %!assert (class (burrrnd (single ([1 1]),1,1)), "single") %!assert (class (burrrnd (1,single (1),1)), "single") %!assert (class (burrrnd (1,single ([1 1]),1)), "single") %!assert (class (burrrnd (1,1,single (1))), "single") %!assert (class (burrrnd (1,1,single ([1 1]))), "single") ## Test input validation %!error burrrnd () %!error burrrnd (1) %!error burrrnd (1,2) %!error burrrnd (ones (3), ones (2), ones (2), 2) %!error burrrnd (ones (2), ones (3), ones (2), 2) %!error burrrnd (ones (2), ones (2), ones (3), 2) %!error burrrnd (i, 2, 2) %!error burrrnd (2, i, 2) %!error burrrnd (2, 2, i) %!error burrrnd (4,2,2, -1) %!error burrrnd (4,2,2, ones (2)) %!error burrrnd (4,2,2, [2 -1 2]) %!error burrrnd (4*ones (2),2,2, 3) %!error burrrnd (4*ones (2),2,2, [3, 2]) %!error burrrnd (4*ones (2),2,2, 3, 2) statistics-1.4.1/inst/PaxHeaders.29769/pcares.m0000644000000000000000000000006213443447555016114 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/pcares.m0000644000175000017500000000530713443447555016630 0ustar00johndjohnd00000000000000## Copyright (C) 2013-2019 Fernando Damian Nieuwveldt ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version 3 ## of the License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{residuals},@var{reconstructed}]}=pcares(@var{X}, @var{NDIM}) ## Calulate residuals from principal component analysis ## ## @itemize @bullet ## @item ## @var{X} : N x P Matrix with N observations and P variables, the variables will be mean centered ## @item ## @var{ndim} : Is a scalar indicating the number of principal components to use and should be <= P ## @end itemize ## ## @subheading References ## ## @enumerate ## @item ## Jolliffe, I. T., Principal Component Analysis, 2nd Edition, Springer, 2002 ## ## @end enumerate ## @end deftypefn ## Author: Fernando Damian Nieuwveldt ## Description: Residuals from Principal Components Analysis function [residuals,reconstructed] = pcares(X,NDIM) if (nargin ~= 2) error('pcares takes two inputs: The data Matrix X and number of principal components NDIM') endif # Mean center data Xcentered = bsxfun(@minus,X,mean(X)); # Apply svd to get the principal component coefficients [U,S,V] = svd(Xcentered); # Use only the first ndim PCA components v = V(:,1:NDIM); if (nargout == 2) # Calculate the residuals residuals = Xcentered - Xcentered * (v*v'); # Reconstructed data using ndim PCA components reconstructed = X - residuals; else # Calculate the residuals residuals = Xcentered - Xcentered * (v*v'); endif endfunction %!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) statistics-1.4.1/inst/PaxHeaders.29769/nakacdf.m0000644000000000000000000000006213443447555016226 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nakacdf.m0000644000175000017500000000631013443447555016735 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} nakacdf (@var{x}, @var{m}, @var{w}) ## For each element of @var{x}, compute the cumulative distribution function ## (CDF) at @var{x} of the Nakagami distribution with shape parameter @var{m} ## and scale parameter @var{w}. ## ## @end deftypefn ## Author: Dag Lyberg ## Description: CDF of the Nakagami distribution function cdf = nakacdf (x, m, w) if (nargin != 3) print_usage (); endif if (! isscalar (m) || ! isscalar (w)) [retval, x, m, w] = common_size (x, m, w); if (retval > 0) error ("nakacdf: X, M and W must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (m) || iscomplex (w)) error ("nakacdf: X, M and W must not be complex"); endif if (isa (x, "single") || isa (m, "single") || isa (w, "single")) inv = zeros (size (x), "single"); else inv = zeros (size (x)); endif k = isnan (x) | ! (m > 0) | ! (w > 0); cdf(k) = NaN; k = (x == Inf) & (0 < m) & (m < Inf) & (0 < w) & (w < Inf); cdf(k) = 1; k = (0 < x) & (x < Inf) & (0 < m) & (m < Inf) & (0 < w) & (w < Inf); if (isscalar(x) && isscalar (m) && isscalar(w)) left = m; right = (m/w) * x^2; cdf(k) = gammainc(right, left); elseif (isscalar (m) && isscalar(w)) left = m * ones(size(x)); right = (m/w) * x.^2; cdf(k) = gammainc(right(k), left(k)); else left = m .* ones(size(x)); right = (m./w) .* x.^2; cdf(k) = gammainc(right(k), left(k)); endif endfunction %!shared x,y %! x = [-1, 0, 1, 2, Inf]; %! y = [0, 0, 0.63212055882855778, 0.98168436111126578, 1]; %!assert (nakacdf (x, ones (1,5), ones (1,5)), y, eps) %!assert (nakacdf (x, 1, 1), y, eps) %!assert (nakacdf (x, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)]) %!assert (nakacdf (x, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)]) %!assert (nakacdf ([x, NaN], 1, 1), [y, NaN], eps) ## Test class of input preserved %!assert (nakacdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps('single')) %!assert (nakacdf ([x, NaN], single (1), 1), single ([y, NaN]), eps('single')) %!assert (nakacdf ([x, NaN], 1, single (1)), single ([y, NaN]), eps('single')) ## Test input validation %!error nakacdf () %!error nakacdf (1) %!error nakacdf (1,2) %!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 (i, 2, 2) %!error nakacdf (2, i, 2) %!error nakacdf (2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/wishpdf.m0000644000000000000000000000006213443447555016303 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/wishpdf.m0000644000175000017500000000542213443447555017015 0ustar00johndjohnd00000000000000## Copyright (C) 2013 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along with Octave; see the file COPYING. If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {} @var{y} = wishpdf (@var{W}, @var{Sigma}, @var{df}, @var{log_y}=false) ## Compute the probability density function of the Wishart distribution ## ## Inputs: A @var{p} x @var{p} matrix @var{W} where to find the PDF. The @var{p} x @var{p} positive definite matrix @var{Sigma} and scalar degrees of freedom parameter @var{df} characterizing the Wishart distribution. (For the density to be finite, need @var{df} > (@var{p} - 1).) ## If the flag @var{log_y} is set, return the log probability density -- this helps avoid underflow when the numerical value of the density is very small ## ## Output: @var{y} is the probability density of Wishart(@var{Sigma}, @var{df}) at @var{W}. ## ## @seealso{wishrnd, iwishpdf} ## @end deftypefn ## Author: Nir Krakauer ## Description: Compute the probability density function of the Wishart distribution function [y] = wishpdf(W, Sigma, df, log_y=false) if (nargin < 3) print_usage (); endif p = size(Sigma, 1); if (df <= (p - 1)) error('df too small, no finite densities exist') endif #calculate the logarithm of G_d(df/2), the multivariate gamma function g = (p * (p-1) / 4) * log(pi); for i = 1:p g = g + log(gamma((df + (1 - i))/2)); #using lngamma_gsl(.) from the gsl package instead of log(gamma(.)) might help avoid underflow/overflow endfor C = chol(Sigma); #use formulas for determinant of positive definite matrix for better efficiency and numerical accuracy logdet_W = 2*sum(log(diag(chol(W)))); logdet_Sigma = 2*sum(log(diag(C))); y = -(df*p)/2 * log(2) - (df/2)*logdet_Sigma - g + ((df - p - 1)/2)*logdet_W - trace(chol2inv(C)*W)/2; if ~log_y y = exp(y); endif endfunction ##test results cross-checked against dwish function in R MCMCpack library %!assert(wishpdf(4, 3, 3.1), 0.07702496, 1E-7); %!assert(wishpdf([2 -0.3;-0.3 4], [1 0.3;0.3 1], 4), 0.004529741, 1E-7); %!assert(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); %% Test input validation %!error wishpdf () %!error wishpdf (1, 2) %!error wishpdf (1, 2, 0) %!error wishpdf (1, 2) statistics-1.4.1/inst/PaxHeaders.29769/gevcdf.m0000644000000000000000000000006213443447555016075 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gevcdf.m0000644000175000017500000000730013443447555016604 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{p} =} gevcdf (@var{x}, @var{k}, @var{sigma}, @var{mu}) ## Compute the cumulative distribution function of the generalized extreme value (GEV) distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} is the support. ## ## @item ## @var{k} is the shape parameter of the GEV distribution. (Also denoted gamma or xi.) ## @item ## @var{sigma} is the scale parameter of the GEV distribution. The elements ## of @var{sigma} must be positive. ## @item ## @var{mu} is the location parameter of the GEV distribution. ## @end itemize ## The inputs must be of common size, or some of them must be scalar. ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{p} is the cumulative distribution of the GEV distribution at each ## element of @var{x} and corresponding parameter values. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = 0:0.5:2.5; ## sigma = 1:6; ## k = 1; ## mu = 0; ## y = gevcdf (x, k, sigma, mu) ## @end group ## ## @group ## y = gevcdf (x, k, 0.5, mu) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Rolf-Dieter Reiss and Michael Thomas. @cite{Statistical Analysis of Extreme Values with Applications to Insurance, Finance, Hydrology and Other Fields}. Chapter 1, pages 16-17, Springer, 2007. ## ## @end enumerate ## @seealso{gevfit, gevinv, gevlike, gevpdf, gevrnd, gevstat} ## @end deftypefn ## Author: Nir Krakauer ## Description: CDF of the generalized extreme value distribution function p = gevcdf (x, k, sigma, mu) # Check arguments if (nargin != 4) print_usage (); endif if (isempty (x) || isempty (k) || isempty (sigma) || isempty (mu) || ~ismatrix (x) || ~ismatrix (k) || ~ismatrix (sigma) || ~ismatrix (mu)) error ("gevcdf: inputs must be a numeric matrices"); endif [retval, x, k, sigma, mu] = common_size (x, k, sigma, mu); if (retval > 0) error ("gevcdf: inputs must be of common size or scalars"); endif z = 1 + k .* (x - mu) ./ sigma; # Calculate pdf p = exp(-(z .^ (-1 ./ k))); p(z <= 0 & x < mu) = 0; p(z <= 0 & x > mu) = 1; inds = (abs (k) < (eps^0.7)); %use a different formula if k is very close to zero if any(inds) z = (mu(inds) - x(inds)) ./ sigma(inds); p(inds) = exp(-exp(z)); endif endfunction %!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 (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 (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 (p, expected_p, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/nakainv.m0000644000000000000000000000006213443447555016266 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nakainv.m0000644000175000017500000000623313443447555017001 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} nakainv (@var{x}, @var{m}, @var{w}) ## For each element of @var{x}, compute the quantile (the inverse of the CDF) ## at @var{x} of the Nakagami distribution with shape parameter @var{m} and ## scale parameter @var{w}. ## ## @end deftypefn ## Author: Dag Lyberg ## Description: Quantile function of the Nakagami distribution function inv = nakainv (x, m, w) if (nargin != 3) print_usage (); endif if (! isscalar (m) || ! isscalar (w)) [retval, x, m, w] = common_size (x, m, w); if (retval > 0) error ("nakainv: X, M and W must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (m) || iscomplex (w)) error ("nakainv: X, M, and W must not be complex"); endif if (isa (x, "single") || isa (m, "single") || isa (w, "single")) inv = zeros (size (x), "single"); else inv = zeros (size (x)); endif k = isnan (x) | ! (0 <= x) | ! (x <= 1) | ! (-Inf < m) | ! (m < Inf) ... | ! (0 < w) | ! (w < Inf); inv(k) = NaN; k = (x == 1) & (-Inf < m) & (m < Inf) & (0 < w) & (w < Inf); inv(k) = Inf; k = (0 < x) & (x < 1) & (0 < m) & (m < Inf) & (0 < w) & (w < Inf); if (isscalar (m) && isscalar(w)) m_gamma = m; w_gamma = w/m; inv(k) = gaminv(x(k), m_gamma, w_gamma); inv(k) = sqrt(inv(k)); else m_gamma = m; w_gamma = w./m; inv(k) = gaminv(x(k), m_gamma(k), w_gamma(k)); inv(k) = sqrt(inv(k)); endif endfunction %!shared x,y %! x = [-Inf, -1, 0, 1/2, 1, 2, Inf]; %! y = [NaN, NaN, 0, 0.83255461115769769, Inf, NaN, NaN]; %!assert (nakainv (x, ones (1,7), ones (1,7)), y, eps) %!assert (nakainv (x, 1, 1), y, eps) %!assert (nakainv (x, [1, 1, 1, NaN, 1, 1, 1], 1), [y(1:3), NaN, y(5:7)], eps) %!assert (nakainv (x, 1, [1, 1, 1, NaN, 1, 1, 1]), [y(1:3), NaN, y(5:7)], eps) %!assert (nakainv ([x, NaN], 1, 1), [y, NaN], eps) ## Test class of input preserved %!assert (nakainv (single ([x, NaN]), 1, 1), single ([y, NaN])) %!assert (nakainv ([x, NaN], single (1), 1), single ([y, NaN])) %!assert (nakainv ([x, NaN], 1, single (1)), single ([y, NaN])) ## Test input validation %!error nakainv () %!error nakainv (1) %!error nakainv (1,2) %!error nakainv (1,2,3,4) %!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 (i, 2, 2) %!error nakainv (2, i, 2) %!error nakainv (2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/sigma_pts.m0000644000000000000000000000006213443447555016625 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/sigma_pts.m0000644000175000017500000000764613443447555017351 0ustar00johndjohnd00000000000000## Copyright (C) 2017 - Juan Pablo Carbajal ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## Author: Juan Pablo Carbajal ## -*- texinfo -*- ## @deftypefn {} {@var{pts} =} sigma_pts (@var{n}) ## @deftypefnx {@var{pts} =} sigma_pts (@var{n}, @var{m}) ## @deftypefnx {@var{pts} =} sigma_pts (@var{n}, @var{m}, @var{K}) ## @deftypefnx {@var{pts} =} sigma_pts (@var{n}, @var{m}, @var{K}, @var{l}) ## Calculates 2*@var{n}+1 sigma points in @var{n} dimensions. ## ## Sigma points are used in the unscented transfrom to estimate ## the result of applying a given nonlinear transformation to a probability ## distribution that is characterized only in terms of a finite set of statistics. ## ## If only the dimension @var{n} is given the resulting points have zero mean ## and identity covariance matrix. ## If the mean @var{m} or the covaraince matrix @var{K} are given, then the resulting points ## will have those statistics. ## The factor @var{l} scaled the points away from the mean. It is useful to tune ## the accuracy of the unscented transfrom. ## ## There is no unique way of computing sigma points, this function implements the ## algorithm described in section 2.6 "The New Filter" pages 40-41 of ## ## Uhlmann, Jeffrey (1995). "Dynamic Map Building and Localization: New Theoretical Foundations". ## Ph.D. thesis. University of Oxford. ## ## @end deftypefn function pts = sigma_pts (n, m = [], K = [], l = 0) if isempty (K) K = eye (n); endif if isempty (m) m = zeros (1, n); endif if (n ~= length (m)) error ("Dimension and size of mean vector don't match.") endif if any(n ~= size (K)) error ("Dimension and size of covariance matrix don't match.") endif if isdefinite (K) <= 0 error ("Covariance matrix should be positive definite.") endif pts = zeros (2 * n + 1, n); pts(1,:) = m; K = sqrtm ((n + l) * K); pts(2:n+1,:) = bsxfun (@plus, m , K); pts(n+2:end,:) = bsxfun (@minus, m , K); endfunction %!demo %! K = [1 0.5; 0.5 1]; # covaraince 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 (mean (p), zeros(1,5), sqrt(eps)); %! assert (cov (p), eye(5), sqrt(eps)); %!test %! m = randn(1, 5); %! p = sigma_pts (5, m); %! assert (mean (p), m, sqrt(eps)); %! assert (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 (mean (p), zeros(1,5), sqrt(eps)); %! assert (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]); statistics-1.4.1/inst/PaxHeaders.29769/ztest.m0000644000000000000000000000006213443447555016010 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/ztest.m0000644000175000017500000001021513443447555016516 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Tony Richardson ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{z}, @var{zcrit}] =} ztest (@var{x}, @var{m}, @var{s}) ## @deftypefnx {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{z}, @var{zcrit}] =} ztest (@var{x}, @var{m}, @var{s}, @var{Name}, @var{Value}) ## Test for mean of a normal sample with known variance. ## ## Perform a Z-test of the null hypothesis @code{mean (@var{x}) == @var{m}} ## for a sample @var{x} from a normal distribution with unknown ## mean and known std deviation @var{s}. Under the null, the test statistic ## @var{z} follows a standard normal distribution. ## ## Name-Value pair arguments can be used to set various options. ## @qcode{"alpha"} can be used to specify the significance level ## of the test (the default value is 0.05). @qcode{"tail"}, can be used ## to select the desired alternative hypotheses. If the value is ## @qcode{"both"} (default) the null is tested against the two-sided ## alternative @code{mean (@var{x}) != @var{m}}. ## If it is @qcode{"right"} the one-sided alternative @code{mean (@var{x}) ## > @var{m}} is considered. Similarly for @qcode{"left"}, the one-sided ## alternative @code{mean (@var{x}) < @var{m}} is considered. ## When argument @var{x} is a matrix, @qcode{"dim"} can be used to selection ## the dimension over which to perform the test. (The default is the ## first non-singleton dimension.) ## ## If @var{h} is 0 the null hypothesis is accepted, if it is 1 the null ## hypothesis is rejected. The p-value of the test is returned in @var{pval}. ## A 100(1-alpha)% confidence interval is returned in @var{ci}. The test statistic ## value is returned in @var{z} and the z critical value in @var{zcrit}. ## ## @end deftypefn ## Author: Tony Richardson function [h, p, ci, zval, zcrit] = ztest(x, m, sigma, varargin) alpha = 0.05; tail = 'both'; % Find the first non-singleton dimension of x dim = min(find(size(x)~=1)); if isempty(dim), dim = 1; end i = 1; while ( i <= length(varargin) ) switch lower(varargin{i}) case 'alpha' i = i + 1; alpha = varargin{i}; case 'tail' i = i + 1; tail = varargin{i}; case 'dim' i = i + 1; dim = varargin{i}; otherwise error('Invalid Name argument.',[]); end i = i + 1; end if ~isa(tail, 'char') error('tail argument to ztest must be a string\n',[]); end % Calculate the test statistic value (zval) n = size(x, dim); x_bar = mean(x, dim); x_bar_std = sigma/sqrt(n); zval = (x_bar - m)./x_bar_std; % Based on the "tail" argument determine the P-value, the critical values, % and the confidence interval. switch lower(tail) case 'both' p = 2*(1 - normcdf(abs(zval))); zcrit = -norminv(alpha/2); ci = [x_bar-zcrit*x_bar_std; x_bar+zcrit*x_bar_std]; case 'left' p = normcdf(zval); zcrit = -norminv(alpha); ci = [-inf*ones(size(x_bar)); x_bar+zcrit*x_bar_std]; case 'right' p = 1 - normcdf(zval); zcrit = -norminv(alpha); ci = [x_bar-zcrit*x_bar_std; inf*ones(size(x_bar))]; otherwise error('Invalid fifth (tail) argument to ztest\n',[]); end % Reshape the ci array to match MATLAB shaping if and(isscalar(x_bar), dim==2) ci = ci(:)'; elseif size(x_bar,2) ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{data}, @var{varnames}, @var{casenames}] =} tblread (@var{filename}) ## @deftypefnx {Function File} {[@var{data}, @var{varnames}, @var{casenames}] =} tblread (@var{filename}, @var{delimeter}) ## Read tabular data from an ascii file. ## ## @var{data} is read from an ascii data file named @var{filename} with ## an optional @var{delimeter}. The delimeter may be any single ## character or ## @itemize ## @item "space" " " (default) ## @item "tab" "\t" ## @item "comma" "," ## @item "semi" ";" ## @item "bar" "|" ## @end itemize ## ## The @var{data} is read starting at cell (2,2) where the ## @var{varnames} form a char matrix from the first row (starting at ## (1,2)) vertically concatenated, and the @var{casenames} form a char ## matrix read from the first column (starting at (2,1)) vertically ## concatenated. ## @seealso{tblwrite, csv2cell, cell2csv} ## @end deftypefn function [data, varnames, casenames] = tblread (f="", d=" ") ## Check arguments if nargin < 1 || nargin > 2 print_usage (); endif if isempty (f) ## FIXME: open a file dialog box in this case when a file dialog box ## becomes available error ("tblread: filename must be given") endif [d err] = tbl_delim (d); if ! isempty (err) error ("tblread: %s", err) endif d = csv2cell (f, d); data = cell2mat (d(2:end, 2:end)); varnames = strvcat (d(1,2:end)); casenames = strvcat (d(2:end,1)); endfunction ## Tests %!shared d, v, c, tblreadspacefile, tblreadtabfile %! d = [1 2;3 4]; %! v = ["a ";"bc"]; %! c = ["de";"f "]; %! tblreadspacefile = file_in_loadpath("test/tblread-space.dat"); %! tblreadtabfile = file_in_loadpath("test/tblread-tab.dat"); %!test %! [dt vt ct] = tblread (tblreadspacefile); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %!test %! [dt vt ct] = tblread (tblreadspacefile, " "); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %!test %! [dt vt ct] = tblread (tblreadspacefile, "space"); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %!test %! [dt vt ct] = tblread (tblreadtabfile, "tab"); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %!test %! [dt vt ct] = tblread (tblreadtabfile, "\t"); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %!test %! [dt vt ct] = tblread (tblreadtabfile, '\t'); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); statistics-1.4.1/inst/PaxHeaders.29769/burrpdf.m0000644000000000000000000000006213443447555016303 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/burrpdf.m0000644000175000017500000000666013443447555017022 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} burrpdf (@var{x}, @var{alpha}, @var{c}, @var{k}) ## For each element of @var{x}, compute the probability density function (PDF) ## at @var{x} of the Burr distribution with scale parameter @var{alpha} and ## shape parameters @var{c} and @var{k}. ## @end deftypefn ## Author: Dag Lyberg ## Description: PDF of the Burr distribution function pdf = burrpdf (x, alpha, c, k) if (nargin != 4) print_usage (); endif if (! isscalar (alpha) || ! isscalar (c) || ! isscalar (k) ) [retval, x, alpha, c, k] = common_size (x, alpha, c, k); if (retval > 0) error ("burrpdf: X, ALPHA, C AND K must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex(alpha) || iscomplex (c) || iscomplex (k)) error ("burrpdf: X, ALPHA, C AND K must not be complex"); endif if (isa (x, "single") || isa (alpha, "single") ... || isa (c, "single") || isa (k, "single")) pdf = zeros (size (x), "single"); else pdf = zeros (size (x)); endif j = isnan (x) | ! (alpha > 0) | ! (c > 0) | ! (k > 0); pdf(j) = NaN; j = (x > 0) & (0 < alpha) & (alpha < Inf) & (0 < c) & (c < Inf) ... & (0 < k) & (k < Inf); if (isscalar (alpha) && isscalar (c) && isscalar(k)) pdf(j) = (c * k / alpha) .* (x(j) / alpha).^(c-1) ./ ... (1 + (x(j) / alpha).^c).^(k + 1); else pdf(j) = (c(j) .* k(j) ./ alpha(j) ).* x(j).^(c(j)-1) ./ ... (1 + (x(j) ./ alpha(j) ).^c(j) ).^(k(j) + 1); endif endfunction %!shared x,y %! x = [-1, 0, 1, 2, Inf]; %! y = [0, 0, 1/4, 1/9, 0]; %!assert (burrpdf (x, ones(1,5), ones (1,5), ones (1,5)), y) %!assert (burrpdf (x, 1, 1, 1), y) %!assert (burrpdf (x, [1, 1, NaN, 1, 1], 1, 1), [y(1:2), NaN, y(4:5)]) %!assert (burrpdf (x, 1, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)]) %!assert (burrpdf (x, 1, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)]) %!assert (burrpdf ([x, NaN], 1, 1, 1), [y, NaN]) ## Test class of input preserved %!assert (burrpdf (single ([x, NaN]), 1, 1, 1), single ([y, NaN])) %!assert (burrpdf ([x, NaN], single (1), 1, 1), single ([y, NaN])) %!assert (burrpdf ([x, NaN], 1, single (1), 1), single ([y, NaN])) %!assert (burrpdf ([x, NaN], 1, 1, single (1)), single ([y, NaN])) ## Test input validation %!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 (i, 2, 2, 2) %!error burrpdf (2, i, 2, 2) %!error burrpdf (2, 2, i, 2) %!error burrpdf (2, 2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/ttest.m0000644000000000000000000000006213443447555016002 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/ttest.m0000644000175000017500000001311113443447555016506 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Tony Richardson ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} ttest (@var{x}) ## @deftypefnx {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} ttest (@var{x}, @var{m}) ## @deftypefnx {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} ttest (@var{x}, @var{y}) ## @deftypefnx {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} ttest (@var{x}, @var{m}, @var{Name}, @var{Value}) ## @deftypefnx {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} ttest (@var{x}, @var{y}, @var{Name}, @var{Value}) ## Test for mean of a normal sample with unknown variance. ## ## Perform a T-test of the null hypothesis @code{mean (@var{x}) == ## @var{m}} for a sample @var{x} from a normal distribution with unknown ## mean and unknown std deviation. Under the null, the test statistic ## @var{t} has a Student's t distribution. The default value of ## @var{m} is 0. ## ## If the second argument @var{y} is a vector, a paired-t test of the ## hypothesis @code{mean (@var{x}) = mean (@var{y})} is performed. ## ## Name-Value pair arguments can be used to set various options. ## @qcode{"alpha"} can be used to specify the significance level ## of the test (the default value is 0.05). @qcode{"tail"}, can be used ## to select the desired alternative hypotheses. If the value is ## @qcode{"both"} (default) the null is tested against the two-sided ## alternative @code{mean (@var{x}) != @var{m}}. ## If it is @qcode{"right"} the one-sided alternative @code{mean (@var{x}) ## > @var{m}} is considered. Similarly for @qcode{"left"}, the one-sided ## alternative @code{mean (@var{x}) < @var{m}} is considered. ## When argument @var{x} is a matrix, @qcode{"dim"} can be used to selection ## the dimension over which to perform the test. (The default is the ## first non-singleton dimension). ## ## If @var{h} is 0 the null hypothesis is accepted, if it is 1 the null ## hypothesis is rejected. The p-value of the test is returned in @var{pval}. ## A 100(1-alpha)% confidence interval is returned in @var{ci}. @var{stats} ## is a structure containing the value of the test statistic (@var{tstat}), ## the degrees of freedom (@var{df}) and the sample standard deviation ## (@var{sd}). ## ## @end deftypefn ## Author: Tony Richardson function [h, p, ci, stats] = ttest(x, my, varargin) % Set default arguments my_default = 0; alpha = 0.05; tail = 'both'; % Find the first non-singleton dimension of x dim = min(find(size(x)~=1)); if isempty(dim), dim = 1; end if (nargin == 1) my = my_default; end i = 1; while ( i <= length(varargin) ) switch lower(varargin{i}) case 'alpha' i = i + 1; alpha = varargin{i}; case 'tail' i = i + 1; tail = varargin{i}; case 'dim' i = i + 1; dim = varargin{i}; otherwise error('Invalid Name argument.',[]); end i = i + 1; end if ~isa(tail, 'char') error('tail argument to ttest must be a string\n',[]); end if any(and(~isscalar(my),size(x)~=size(my))) error('Arrays in paired test must be the same size.'); end % Set default values if arguments are present but empty if isempty(my) my = my_default; end % This adjustment allows everything else to remain the % same for both the one-sample t test and paired tests. x = x - my; % Calculate the test statistic value (tval) n = size(x, dim); x_bar = mean(x, dim); stats.tstat = 0; stats.df = n-1; stats.sd = std(x, 0, dim); x_bar_std = stats.sd/sqrt(n); tval = (x_bar)./x_bar_std; stats.tstat = tval; % Based on the "tail" argument determine the P-value, the critical values, % and the confidence interval. switch lower(tail) case 'both' p = 2*(1 - tcdf(abs(tval),n-1)); tcrit = -tinv(alpha/2,n-1); ci = [x_bar-tcrit*x_bar_std; x_bar+tcrit*x_bar_std] + my; case 'left' p = tcdf(tval,n-1); tcrit = -tinv(alpha,n-1); ci = [-inf*ones(size(x_bar)); my+x_bar+tcrit*x_bar_std]; case 'right' p = 1 - tcdf(tval,n-1); tcrit = -tinv(alpha,n-1); ci = [my+x_bar-tcrit*x_bar_std; inf*ones(size(x_bar))]; otherwise error('Invalid tail argument to ttest\n',[]); end % Reshape the ci array to match MATLAB shaping if and(isscalar(x_bar), dim==2) ci = ci(:)'; elseif size(x_bar,2). ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} cdf (@var{name}, @var{X}, @dots{}) ## Return cumulative density function of @var{name} function for value ## @var{x}. ## This is a wrapper around various @var{name}cdf and @var{name}_cdf ## functions. See the individual functions help to learn the signification of ## the arguments after @var{x}. Supported functions and corresponding number of ## additional arguments are: ## ## @multitable @columnfractions 0.02 0.3 0.45 0.2 ## @headitem @tab function @tab alternative @tab args ## @item @tab "beta" @tab "beta" @tab 2 ## @item @tab "bino" @tab "binomial" @tab 2 ## @item @tab "cauchy" @tab @tab 2 ## @item @tab "chi2" @tab "chisquare" @tab 1 ## @item @tab "discrete" @tab @tab 2 ## @item @tab "exp" @tab "exponential" @tab 1 ## @item @tab "f" @tab @tab 2 ## @item @tab "gam" @tab "gamma" @tab 2 ## @item @tab "geo" @tab "geometric" @tab 1 ## @item @tab "gev" @tab "generalized extreme value" @tab 3 ## @item @tab "hyge" @tab "hypergeometric" @tab 3 ## @item @tab "kolmogorov_smirnov" @tab @tab 1 ## @item @tab "laplace" @tab @tab 0 ## @item @tab "logistic" @tab @tab 0 ## @item @tab "logn" @tab "lognormal" @tab 2 ## @item @tab "norm" @tab "normal" @tab 2 ## @item @tab "poiss" @tab "poisson" @tab 1 ## @item @tab "rayl" @tab "rayleigh" @tab 1 ## @item @tab "t" @tab @tab 1 ## @item @tab "unif" @tab "uniform" @tab 2 ## @item @tab "wbl" @tab "weibull" @tab 2 ## @end multitable ## ## @seealso{betacdf, binocdf, cauchy_cdf, chi2cdf, discrete_cdf, ## expcdf, fcdf, gamcdf, geocdf, gevcdf, hygecdf, ## kolmogorov_smirnov_cdf, laplace_cdf, logistic_cdf, logncdf, ## normcdf, poisscdf, raylcdf, tcdf, unifcdf, wblcdf} ## @end deftypefn function [retval] = cdf (varargin) ## implemented functions persistent allcdf = {{"beta", "beta"}, @betacdf, 2, ... {"bino", "binomial"}, @binocdf, 2, ... {"cauchy"}, @cauchy_cdf, 2, ... {"chi2", "chisquare"}, @chi2cdf, 1, ... {"discrete"}, @discrete_cdf, 2, ... {"exp", "exponential"}, @expcdf, 1, ... {"f"}, @fcdf, 2, ... {"gam", "gamma"}, @gamcdf, 2, ... {"geo", "geometric"}, @geocdf, 1, ... {"gev", "generalized extreme value"}, @gevcdf, 3, ... {"hyge", "hypergeometric"}, @hygecdf, 3, ... {"kolmogorov_smirnov"}, @kolmogorov_smirnov_cdf, 1, ... {"laplace"}, @laplace_cdf, 0, ... {"logistic"}, @logistic_cdf, 0, ... # ML has 2 args here {"logn", "lognormal"}, @logncdf, 2, ... {"norm", "normal"}, @normcdf, 2, ... {"poiss", "poisson"}, @poisscdf, 1, ... {"rayl", "rayleigh"}, @raylcdf, 1, ... {"t"}, @tcdf, 1, ... {"unif", "uniform"}, @unifcdf, 2, ... {"wbl", "weibull"}, @wblcdf, 2}; if (numel (varargin) < 2 || ! ischar (varargin{1})) print_usage (); endif name = varargin{1}; x = varargin{2}; varargin(1:2) = []; nargs = numel (varargin); cdfnames = allcdf(1:3:end); cdfhdl = allcdf(2:3:end); cdfargs = allcdf(3:3:end); idx = cellfun (@(x) any (strcmpi (name, x)), cdfnames); if (any (idx)) if (nargs == cdfargs{idx}) retval = feval (cdfhdl{idx}, x, varargin{:}); else error ("cdf: %s requires %d arguments", name, cdfargs{idx}) endif else error ("cdf: %s not implemented", name); endif endfunction %!test %! assert(cdf ('norm', 1, 0, 1), normcdf (1, 0, 1))statistics-1.4.1/inst/PaxHeaders.29769/burrcdf.m0000644000000000000000000000006213443447555016266 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/burrcdf.m0000644000175000017500000000661113443447555017001 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} burrcdf (@var{x}, @var{c}, @var{k}) ## For each element of @var{x}, compute the cumulative distribution function ## (CDF) at @var{x} of the Burr distribution with scale parameter @var{alpha} ## and shape parameters @var{c} and @var{k}. ## @end deftypefn ## Author: Dag Lyberg ## Description: CDF of the Burr distribution function cdf = burrcdf (x, alpha, c, k) if (nargin != 4) print_usage (); endif if (! isscalar (alpha) || ! isscalar (c) || ! isscalar (k) ) [retval, x, alpha, c, k] = common_size (x, alpha, c, k); if (retval > 0) error ("burrcdf: X, ALPHA, C AND K must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex(alpha) || iscomplex (c) || iscomplex (k)) error ("burrcdf: X, ALPHA, C AND K must not be complex"); endif if (isa (x, "single") || isa (alpha, "single") || isa (c, "single") ... || isa (k, "single")) cdf = zeros (size (x), "single"); else cdf = zeros (size (x)); endif j = isnan (x) | ! (alpha > 0) | ! (c > 0) | ! (k > 0); cdf(j) = NaN; j = (x > 0) & (0 < alpha) & (alpha < Inf) & (0 < c) & (c < Inf) ... & (0 < k) & (k < Inf); if (isscalar (alpha) && isscalar(c) && isscalar(k)) cdf(j) = 1 - (1 + (x(j) / alpha).^c).^(-k); else cdf(j) = 1 - (1 + (x(j) ./ alpha(j)).^c(j)).^(-k(j)); endif endfunction %!shared x,y %! x = [-1, 0, 1, 2, Inf]; %! y = [0, 0, 1/2, 2/3, 1]; %!assert (burrcdf (x, ones(1,5), ones (1,5), ones (1,5)), y, eps) %!assert (burrcdf (x, 1, 1, 1), y, eps) %!assert (burrcdf (x, [1, 1, NaN, 1, 1], 1, 1), [y(1:2), NaN, y(4:5)], eps) %!assert (burrcdf (x, 1, [1, 1, NaN, 1, 1], 1), [y(1:2), NaN, y(4:5)], eps) %!assert (burrcdf (x, 1, 1, [1, 1, NaN, 1, 1]), [y(1:2), NaN, y(4:5)], eps) %!assert (burrcdf ([x, NaN], 1, 1, 1), [y, NaN], eps) ## Test class of input preserved %!assert (burrcdf (single ([x, NaN]), 1, 1, 1), single ([y, NaN]), eps('single')) %!assert (burrcdf ([x, NaN], single (1), 1, 1), single ([y, NaN]), eps('single')) %!assert (burrcdf ([x, NaN], 1, single (1), 1), single ([y, NaN]), eps('single')) %!assert (burrcdf ([x, NaN], 1, 1, single (1)), single ([y, NaN]), eps('single')) ## Test input validation %!error burrcdf () %!error burrcdf (1) %!error burrcdf (1,2) %!error burrcdf (1,2,3) %!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 (i, 2, 2, 2) %!error burrcdf (2, i, 2, 2) %!error burrcdf (2, 2, i, 2) %!error burrcdf (2, 2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/lognstat.m0000644000000000000000000000006213443447555016472 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/lognstat.m0000644000175000017500000000662613443447555017213 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} lognstat (@var{mu}, @var{sigma}) ## Compute mean and variance of the lognormal distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{mu} is the first parameter of the lognormal distribution ## ## @item ## @var{sigma} is the second parameter of the lognormal distribution. ## @var{sigma} must be positive or zero ## @end itemize ## @var{mu} and @var{sigma} must be of common size or one of them must be ## scalar ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the lognormal distribution ## ## @item ## @var{v} is the variance of the lognormal distribution ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## mu = 0:0.2:1; ## sigma = 0.2:0.2:1.2; ## [m, v] = lognstat (mu, sigma) ## @end group ## ## @group ## [m, v] = lognstat (0, sigma) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the lognormal distribution function [m, v] = lognstat (mu, sigma) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (mu) && ! ismatrix (mu)) error ("lognstat: mu must be a numeric matrix"); endif if (! isempty (sigma) && ! ismatrix (sigma)) error ("lognstat: sigma must be a numeric matrix"); endif if (! isscalar (mu) || ! isscalar (sigma)) [retval, mu, sigma] = common_size (mu, sigma); if (retval > 0) error ("lognstat: mu and sigma must be of common size or scalar"); endif endif # Calculate moments m = exp (mu + (sigma .^ 2) ./ 2); v = (exp (sigma .^ 2) - 1) .* exp (2 .* mu + sigma .^ 2); # Continue argument check k = find (! (sigma >= 0) | ! (sigma < Inf)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!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 (m, expected_m, 0.001); %! assert (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 (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/hygestat.m0000644000000000000000000000006213443447555016467 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/hygestat.m0000644000175000017500000000746113443447555017206 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{mn}, @var{v}] =} hygestat (@var{t}, @var{m}, @var{n}) ## Compute mean and variance of the hypergeometric distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{t} is the total size of the population of the hypergeometric ## distribution. The elements of @var{t} must be positive natural numbers ## ## @item ## @var{m} is the number of marked items of the hypergeometric distribution. ## The elements of @var{m} must be natural numbers ## ## @item ## @var{n} is the size of the drawn sample of the hypergeometric ## distribution. The elements of @var{n} must be positive natural numbers ## @end itemize ## @var{t}, @var{m}, and @var{n} must be of common size or scalar ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{mn} is the mean of the hypergeometric distribution ## ## @item ## @var{v} is the variance of the hypergeometric distribution ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## t = 4:9; ## m = 0:5; ## n = 1:6; ## [mn, v] = hygestat (t, m, n) ## @end group ## ## @group ## [mn, v] = hygestat (t, m, 2) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the hypergeometric distribution function [mn, v] = hygestat (t, m, n) # Check arguments if (nargin != 3) print_usage (); endif if (! isempty (t) && ! ismatrix (t)) error ("hygestat: t must be a numeric matrix"); endif if (! isempty (m) && ! ismatrix (m)) error ("hygestat: m must be a numeric matrix"); endif if (! isempty (n) && ! ismatrix (n)) error ("hygestat: n must be a numeric matrix"); endif if (! isscalar (t) || ! isscalar (m) || ! isscalar (n)) [retval, t, m, n] = common_size (t, m, n); if (retval > 0) error ("hygestat: t, m and n must be of common size or scalar"); endif endif # Calculate moments mn = (n .* m) ./ t; v = (n .* (m ./ t) .* (1 - m ./ t) .* (t - n)) ./ (t - 1); # Continue argument check k = find (! (t >= 0) | ! (m >= 0) | ! (n > 0) | ! (t == round (t)) | ! (m == round (m)) | ! (n == round (n)) | ! (m <= t) | ! (n <= t)); if (any (k)) mn(k) = NaN; v(k) = NaN; endif endfunction %!test %! t = 4:9; %! m = 0:5; %! n = 1:6; %! [mn, v] = hygestat (t, m, 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 (mn, expected_mn, 0.001); %! assert (v, expected_v, 0.001); %!test %! t = 4:9; %! m = 0:5; %! [mn, v] = hygestat (t, m, 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 (mn, expected_mn, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/ttest2.m0000644000000000000000000000006213443447555016064 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/ttest2.m0000644000175000017500000001257213443447555016602 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Tony Richardson ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} ttest2 (@var{x}, @var{y}) ## @deftypefnx {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} ttest2 (@var{x}, @var{y}, @var{Name}, @var{Value}) ## Test for mean of a normal sample with known variance. ## ## Perform a T-test of the null hypothesis @code{mean (@var{x}) == ## @var{m}} for a sample @var{x} from a normal distribution with unknown ## mean and unknown std deviation. Under the null, the test statistic ## @var{t} has a Student's t distribution. ## ## If the second argument @var{y} is a vector, a paired-t test of the ## hypothesis @code{mean (@var{x}) = mean (@var{y})} is performed. ## ## The argument @qcode{"alpha"} can be used to specify the significance level ## of the test (the default value is 0.05). The string ## argument @qcode{"tail"}, can be used to select the desired alternative ## hypotheses. If @qcode{"alt"} is @qcode{"both"} (default) the null is ## tested against the two-sided alternative @code{mean (@var{x}) != @var{m}}. ## If @qcode{"alt"} is @qcode{"right"} the one-sided ## alternative @code{mean (@var{x}) > @var{m}} is considered. ## Similarly for @qcode{"left"}, the one-sided alternative @code{mean ## (@var{x}) < @var{m}} is considered. When @qcode{"vartype"} is @qcode{"equal"} ## the variances are assumed to be equal (this is the default). When ## @qcode{"vartype"} is @qcode{"unequal"} the variances are not assumed equal. ## When argument @var{x} is a matrix the @qcode{"dim"} argument can be ## used to selection the dimension over which to perform the test. ## (The default is the first non-singleton dimension.) ## ## If @var{h} is 0 the null hypothesis is accepted, if it is 1 the null ## hypothesis is rejected. The p-value of the test is returned in @var{pval}. ## A 100(1-alpha)% confidence interval is returned in @var{ci}. @var{stats} ## is a structure containing the value of the test statistic (@var{tstat}), ## the degrees of freedom (@var{df}) and the sample standard deviation ## (@var{sd}). ## ## @end deftypefn ## Author: Tony Richardson function [h, p, ci, stats] = ttest2(x, y, varargin) alpha = 0.05; tail = 'both'; vartype = 'equal'; % Find the first non-singleton dimension of x dim = min(find(size(x)~=1)); if isempty(dim), dim = 1; end i = 1; while ( i <= length(varargin) ) switch lower(varargin{i}) case 'alpha' i = i + 1; alpha = varargin{i}; case 'tail' i = i + 1; tail = varargin{i}; case 'vartype' i = i + 1; vartype = varargin{i}; case 'dim' i = i + 1; dim = varargin{i}; otherwise error('Invalid Name argument.',[]); end i = i + 1; end if ~isa(tail, 'char') error('Tail argument to ttest2 must be a string\n',[]); end m = size(x, dim); n = size(y, dim); x_bar = mean(x,dim)-mean(y,dim); s1_var = var(x, 0, dim); s2_var = var(y, 0, dim); switch lower(vartype) case 'equal' stats.tstat = 0; stats.df = (m + n - 2)*ones(size(x_bar)); sp_var = ((m-1)*s1_var + (n-1)*s2_var)./stats.df; stats.sd = sqrt(sp_var); x_bar_std = sqrt(sp_var*(1/m+1/n)); case 'unequal' stats.tstat = 0; se1 = sqrt(s1_var/m); se2 = sqrt(s2_var/n); sp_var = s1_var/m + s2_var/n; stats.df = ((se1.^2+se2.^2).^2 ./ (se1.^4/(m-1) + se2.^4/(n-1))); stats.sd = [sqrt(s1_var); sqrt(s2_var)]; x_bar_std = sqrt(sp_var); otherwise error('Invalid fifth (vartype) argument to ttest2\n',[]); end stats.tstat = x_bar./x_bar_std; % Based on the "tail" argument determine the P-value, the critical values, % and the confidence interval. switch lower(tail) case 'both' p = 2*(1 - tcdf(abs(stats.tstat),stats.df)); tcrit = -tinv(alpha/2,stats.df); %ci = [x_bar-tcrit*stats.sd; x_bar+tcrit*stats.sd]; ci = [x_bar-tcrit.*x_bar_std; x_bar+tcrit.*x_bar_std]; case 'left' p = tcdf(stats.tstat,stats.df); tcrit = -tinv(alpha,stats.df); ci = [-inf*ones(size(x_bar)); x_bar+tcrit.*x_bar_std]; case 'right' p = 1 - tcdf(stats.tstat,stats.df); tcrit = -tinv(alpha,stats.df); ci = [x_bar-tcrit.*x_bar_std; inf*ones(size(x_bar))]; otherwise error('Invalid fourth (tail) argument to ttest2\n',[]); end % Reshape the ci array to match MATLAB shaping if and(isscalar(x_bar), dim==2) ci = ci(:)'; stats.sd = stats.sd(:)'; elseif size(x_bar,2). ## -*- texinfo -*- ## @deftypefn {} {} gpinv (@var{x}, @var{shape}, @var{scale}, @var{location}) ## For each element of @var{x}, compute the quantile (the inverse of the CDF) ## at @var{x} of the generalized Pareto distribution with parameters ## @var{location}, @var{scale}, and @var{shape}. ## @end deftypefn ## Author: Dag Lyberg ## Description: Quantile function of the generalized Pareto distribution function inv = gpinv (x, shape, scale, location) if (nargin != 4) print_usage (); endif if (! isscalar (location) || ! isscalar (scale) || ! isscalar (shape)) [retval, x, location, scale, shape] = ... common_size (x, location, scale, shape); if (retval > 0) error ("gpinv: X, LOCATION, SCALE and SHAPE must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (location) ... || iscomplex (scale) || iscomplex (shape)) error ("gpinv: X, LOCATION, SCALE and SHAPE must not be complex"); endif if (isa (x, "single") || isa (location, "single") ... || isa (scale, "single") || isa (shape, "single")) inv = zeros (size (x), "single"); else inv = zeros (size (x)); endif k = isnan (x) | ! (0 <= x) | ! (x <= 1) ... | ! (-Inf < location) | ! (location < Inf) ... | ! (scale > 0) | ! (scale < Inf) ... | ! (-Inf < shape) | ! (shape < Inf); inv(k) = NaN; k = (0 <= x) & (x <= 1) & (-Inf < location) & (location < Inf) ... & (scale > 0) & (scale < Inf) & (-Inf < shape) & (shape < Inf); if (isscalar (location) && isscalar (scale) && isscalar (shape)) if (shape == 0) inv(k) = -log(1 - x(k)); inv(k) = scale * inv(k) + location; elseif (shape > 0) inv(k) = (1 - x(k)).^(-shape) - 1; inv(k) = (scale / shape) * inv(k) + location; elseif (shape < 0) inv(k) = (1 - x(k)).^(-shape) - 1; inv(k) = (scale / shape) * inv(k) + location; end else j = k & (shape == 0); if (any (j)) inv(j) = -log (1 - x(j)); inv(j) = scale(j) .* inv(j) + location(j); endif j = k & (shape > 0); if (any (j)) inv(j) = (1 - x(j)).^(-shape(j)) - 1; inv(j) = (scale(j) ./ shape(j)) .* inv(j) + location(j); endif j = k & (shape < 0); if (any (j)) inv(j) = (1 - x(j)).^(-shape(j)) - 1; inv(j) = (scale(j) ./ shape(j)) .* inv(j) + location(j); endif endif endfunction %!shared x,y1,y2,y3 %! x = [-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 (gpinv (x, zeros (1,5), ones (1,5), zeros (1,5)), y1) %!assert (gpinv (x, 0, 1, zeros (1,5)), y1) %!assert (gpinv (x, 0, ones (1,5), 0), y1) %!assert (gpinv (x, zeros (1,5), 1, 0), y1) %!assert (gpinv (x, 0, 1, 0), y1) %!assert (gpinv (x, 0, 1, [0, 0, NaN, 0, 0]), [y1(1:2), NaN, y1(4:5)]) %!assert (gpinv (x, 0, [1, 1, NaN, 1, 1], 0), [y1(1:2), NaN, y1(4:5)]) %!assert (gpinv (x, [0, 0, NaN, 0, 0], 1, 0), [y1(1:2), NaN, y1(4:5)]) %!assert (gpinv ([x(1:2), NaN, x(4:5)], 0, 1, 0), [y1(1:2), NaN, y1(4:5)]) %!assert (gpinv (x, ones (1,5), ones (1,5), zeros (1,5)), y2) %!assert (gpinv (x, 1, 1, zeros (1,5)), y2) %!assert (gpinv (x, 1, ones (1,5), 0), y2) %!assert (gpinv (x, ones (1,5), 1, 0), y2) %!assert (gpinv (x, 1, 1, 0), y2) %!assert (gpinv (x, 1, 1, [0, 0, NaN, 0, 0]), [y2(1:2), NaN, y2(4:5)]) %!assert (gpinv (x, 1, [1, 1, NaN, 1, 1], 0), [y2(1:2), NaN, y2(4:5)]) %!assert (gpinv (x, [1, 1, NaN, 1, 1], 1, 0), [y2(1:2), NaN, y2(4:5)]) %!assert (gpinv ([x(1:2), NaN, x(4:5)], 1, 1, 0), [y2(1:2), NaN, y2(4:5)]) %!assert (gpinv (x, -ones (1,5), ones (1,5), zeros (1,5)), y3) %!assert (gpinv (x, -1, 1, zeros (1,5)), y3) %!assert (gpinv (x, -1, ones (1,5), 0), y3) %!assert (gpinv (x, -ones (1,5), 1, 0), y3) %!assert (gpinv (x, -1, 1, 0), y3) %!assert (gpinv (x, -1, 1, [0, 0, NaN, 0, 0]), [y3(1:2), NaN, y3(4:5)]) %!assert (gpinv (x, -1, [1, 1, NaN, 1, 1], 0), [y3(1:2), NaN, y3(4:5)]) %!assert (gpinv (x, -[1, 1, NaN, 1, 1], 1, 0), [y3(1:2), NaN, y3(4:5)]) %!assert (gpinv ([x(1:2), NaN, x(4:5)], -1, 1, 0), [y3(1:2), NaN, y3(4:5)]) ## Test class of input preserved %!assert (gpinv (single ([x, NaN]), 0, 1, 0), single ([y1, NaN])) %!assert (gpinv ([x, NaN], 0, 1, single (0)), single ([y1, NaN])) %!assert (gpinv ([x, NaN], 0, single (1), 0), single ([y1, NaN])) %!assert (gpinv ([x, NaN], single (0), 1, 0), single ([y1, NaN])) %!assert (gpinv (single ([x, NaN]), 1, 1, 0), single ([y2, NaN])) %!assert (gpinv ([x, NaN], 1, 1, single (0)), single ([y2, NaN])) %!assert (gpinv ([x, NaN], 1, single (1), 0), single ([y2, NaN])) %!assert (gpinv ([x, NaN], single (1), 1, 0), single ([y2, NaN])) %!assert (gpinv (single ([x, NaN]), -1, 1, 0), single ([y3, NaN])) %!assert (gpinv ([x, NaN], -1, 1, single (0)), single ([y3, NaN])) %!assert (gpinv ([x, NaN], -1, single (1), 0), single ([y3, NaN])) %!assert (gpinv ([x, NaN], single (-1), 1, 0), single ([y3, NaN])) ## Test input validation %!error gpinv () %!error gpinv (1) %!error gpinv (1,2) %!error gpinv (1,2,3) %!error gpinv (1,2,3,4,5) %!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 (i, 2, 2, 2) %!error gpinv (2, i, 2, 2) %!error gpinv (2, 2, i, 2) %!error gpinv (2, 2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/harmmean.m0000644000000000000000000000006213443447555016427 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/harmmean.m0000644000175000017500000000215113443447555017135 0ustar00johndjohnd00000000000000## Copyright (C) 2001 Paul Kienzle ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} harmmean (@var{x}) ## @deftypefnx{Function File} harmmean (@var{x}, @var{dim}) ## Compute the harmonic mean. ## ## This function does the same as @code{mean (x, "h")}. ## ## @seealso{mean} ## @end deftypefn function a = harmmean(x, dim) if (nargin == 1) a = mean(x, "h"); elseif (nargin == 2) a = mean(x, "h", dim); else print_usage; endif endfunction statistics-1.4.1/inst/PaxHeaders.29769/gevinv.m0000644000000000000000000000006213443447555016135 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gevinv.m0000644000175000017500000000621213443447555016645 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{X} =} gevinv (@var{P}, @var{k}, @var{sigma}, @var{mu}) ## Compute a desired quantile (inverse CDF) of the generalized extreme value (GEV) distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{P} is the desired quantile of the GEV distribution. (Between 0 and 1.) ## @item ## @var{k} is the shape parameter of the GEV distribution. (Also denoted gamma or xi.) ## @item ## @var{sigma} is the scale parameter of the GEV distribution. The elements ## of @var{sigma} must be positive. ## @item ## @var{mu} is the location parameter of the GEV distribution. ## @end itemize ## The inputs must be of common size, or some of them must be scalar. ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{X} is the value corresponding to each quantile of the GEV distribution ## @end itemize ## @subheading References ## ## @enumerate ## @item ## Rolf-Dieter Reiss and Michael Thomas. @cite{Statistical Analysis of Extreme Values with Applications to Insurance, Finance, Hydrology and Other Fields}. Chapter 1, pages 16-17, Springer, 2007. ## @item ## J. R. M. Hosking (2012). @cite{L-moments}. R package, version 1.6. URL: http://CRAN.R-project.org/package=lmom. ## ## @end enumerate ## @seealso{gevcdf, gevfit, gevlike, gevpdf, gevrnd, gevstat} ## @end deftypefn ## Author: Nir Krakauer ## Description: Inverse CDF of the generalized extreme value distribution function [X] = gevinv (P, k = 0, sigma = 1, mu = 0) [retval, P, k, sigma, mu] = common_size (P, k, sigma, mu); if (retval > 0) error ("gevinv: inputs must be of common size or scalars"); endif X = P; llP = log(-log(P)); kllP = k .* llP; ii = (abs(kllP) < 1E-4); #use the Taylor series expansion of the exponential to avoid roundoff error or dividing by zero when k is small X(ii) = mu(ii) - sigma(ii) .* llP(ii) .* (1 - kllP(ii) .* (1 - kllP(ii))); X(~ii) = mu(~ii) + (sigma(~ii) ./ k(~ii)) .* (exp(-kllP(~ii)) - 1); endfunction %!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 (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 (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 (c, p, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/hmmviterbi.m0000644000000000000000000000006213443447555017005 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/hmmviterbi.m0000644000175000017500000002205113443447555017514 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{vpath} =} hmmviterbi (@var{sequence}, @var{transprob}, @var{outprob}) ## @deftypefnx {Function File} {} hmmviterbi (@dots{}, 'symbols', @var{symbols}) ## @deftypefnx {Function File} {} hmmviterbi (@dots{}, 'statenames', @var{statenames}) ## Use the Viterbi algorithm to find the Viterbi path of a hidden Markov ## model given a sequence of outputs. The model assumes that the generation ## starts in state @code{1} at step @code{0} but does not include step ## @code{0} in the generated states and sequence. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{sequence} is the vector of length @var{len} of given outputs. The ## outputs must be integers ranging from @code{1} to ## @code{columns (outprob)}. ## ## @item ## @var{transprob} is the matrix of transition probabilities of the states. ## @code{transprob(i, j)} is the probability of a transition to state ## @code{j} given state @code{i}. ## ## @item ## @var{outprob} is the matrix of output probabilities. ## @code{outprob(i, j)} is the probability of generating output @code{j} ## given state @code{i}. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{vpath} is the vector of the same length as @var{sequence} of the ## estimated hidden states. The states are integers ranging from @code{1} to ## @code{columns (transprob)}. ## @end itemize ## ## If @code{'symbols'} is specified, then @var{sequence} is expected to be a ## sequence of the elements of @var{symbols} instead of integers ranging ## from @code{1} to @code{columns (outprob)}. @var{symbols} can be a cell array. ## ## If @code{'statenames'} is specified, then the elements of ## @var{statenames} are used for the states in @var{vpath} instead of ## integers ranging from @code{1} to @code{columns (transprob)}. ## @var{statenames} can be a cell array. ## ## @subheading Examples ## ## @example ## @group ## 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 (25, transprob, outprob) ## vpath = hmmviterbi (sequence, transprob, outprob) ## @end group ## ## @group ## symbols = @{'A', 'B', 'C'@}; ## statenames = @{'One', 'Two'@}; ## [sequence, states] = hmmgenerate (25, transprob, outprob, ## 'symbols', symbols, 'statenames', statenames) ## vpath = hmmviterbi (sequence, transprob, outprob, ## 'symbols', symbols, 'statenames', statenames) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Lawrence R. Rabiner. A Tutorial on Hidden Markov Models and Selected ## Applications in Speech Recognition. @cite{Proceedings of the IEEE}, ## 77(2), pages 257-286, February 1989. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Viterbi path of a hidden Markov model function vpath = hmmviterbi (sequence, transprob, outprob, varargin) # Check arguments if (nargin < 3 || mod (length (varargin), 2) != 0) print_usage (); endif if (! ismatrix (transprob)) error ("hmmviterbi: transprob must be a non-empty numeric matrix"); endif if (! ismatrix (outprob)) error ("hmmviterbi: outprob must be a non-empty numeric matrix"); endif len = length (sequence); # nstate is the number of states of the hidden Markov model nstate = rows (transprob); # noutput is the number of different outputs that the hidden Markov model # can generate noutput = columns (outprob); # Check whether transprob and outprob are feasible for a hidden Markov model if (columns (transprob) != nstate) error ("hmmviterbi: transprob must be a square matrix"); endif if (rows (outprob) != nstate) error ("hmmviterbi: outprob must have the same number of rows as transprob"); endif # Flag for symbols usesym = false; # Flag for statenames usesn = false; # Process varargin for i = 1:2:length (varargin) # There must be an identifier: 'symbols' or 'statenames' if (! ischar (varargin{i})) print_usage (); endif # Upper case is also fine lowerarg = lower (varargin{i}); if (strcmp (lowerarg, 'symbols')) if (length (varargin{i + 1}) != noutput) error ("hmmviterbi: number of symbols does not match number of possible outputs"); endif usesym = true; # Use the following argument as symbols symbols = varargin{i + 1}; # The same for statenames elseif (strcmp (lowerarg, 'statenames')) if (length (varargin{i + 1}) != nstate) error ("hmmviterbi: number of statenames does not match number of states"); endif usesn = true; # Use the following argument as statenames statenames = varargin{i + 1}; else error ("hmmviterbi: expected 'symbols' or 'statenames' but found '%s'", varargin{i}); endif endfor # Transform sequence from symbols to integers if necessary if (usesym) # sequenceint is used to build the transformed sequence sequenceint = zeros (1, len); for i = 1:noutput # Search for symbols(i) in the sequence, isequal will have 1 at # corresponding indices; i is the right integer for that symbol isequal = ismember (sequence, symbols(i)); # We do not want to change sequenceint if the symbol appears a second # time in symbols if (any ((sequenceint == 0) & (isequal == 1))) isequal *= i; sequenceint += isequal; endif endfor if (! all (sequenceint)) index = max ((sequenceint == 0) .* (1:len)); error (["hmmviterbi: sequence(" int2str (index) ") not in symbols"]); endif sequence = sequenceint; else if (! isvector (sequence) && ! isempty (sequence)) error ("hmmviterbi: sequence must be a vector"); endif if (! all (ismember (sequence, 1:noutput))) index = max ((ismember (sequence, 1:noutput) == 0) .* (1:len)); error (["hmmviterbi: sequence(" int2str (index) ") out of range"]); endif endif # Each row in transprob and outprob should contain log probabilities # => scale so that the sum is 1 and convert to log space # - for transprob s = sum (transprob, 2); s(s == 0) = 1; transprob = log (transprob ./ (s * ones (1, columns (transprob)))); # - for outprob s = sum (outprob, 2); s(s == 0) = 1; outprob = log (outprob ./ (s * ones (1, columns (outprob)))); # Store the path starting from i in spath(i, :) spath = ones (nstate, len + 1); # Set the first state for each path spath(:, 1) = (1:nstate)'; # Store the probability of path i in spathprob(i) spathprob = transprob(1, :); # Find the most likely paths for the given output sequence for i = 1:len # Calculate the new probabilities of the continuation with each state nextpathprob = ((spathprob' + outprob(:, sequence(i))) * ones (1, nstate)) + transprob; # Find the paths with the highest probabilities [spathprob, mindex] = max (nextpathprob); # Update spath and spathprob with the new paths spath = spath(mindex, :); spath(:, i + 1) = (1:nstate)'; endfor # Set vpath to the most likely path # We do not want the last state because we do not have an output for it [m, mindex] = max (spathprob); vpath = spath(mindex, 1:len); # Transform vpath into statenames if requested if (usesn) vpath = reshape (statenames(vpath), 1, len); endif endfunction %!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 (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 (vpath, expected); statistics-1.4.1/inst/PaxHeaders.29769/nakarnd.m0000644000000000000000000000006213443447555016255 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nakarnd.m0000644000175000017500000001055113443447555016766 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} nakarnd (@var{m}, @var{w}) ## @deftypefnx {} {} nakarnd (@var{m}, @var{w}, @var{r}) ## @deftypefnx {} {} nakarnd (@var{m}, @var{w}, @var{r}, @var{c}, @dots{}) ## @deftypefnx {} {} nakarnd (@var{m}, @var{w}, [@var{sz}]) ## Return a matrix of random samples from the Nakagami distribution with ## shape parameter @var{m} and scale @var{w}. ## ## When called with a single size argument, return a square matrix with ## the dimension specified. When called with more than one scalar argument the ## first two arguments are taken as the number of rows and columns and any ## further arguments specify additional matrix dimensions. The size may also ## be specified with a vector of dimensions @var{sz}. ## ## If no size arguments are given then the result matrix is the common size of ## @var{m} and @var{w}. ## @end deftypefn ## Author: Dag Lyberg ## Description: Random deviates from the Nakagami distribution function rnd = nakarnd (m, w, varargin) if (nargin < 2) print_usage (); endif if (! isscalar (m) || ! isscalar (w)) [retval, m, w] = common_size (m, w); if (retval > 0) error ("nakarnd: M and W must be of common size or scalars"); endif endif if (iscomplex (m) || iscomplex (w)) error ("nakarnd: M and W must not be complex"); endif if (nargin == 2) sz = size (m); elseif (nargin == 3) if (isscalar (varargin{1}) && varargin{1} >= 0) sz = [varargin{1}, varargin{1}]; elseif (isrow (varargin{1}) && all (varargin{1} >= 0)) sz = varargin{1}; else error ("nakarnd: dimension vector must be row vector of non-negative integers"); endif elseif (nargin > 3) if (any (cellfun (@(x) (! isscalar (x) || x < 0), varargin))) error ("nakarnd: dimensions must be non-negative integers"); endif sz = [varargin{:}]; endif if (! isscalar (m) && ! isequal (size (w), sz)) error ("nakagrnd: M and W must be scalar or of size SZ"); endif if (isa (m, "single") || isa (w, "single")) cls = "single"; else cls = "double"; endif if (isscalar (m) && isscalar (w)) if ((0 < m) && (m < Inf) && (0 < w) && (w < Inf)) m_gamma = m; w_gamma = w/m; rnd = gamrnd(m_gamma, w_gamma, sz); rnd = sqrt(rnd); else rnd = NaN (sz, cls); endif else rnd = NaN (sz, cls); k = (0 < m) & (m < Inf) & (0 < w) & (w < Inf); m_gamma = m; w_gamma = w./m; rnd(k) = gamrnd(m_gamma(k), w_gamma(k)); rnd(k) = sqrt(rnd(k)); endif endfunction %!assert (size (nakarnd (1,1)), [1, 1]) %!assert (size (nakarnd (ones (2,1), 1)), [2, 1]) %!assert (size (nakarnd (ones (2,2), 1)), [2, 2]) %!assert (size (nakarnd (1, ones (2,1))), [2, 1]) %!assert (size (nakarnd (1, ones (2,2))), [2, 2]) %!assert (size (nakarnd (1,1, 3)), [3, 3]) %!assert (size (nakarnd (1,1, [4 1])), [4, 1]) %!assert (size (nakarnd (1,1, 4, 1)), [4, 1]) ## Test class of input preserved %!assert (class (nakarnd (1,1)), "double") %!assert (class (nakarnd (single (1),1)), "single") %!assert (class (nakarnd (single ([1 1]),1)), "single") %!assert (class (nakarnd (1,single (1))), "single") %!assert (class (nakarnd (1,single ([1 1]))), "single") ## Test input validation %!error nakarnd () %!error nakarnd (1) %!error nakarnd (zeros (3), ones (2)) %!error nakarnd (zeros (2), ones (3)) %!error nakarnd (i, 2) %!error nakarnd (1, i) %!error nakarnd (1,2, -1) %!error nakarnd (1,2, ones (2)) %!error nakarnd (1, 2, [2 -1 2]) %!error nakarnd (1,2, 1, ones (2)) %!error nakarnd (1,2, 1, -1) %!error nakarnd (ones (2,2), 2, 3) %!error nakarnd (ones (2,2), 2, [3, 2]) %!error nakarnd (ones (2,2), 2, 2, 3) statistics-1.4.1/inst/PaxHeaders.29769/randsample.m0000644000000000000000000000006213443447555016765 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/randsample.m0000644000175000017500000001046013443447555017475 0ustar00johndjohnd00000000000000## Copyright (C) 2014 - Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## Author: Nir Krakauer ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} randsample (@var{v}, @var{k}, @var{replacement}=false [, @var{w}]) ## Elements sampled from a vector. ## ## Returns @var{k} random elements from a vector @var{v} with @var{n} elements, sampled without or with @var{replacement}. ## ## If @var{v} is a scalar, samples from 1:@var{v}. ## ## If a weight vector @var{w} of the same size as @var{v} is specified, the probablility of each element being sampled is proportional to @var{w}. Unlike Matlab's function of the same name, this can be done for sampling with or without replacement. ## ## Randomization is performed using rand(). ## ## @seealso{randperm} ## @end deftypefn function y = randsample(v,k,replacement=false,w=[]) if (isscalar (v) && isreal (v)) n = v; vector_v = false; elseif (isvector (v)) n = numel (v); vector_v = true; else error ('Octave:invalid-input-arg', 'randsample: The input v must be a vector or positive integer.'); endif if k < 0 || ( k > n && !replacement ) error ('Octave:invalid-input-arg', 'randsample: The input k must be a non-negative integer. Sampling without replacement needs k <= n.'); endif if (all (length (w) != [0, n])) error ('Octave:invalid-input-arg', 'randsample: the size w (%d) must match the first argument (%d)', length(w), n); endif if (replacement) # sample with replacement if (isempty (w)) # all elements are equally likely to be sampled y = round (n * rand(1, k) + 0.5); else y = weighted_replacement (k, w); endif else # sample without replacement if (isempty (w)) # all elements are equally likely to be sampled y = randperm (n, k); else # use "accept-reject"-like sampling y = weighted_replacement (k, w); while (1) [yy, idx] = sort (y); # Note: sort keeps order of equal elements. Idup = [false, (diff (yy)==0)]; if !any (Idup) break else Idup(idx) = Idup; # find duplicates in original vector w(y) = 0; # don't permit resampling # remove duplicates, then sample again y = [y(~Idup), (weighted_replacement (sum (Idup), w))]; endif endwhile endif endif if vector_v y = v(y); endif endfunction function y = weighted_replacement (k, w) w = w / sum(w); w = [0 cumsum(w(:))']; # distribute k uniform random deviates based on the given weighting y = arrayfun (@(x) find (w <= x, 1, "last"), rand (1, k)); endfunction %!test %! n = 20; %! k = 5; %! x = randsample(n, k); %! assert (size(x), [1 k]); %! x = randsample(n, k, true); %! assert (size(x), [1 k]); %! x = randsample(n, k, false); %! assert (size(x), [1 k]); %! x = randsample(n, k, true, ones(n, 1)); %! assert (size(x), [1 k]); %! x = randsample(1:n, k); %! assert (size(x), [1 k]); %! x = randsample(1:n, k, true); %! assert (size(x), [1 k]); %! x = randsample(1:n, k, false); %! assert (size(x), [1 k]); %! x = randsample(1:n, k, true, ones(n, 1)); %! assert (size(x), [1 k]); %! x = randsample((1:n)', k); %! assert (size(x), [k 1]); %! x = randsample((1:n)', k, true); %! assert (size(x), [k 1]); %! x = randsample((1:n)', k, false); %! assert (size(x), [k 1]); %! x = randsample((1:n)', k, true, ones(n, 1)); %! assert (size(x), [k 1]); %! n = 10; %! k = 100; %! x = randsample(n, k, true, 1:n); %! assert (size(x), [1 k]); %! x = randsample((1:n)', k, true); %! assert (size(x), [k 1]); %! x = randsample(k, k, false, 1:k); %! assert (size(x), [1 k]); statistics-1.4.1/inst/PaxHeaders.29769/copulapdf.m0000644000000000000000000000006213443447555016614 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/copulapdf.m0000644000175000017500000001372513443447555017333 0ustar00johndjohnd00000000000000## Copyright (C) 2008 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{p} =} copulapdf (@var{family}, @var{x}, @var{theta}) ## Compute the probability density function of a copula family. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{family} is the copula family name. Currently, @var{family} can ## be @code{'Clayton'} for the Clayton family, @code{'Gumbel'} for the ## Gumbel-Hougaard family, @code{'Frank'} for the Frank family, or ## @code{'AMH'} for the Ali-Mikhail-Haq family. ## ## @item ## @var{x} is the support where each row corresponds to an observation. ## ## @item ## @var{theta} is the parameter of the copula. The elements of ## @var{theta} must be greater than or equal to @code{-1} for the ## Clayton family, greater than or equal to @code{1} for the ## Gumbel-Hougaard family, arbitrary for the Frank family, and greater ## than or equal to @code{-1} and lower than @code{1} for the ## Ali-Mikhail-Haq family. Moreover, @var{theta} must be non-negative ## for dimensions greater than @code{2}. @var{theta} must be a column ## vector with the same number of rows as @var{x} or be scalar. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{p} is the probability density of the copula at each row of ## @var{x} and corresponding parameter @var{theta}. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = [0.2:0.2:0.6; 0.2:0.2:0.6]; ## theta = [1; 2]; ## p = copulapdf ("Clayton", x, theta) ## @end group ## ## @group ## p = copulapdf ("Gumbel", x, 2) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Roger B. Nelsen. @cite{An Introduction to Copulas}. Springer, ## New York, second edition, 2006. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: PDF of a copula family function p = copulapdf (family, x, theta) # Check arguments if (nargin != 3) print_usage (); endif if (! ischar (family)) error ("copulapdf: family must be one of 'Clayton', 'Gumbel', 'Frank', and 'AMH'"); endif if (! isempty (x) && ! ismatrix (x)) error ("copulapdf: x must be a numeric matrix"); endif [n, d] = size (x); if (! isvector (theta) || (! isscalar (theta) && size (theta, 1) != n)) error ("copulapdf: theta must be a column vector with the same number of rows as x or be scalar"); endif if (n == 0) # Input is empty p = zeros (0, 1); else if (n > 1 && isscalar (theta)) theta = repmat (theta, n, 1); endif # Truncate input to unit hypercube x(x < 0) = 0; x(x > 1) = 1; # Compute the cumulative distribution function according to family lowerarg = lower (family); if (strcmp (lowerarg, "clayton")) # The Clayton family log_cdf = -log (max (sum (x .^ (repmat (-theta, 1, d)), 2) - d + 1, 0)) ./ theta; p = prod (repmat (theta, 1, d) .* repmat (0:(d - 1), n, 1) + 1, 2) .* exp ((1 + theta .* d) .* log_cdf - (theta + 1) .* sum (log (x), 2)); # Product copula at columns where theta == 0 k = find (theta == 0); if (any (k)) p(k) = 1; endif # Check theta if (d > 2) k = find (! (theta >= 0) | ! (theta < inf)); else k = find (! (theta >= -1) | ! (theta < inf)); endif elseif (strcmp (lowerarg, "gumbel")) # The Gumbel-Hougaard family g = sum ((-log (x)) .^ repmat (theta, 1, d), 2); c = exp (-g .^ (1 ./ theta)); p = ((prod (-log (x), 2)) .^ (theta - 1)) ./ prod (x, 2) .* c .* (g .^ (2 ./ theta - 2) + (theta - 1) .* g .^ (1 ./ theta - 2)); # Check theta k = find (! (theta >= 1) | ! (theta < inf)); elseif (strcmp (lowerarg, "frank")) # The Frank family if (d != 2) error ("copulapdf: Frank copula PDF implemented as bivariate only"); endif p = (theta .* exp (theta .* (1 + sum (x, 2))) .* (exp (theta) - 1))./ (exp (theta) - exp (theta + theta .* x(:, 1)) + exp (theta .* sum (x, 2)) - exp (theta + theta .* x(:, 2))) .^ 2; # Product copula at columns where theta == 0 k = find (theta == 0); if (any (k)) p(k) = 1; endif # Check theta k = find (! (theta > -inf) | ! (theta < inf)); elseif (strcmp (lowerarg, "amh")) # The Ali-Mikhail-Haq family if (d != 2) error ("copulapdf: Ali-Mikhail-Haq copula PDF implemented as bivariate only"); endif z = theta .* prod (x - 1, 2) - 1; p = (theta .* (1 - sum (x, 2) - prod (x, 2) - z) - 1) ./ (z .^ 3); # Check theta k = find (! (theta >= -1) | ! (theta < 1)); else error ("copulapdf: unknown copula family '%s'", family); endif if (any (k)) p(k) = NaN; endif endif endfunction %!test %! x = [0.2:0.2:0.6; 0.2:0.2:0.6]; %! theta = [1; 2]; %! p = copulapdf ("Clayton", x, theta); %! expected_p = [0.9872; 0.7295]; %! assert (p, expected_p, 0.001); %!test %! x = [0.2:0.2:0.6; 0.2:0.2:0.6]; %! p = copulapdf ("Gumbel", x, 2); %! expected_p = [0.9468; 0.9468]; %! assert (p, expected_p, 0.001); %!test %! x = [0.2, 0.6; 0.2, 0.6]; %! theta = [1; 2]; %! p = copulapdf ("Frank", x, theta); %! expected_p = [0.9378; 0.8678]; %! assert (p, expected_p, 0.001); %!test %! x = [0.2, 0.6; 0.2, 0.6]; %! theta = [0.3; 0.7]; %! p = copulapdf ("AMH", x, theta); %! expected_p = [0.9540; 0.8577]; %! assert (p, expected_p, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/tabulate.m0000644000000000000000000000006213443447555016440 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/tabulate.m0000644000175000017500000000770113443447555017154 0ustar00johndjohnd00000000000000## Copyright (C) 2003 Alberto Terruzzi ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{table} =} tabulate (@var{data}, @var{edges}) ## ## Compute a frequency table. ## ## For vector data, the function counts the number of ## values in data that fall between the elements in the edges vector ## (which must contain monotonically non-decreasing values). @var{table} is a ## matrix. ## The first column of @var{table} is the number of bin, the second ## is the number of instances in each class (absolute frequency). The ## third column contains the percentage of each value (relative ## frequency) and the fourth column contains the cumulative frequency. ## ## If @var{edges} is missed the width of each class is unitary, if @var{edges} ## is a scalar then represent the number of classes, or you can define the ## width of each bin. ## @var{table}(@var{k}, 2) will count the value @var{data} (@var{i}) if ## @var{edges} (@var{k}) <= @var{data} (@var{i}) < @var{edges} (@var{k}+1). ## The last bin will count the value of @var{data} (@var{i}) if ## @var{edges}(@var{k}) <= @var{data} (@var{i}) <= @var{edges} (@var{k}+1). ## Values outside the values in @var{edges} are not counted. Use -inf and inf ## in @var{edges} to include all values. ## Tabulate with no output arguments returns a formatted table in the ## command window. ## ## Example ## ## @example ## sphere_radius = [1:0.05:2.5]; ## tabulate (sphere_radius) ## @end example ## ## Tabulate returns 2 bins, the first contains the sphere with radius ## between 1 and 2 mm excluded, and the second one contains the sphere with ## radius between 2 and 3 mm. ## ## @example ## tabulate (sphere_radius, 10) ## @end example ## ## Tabulate returns ten bins. ## ## @example ## tabulate (sphere_radius, [1, 1.5, 2, 2.5]) ## @end example ## ## Tabulate returns three bins, the first contains the sphere with radius ## between 1 and 1.5 mm excluded, the second one contains the sphere with ## radius between 1.5 and 2 mm excluded, and the third contains the sphere with ## radius between 2 and 2.5 mm. ## ## @example ## bar (table (:, 1), table (:, 2)) ## @end example ## ## draw histogram. ## ## @seealso{bar, pareto} ## @end deftypefn ## Author: Alberto Terruzzi ## Version: 1.0 ## Created: 13 February 2003 function table = tabulate (varargin) if nargin < 1 || nargin > 2 print_usage; endif data = varargin{1}; if isvector (data) != 1 error ("data must be a vector."); endif n = length(data); m = min(data); M = max(data); if nargin == 1 edges = 1:1:max(data)+1; else edges = varargin{2}; end if isscalar(edges) h=(M-m)/edges; edges = [m:h:M]; end # number of classes bins=length(edges)-1; # initialize freqency table freqtable = zeros(bins,4); for k=1:1:bins; if k != bins freqtable(k,2)=length(find (data >= edges(k) & data < edges(k+1))); else freqtable(k,2)=length(find (data >= edges(k) & data <= edges(k+1))); end if k == 1 freqtable (k,4) = freqtable(k,2); else freqtable(k,4) = freqtable(k-1,4) + freqtable(k,2); end end freqtable(:,1) = edges(1:end-1)(:); freqtable(:,3) = 100*freqtable(:,2)/n; if nargout == 0 disp(" bin Fa Fr% Fc"); printf("%8g %5d %6.2f%% %5d\n",freqtable'); else table = freqtable; end endfunction statistics-1.4.1/inst/PaxHeaders.29769/mahal.m0000644000000000000000000000006213443447555015721 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/mahal.m0000644000175000017500000000525613443447555016440 0ustar00johndjohnd00000000000000## Copyright (C) 2015 Lachlan Andrew ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## This program, is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {} mahal (@var{y}, @var{x}) ## Mahalanobis' D-square distance. ## ## Return the Mahalanobis' D-square distance of the points in ## @var{y} from the distribution implied by points @var{x}. ## ## Specifically, it uses a Cholesky decomposition to set ## ## @example ## answer(i) = (@var{y}(i,:) - mean (@var{x})) * inv (A) * (@var{y}(i,:)-mean (@var{x}))' ## @end example ## ## where A is the covariance of @var{x}. ## ## The data @var{x} and @var{y} must have the same number of components ## (columns), but may have a different number of observations (rows). ## ## @end deftypefn ## Author: Lachlan Andrew ## Created: September 2015 ## Based on function mahalanobis by Friedrich Leisch function retval = mahal (y, x) if (nargin != 2) print_usage (); endif if (! (isnumeric (x) || islogical (x)) || ! (isnumeric (y) || islogical (y))) error ("mahal: X and Y must be numeric matrices or vectors"); endif if (! ismatrix (x) || ! ismatrix (y)) error ("mahal: X and Y must be 2-D matrices or vectors"); endif [xr, xc] = size (x); [yr, yc] = size (y); if (xc != yc) error ("mahal: X and Y must have the same number of columns"); endif if (isinteger (x)) x = double (x); endif xm = mean (x, 1); ## Center data by subtracting mean of x x = bsxfun (@minus, x, xm); y = bsxfun (@minus, y, xm); w = (x' * x) / (xr - 1); retval = sumsq (y / chol (w), 2); endfunction ## Test input validation %!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 (mahal (X, X), [1.5; 1.5; 1.5; 1.5], 10*eps) %! assert (mahal (X, X+1), [7.5; 7.5; 1.5; 13.5], 10*eps) %!assert (mahal ([true; true], [false; true]), [0.5; 0.5], eps) statistics-1.4.1/inst/PaxHeaders.29769/gprnd.m0000644000000000000000000000006213443447555015751 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gprnd.m0000644000175000017500000001471013443447555016463 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} gprnd (@var{shape}, @var{scale}, @var{location}) ## @deftypefnx {} {} gprnd (@var{shape}, @var{scale}, @var{location}, @var{r}) ## @deftypefnx {} {} gprnd (@var{shape}, @var{scale}, @var{location}, @var{r}, @var{c}, @dots{}) ## @deftypefnx {} {} gprnd (@var{shape}, @var{scale}, @var{location}, [@var{sz}]) ## Return a matrix of random samples from the generalized Pareto distribution ## with parameters @var{location}, @var{scale} and @var{shape}. ## ## When called with a single size argument, return a square matrix with ## the dimension specified. When called with more than one scalar argument the ## first two arguments are taken as the number of rows and columns and any ## further arguments specify additional matrix dimensions. The size may also ## be specified with a vector of dimensions @var{sz}. ## ## If no size arguments are given then the result matrix is the common size of ## @var{location}, @var{scale} and @var{shape}. ## @end deftypefn ## Author: Dag Lyberg ## Description: Random deviates from the generalized Pareto distribution function rnd = gprnd (shape, scale, location, varargin) if (nargin < 3) print_usage (); endif if (! isscalar (location) || ! isscalar (scale) || ! isscalar (shape)) [retval, location, scale, shape] = common_size (location, scale, shape); if (retval > 0) error ("gpgrnd: LOCATION, SCALE and SHAPE must be of common size or scalars"); endif endif if (iscomplex (location) || iscomplex (scale) || iscomplex (shape)) error ("gprnd: LOCATION, SCALE and SHAPE must not be complex"); endif if (nargin == 3) sz = size (location); elseif (nargin == 4) if (isscalar (varargin{1}) && varargin{1} >= 0) sz = [varargin{1}, varargin{1}]; elseif (isrow (varargin{1}) && all (varargin{1} >= 0)) sz = varargin{1}; else error ("gprnd: dimension vector must be row vector of non-negative integers"); endif elseif (nargin > 4) if (any (cellfun (@(x) (! isscalar (x) || x < 0), varargin))) error ("gprnd: dimensions must be non-negative integers"); endif sz = [varargin{:}]; endif if (! isscalar (location) && ! isequal (size (location), sz)) error ("gprnd: LOCATION, SCALE and SHAPE must be scalar or of size SZ"); endif if (isa (location, "single") || isa (scale, "single") || isa (shape, "single")) cls = "single"; else cls = "double"; endif if (isscalar (location) && isscalar (scale) && isscalar (shape)) if ((-Inf < location) && (location < Inf) && (0 < scale) && (scale < Inf) ... && (-Inf < shape) && (shape < Inf)) rnd = rand(sz,cls); if (shape == 0) rnd = -log(1 - rnd); rnd = scale * rnd + location; elseif ((shape < 0) || (shape > 0)) rnd = (1 - rnd).^(-shape) - 1; rnd = (scale / shape) * rnd + location; end else rnd = NaN (sz, cls); endif else rnd = NaN (sz, cls); k = (-Inf < location) & (location < Inf) & (scale > 0) ... & (-Inf < shape) & (shape < Inf); rnd(k(:)) = rand (1, sum(k(:)), cls); if (any (shape == 0)) rnd(k) = -log(1 - rnd(k)); rnd(k) = scale(k) .* rnd(k) + location(k); elseif (any (shape < 0 | shape > 0)) rnd(k) = (1 - rnd(k)).^(-shape(k)) - 1; rnd(k) = (scale(k) ./ shape(k)) .* rnd(k) + location(k); end endif endfunction %!assert (size (gprnd (0,1,0)), [1, 1]) %!assert (size (gprnd (0, 1, zeros (2,1))), [2, 1]) %!assert (size (gprnd (0, 1, zeros (2,2))), [2, 2]) %!assert (size (gprnd (0, ones (2,1), 0)), [2, 1]) %!assert (size (gprnd (0, ones (2,2), 0)), [2, 2]) %!assert (size (gprnd (zeros (2,1), 1, 0)), [2, 1]) %!assert (size (gprnd (zeros (2,2), 1, 0)), [2, 2]) %!assert (size (gprnd (0, 1, 0, 3)), [3, 3]) %!assert (size (gprnd (0, 1, 0, [4 1])), [4, 1]) %!assert (size (gprnd (0, 1, 0, 4, 1)), [4, 1]) %!assert (size (gprnd (1,1,0)), [1, 1]) %!assert (size (gprnd (1, 1, zeros (2,1))), [2, 1]) %!assert (size (gprnd (1, 1, zeros (2,2))), [2, 2]) %!assert (size (gprnd (1, ones (2,1), 0)), [2, 1]) %!assert (size (gprnd (1, ones (2,2), 0)), [2, 2]) %!assert (size (gprnd (ones (2,1), 1, 0)), [2, 1]) %!assert (size (gprnd (ones (2,2), 1, 0)), [2, 2]) %!assert (size (gprnd (1, 1, 0, 3)), [3, 3]) %!assert (size (gprnd (1, 1, 0, [4 1])), [4, 1]) %!assert (size (gprnd (1, 1, 0, 4, 1)), [4, 1]) %!assert (size (gprnd (-1, 1, 0)), [1, 1]) %!assert (size (gprnd (-1, 1, zeros (2,1))), [2, 1]) %!assert (size (gprnd (1, -1, zeros (2,2))), [2, 2]) %!assert (size (gprnd (-1, ones (2,1), 0)), [2, 1]) %!assert (size (gprnd (-1, ones (2,2), 0)), [2, 2]) %!assert (size (gprnd (-ones (2,1), 1, 0)), [2, 1]) %!assert (size (gprnd (-ones (2,2), 1, 0)), [2, 2]) %!assert (size (gprnd (-1, 1, 0, 3)), [3, 3]) %!assert (size (gprnd (-1, 1, 0, [4 1])), [4, 1]) %!assert (size (gprnd (-1, 1, 0, 4, 1)), [4, 1]) ## Test class of input preserved %!assert (class (gprnd (0,1,0)), "double") %!assert (class (gprnd (0, 1, single (0))), "single") %!assert (class (gprnd (0, 1, single ([0 0]))), "single") %!assert (class (gprnd (0,single (1),0)), "single") %!assert (class (gprnd (0,single ([1 1]),0)), "single") %!assert (class (gprnd (single (0), 1, 0)), "single") %!assert (class (gprnd (single ([0 0]), 1, 0)), "single") ## Test input validation %!error gprnd () %!error gprnd (1) %!error gprnd (1,2) %!error gprnd (zeros (2), ones (2), zeros (3)) %!error gprnd (zeros (2), ones (3), zeros (2)) %!error gprnd (zeros (3), ones (2), zeros (2)) %!error gprnd (i, 1, 0) %!error gprnd (0, i, 0) %!error gprnd (0, 1, i) %!error gprnd (0,1,0, -1) %!error gprnd (0,1,0, ones (2)) %!error gprnd (0,1,0, [2 -1 2]) %!error gprnd (0,1, zeros (2), 3) %!error gprnd (0,1, zeros (2), [3, 2]) %!error gprnd (0,1, zeros (2), 3, 2) statistics-1.4.1/inst/PaxHeaders.29769/iwishrnd.m0000644000000000000000000000006213443447555016466 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/iwishrnd.m0000644000175000017500000000543713443447555017206 0ustar00johndjohnd00000000000000## Copyright (C) 2013 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along with Octave; see the file COPYING. If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {} [@var{W}[, @var{DI}]] = iwishrnd (@var{Psi}, @var{df}[, @var{DI}][, @var{n}=1]) ## Return a random matrix sampled from the inverse Wishart distribution with given parameters ## ## Inputs: the @var{p} x @var{p} positive definite matrix @var{Tau} and scalar degrees of freedom parameter @var{df} (and optionally the transposed Cholesky factor @var{DI} of @var{Sigma} = @code{inv(Tau)}). ## @var{df} can be non-integer as long as @var{df} > @var{d} ## ## Output: a random @var{p} x @var{p} matrix @var{W} from the inverse Wishart(@var{Tau}, @var{df}) distribution. (@code{inv(W)} is from the Wishart(@code{inv(Tau)}, @var{df}) distribution.) If @var{n} > 1, then @var{W} is @var{p} x @var{p} x @var{n} and holds @var{n} such random matrices. (Optionally, the transposed Cholesky factor @var{DI} of @var{Sigma} is also returned.) ## ## Averaged across many samples, the mean of @var{W} should approach @var{Tau} / (@var{df} - @var{p} - 1). ## ## Reference: Yu-Cheng Ku and Peter Bloomfield (2010), Generating Random Wishart Matrices with Fractional Degrees of Freedom in OX, http://www.gwu.edu/~forcpgm/YuChengKu-030510final-WishartYu-ChengKu.pdf ## ## @seealso{wishrnd, iwishpdf} ## @end deftypefn ## Author: Nir Krakauer ## Description: Random matrices from the inverse Wishart distribution function [W, DI] = iwishrnd(Tau, df, DI, n = 1) if (nargin < 2) print_usage (); endif if nargin < 3 || isempty(DI) try D = chol(inv(Tau)); catch error('Cholesky decomposition failed; Tau probably not positive definite') end_try_catch DI = D'; else D = DI'; endif w = wishrnd([], df, D, n); if n > 1 p = size(D, 1); W = nan(p, p, n); endif for i = 1:n W(:, :, i) = inv(w(:, :, i)); endfor endfunction %!assert(size (iwishrnd (1,2,1)), [1, 1]); %!assert(size (iwishrnd ([],2,1)), [1, 1]); %!assert(size (iwishrnd ([3 1; 1 3], 2.00001, [], 1)), [2, 2]); %!assert(size (iwishrnd (eye(2), 2, [], 3)), [2, 2, 3]); %% Test input validation %!error iwishrnd () %!error iwishrnd (1) %!error iwishrnd ([-3 1; 1 3],1) %!error iwishrnd ([1; 1],1) statistics-1.4.1/inst/PaxHeaders.29769/raylpdf.m0000644000000000000000000000006213443447555016300 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/raylpdf.m0000644000175000017500000000620313443447555017010 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} raylpdf (@var{x}, @var{sigma}) ## Compute the probability density function of the Rayleigh distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} is the support. The elements of @var{x} must be non-negative. ## ## @item ## @var{sigma} is the parameter of the Rayleigh distribution. The elements ## of @var{sigma} must be positive. ## @end itemize ## @var{x} and @var{sigma} must be of common size or one of them must be ## scalar. ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{y} is the probability density of the Rayleigh distribution at each ## element of @var{x} and corresponding parameter @var{sigma}. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = 0:0.5:2.5; ## sigma = 1:6; ## y = raylpdf (x, sigma) ## @end group ## ## @group ## y = raylpdf (x, 0.5) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. pages 104 and 148, McGraw-Hill, New York, second edition, ## 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: PDF of the Rayleigh distribution function y = raylpdf (x, sigma) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (x) && ! ismatrix (x)) error ("raylpdf: x must be a numeric matrix"); endif if (! isempty (sigma) && ! ismatrix (sigma)) error ("raylpdf: sigma must be a numeric matrix"); endif if (! isscalar (x) || ! isscalar (sigma)) [retval, x, sigma] = common_size (x, sigma); if (retval > 0) error ("raylpdf: x and sigma must be of common size or scalar"); endif endif # Calculate pdf y = x .* exp ((-x .^ 2) ./ (2 .* sigma .^ 2)) ./ (sigma .^ 2); # Continue argument check k = find (! (x >= 0) | ! (x < Inf) | ! (sigma > 0)); if (any (k)) y(k) = NaN; endif endfunction %!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 (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 (y, expected_y, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/pdist.m0000644000000000000000000000006213443447555015762 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/pdist.m0000644000175000017500000001644413443447555016502 0ustar00johndjohnd00000000000000## Copyright (C) 2008 Francesco Potortì ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} pdist (@var{x}) ## @deftypefnx {Function File} {@var{y} =} pdist (@var{x}, @var{metric}) ## @deftypefnx {Function File} {@var{y} =} pdist (@var{x}, @var{metric}, @var{metricarg}, @dots{}) ## ## Return the distance between any two rows in @var{x}. ## ## @var{x} is the @var{n}x@var{d} matrix representing @var{q} row ## vectors of size @var{d}. ## ## The output is a dissimilarity matrix formatted as a row vector ## @var{y}, @math{(n-1)*n/2} long, where the distances are in ## the order [(1, 2) (1, 3) @dots{} (2, 3) @dots{} (n-1, n)]. You can ## use the @code{squareform} function to display the distances between ## the vectors arranged into an @var{n}x@var{n} matrix. ## ## @code{metric} is an optional argument specifying how the distance is ## computed. It can be any of the following ones, defaulting to ## "euclidean", or a user defined function that takes two arguments ## @var{x} and @var{y} plus any number of optional arguments, ## where @var{x} is a row vector and and @var{y} is a matrix having the ## same number of columns as @var{x}. @code{metric} returns a column ## vector where row @var{i} is the distance between @var{x} and row ## @var{i} of @var{y}. Any additional arguments after the @code{metric} ## are passed as metric (@var{x}, @var{y}, @var{metricarg1}, ## @var{metricarg2} @dots{}). ## ## Predefined distance functions are: ## ## @table @samp ## @item "euclidean" ## Euclidean distance (default). ## ## @item "seuclidean" ## Standardized Euclidean distance. Each coordinate in the sum of ## squares is inverse weighted by the sample variance of that ## coordinate. ## ## @item "mahalanobis" ## Mahalanobis distance: see the function mahalanobis. ## ## @item "cityblock" ## City Block metric, aka Manhattan distance. ## ## @item "minkowski" ## Minkowski metric. Accepts a numeric parameter @var{p}: for @var{p}=1 ## this is the same as the cityblock metric, with @var{p}=2 (default) it ## is equal to the euclidean metric. ## ## @item "cosine" ## One minus the cosine of the included angle between rows, seen as ## vectors. ## ## @item "correlation" ## One minus the sample correlation between points (treated as ## sequences of values). ## ## @item "spearman" ## One minus the sample Spearman's rank correlation between ## observations, treated as sequences of values. ## ## @item "hamming" ## Hamming distance: the quote of the number of coordinates that differ. ## ## @item "jaccard" ## One minus the Jaccard coefficient, the quote of nonzero ## coordinates that differ. ## ## @item "chebychev" ## Chebychev distance: the maximum coordinate difference. ## @end table ## @seealso{linkage, mahalanobis, squareform, pdist2} ## @end deftypefn ## Author: Francesco Potortì function y = pdist (x, metric, varargin) if (nargin < 1) print_usage (); elseif ((nargin > 1) && ! ischar (metric) && ! isa (metric, "function_handle")) error (["pdist: the distance function must be either a string or a " "function handle."]); endif if (nargin < 2) metric = "euclidean"; endif if (! ismatrix (x) || isempty (x)) error ("pdist: x must be a nonempty matrix"); elseif (length (size (x)) > 2) error ("pdist: x must be 1 or 2 dimensional"); endif y = []; if (rows(x) == 1) return; endif if (ischar (metric)) order = nchoosek(1:rows(x),2); Xi = order(:,1); Yi = order(:,2); X = x'; metric = lower (metric); switch (metric) case "euclidean" d = X(:,Xi) - X(:,Yi); y = norm (d, "cols"); case "seuclidean" d = X(:,Xi) - X(:,Yi); weights = inv (diag (var (x, 0, 1))); y = sqrt (sum ((weights * d) .* d, 1)); case "mahalanobis" d = X(:,Xi) - X(:,Yi); weights = inv (cov (x)); y = sqrt (sum ((weights * d) .* d, 1)); case "cityblock" d = X(:,Xi) - X(:,Yi); if (str2num(version()(1:3)) > 3.1) y = norm (d, 1, "cols"); else y = sum (abs (d), 1); endif case "minkowski" d = X(:,Xi) - X(:,Yi); p = 2; # default if (nargin > 2) p = varargin{1}; # explicitly assigned endif; y = norm (d, p, "cols"); case "cosine" prod = X(:,Xi) .* X(:,Yi); weights = sumsq (X(:,Xi), 1) .* sumsq (X(:,Yi), 1); y = 1 - sum (prod, 1) ./ sqrt (weights); case "correlation" if (rows(X) == 1) error ("pdist: correlation distance between scalars not defined") endif cor = corr (X); y = 1 - cor (sub2ind (size (cor), Xi, Yi))'; case "spearman" if (rows(X) == 1) error ("pdist: spearman distance between scalars not defined") endif cor = spearman (X); y = 1 - cor (sub2ind (size (cor), Xi, Yi))'; case "hamming" d = logical (X(:,Xi) - X(:,Yi)); y = sum (d, 1) / rows (X); case "jaccard" d = logical (X(:,Xi) - X(:,Yi)); weights = X(:,Xi) | X(:,Yi); y = sum (d & weights, 1) ./ sum (weights, 1); case "chebychev" d = X(:,Xi) - X(:,Yi); y = norm (d, Inf, "cols"); endswitch endif if (isempty (y)) ## Metric is a function handle or the name of an external function l = rows (x); y = zeros (1, nchoosek (l, 2)); idx = 1; for ii = 1:l-1 for jj = ii+1:l y(idx++) = feval (metric, x(ii,:), x, varargin{:})(jj); endfor endfor endif endfunction %!shared xy, t, eucl %! xy = [0 1; 0 2; 7 6; 5 6]; %! t = 1e-3; %! eucl = @(v,m) sqrt(sumsq(repmat(v,rows(m),1)-m,2)); %!assert(pdist(xy), [1.000 8.602 7.071 8.062 6.403 2.000],t); %!assert(pdist(xy,eucl), [1.000 8.602 7.071 8.062 6.403 2.000],t); %!assert(pdist(xy,"euclidean"), [1.000 8.602 7.071 8.062 6.403 2.000],t); %!assert(pdist(xy,"seuclidean"), [0.380 2.735 2.363 2.486 2.070 0.561],t); %!assert(pdist(xy,"mahalanobis"),[1.384 1.967 2.446 2.384 1.535 2.045],t); %!assert(pdist(xy,"cityblock"), [1.000 12.00 10.00 11.00 9.000 2.000],t); %!assert(pdist(xy,"minkowski"), [1.000 8.602 7.071 8.062 6.403 2.000],t); %!assert(pdist(xy,"minkowski",3),[1.000 7.763 6.299 7.410 5.738 2.000],t); %!assert(pdist(xy,"cosine"), [0.000 0.349 0.231 0.349 0.231 0.013],t); %!assert(pdist(xy,"correlation"),[0.000 2.000 0.000 2.000 0.000 2.000],t); %!assert(pdist(xy,"spearman"), [0.000 2.000 0.000 2.000 0.000 2.000],t); %!assert(pdist(xy,"hamming"), [0.500 1.000 1.000 1.000 1.000 0.500],t); %!assert(pdist(xy,"jaccard"), [1.000 1.000 1.000 1.000 1.000 0.500],t); %!assert(pdist(xy,"chebychev"), [1.000 7.000 5.000 7.000 5.000 2.000],t); statistics-1.4.1/inst/PaxHeaders.29769/dcov.m0000644000000000000000000000006213443447555015572 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/dcov.m0000644000175000017500000001035113443447555016301 0ustar00johndjohnd00000000000000## Copyright (C) 2014 - Maria L. Rizzo and Gabor J. Szekely ## Copyright (C) 2014 Juan Pablo Carbajal ## This work is derived from the R energy package. It was adapted ## for Octave by Juan Pablo Carbajal. ## ## This progrm is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## Author: Juan Pablo Carbajal ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{dCor}, @var{dCov}, @var{dVarX}, @var{dVarY}] =} dcov (@var{x}, @var{y}, @var{index}=1) ## Distance correlation, covariance and correlation statistics. ## ## It returns distace correlation (@var{dCor}), ## distance covariance (@var{dCov}), diatance variace on x (@var{dVarX}) and ## distance variance on y (@var{dVarY}). ## ## Reference: https://en.wikipedia.org/wiki/Distance_correlation ## ## @seealso{corr, cov} ## @end deftypefn function [dCor, dCov, dVarX, dVarY] = dcov (x,y,index=1.0) %x = abs(x - x.'); %y = abs(y - y.'); x = abs (bsxfun (@minus, x, x.')); y = abs (bsxfun (@minus, y, y.')); [n nc] = size (x); [m mc] = size (y); if (n != m) error ("Octave:invalid-input-arg", "Sample sizes must agree."); endif if any (isnan (x) | isnan (y)) error ("Octave:invalid-input-arg","Data contains missing or infinite values."); endif if index < 0 || index > 2 warning ("Octave:invalid-input-arg","index must be in [0,2), using default index=1"); index = 1.0; endif A = Akl (x, index); B = Akl (y, index); dCov = sqrt (mean (A(:) .* B(:))); dVarX = sqrt (mean (A(:).^2) ); dVarY = sqrt (mean (B(:).^2) ); V = sqrt (dVarX .* dVarY); if V > 0 dCor = dCov / V; else dCor = 0; end endfunction function c = Akl (x, index) # Double centered distance d = x .^ index; rm = mean (d, 2); # row mean gm = mean (d(:)); # grand mean c = d - bsxfun (@plus, rm, rm.') + gm; endfunction %!demo %! 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 statistics-1.4.1/inst/PaxHeaders.29769/chi2stat.m0000644000000000000000000000006213443447555016360 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/chi2stat.m0000644000175000017500000000445013443447555017072 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} chi2stat (@var{n}) ## Compute mean and variance of the chi-square distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{n} is the parameter of the chi-square distribution. The elements ## of @var{n} must be positive ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the chi-square distribution ## ## @item ## @var{v} is the variance of the chi-square distribution ## @end itemize ## ## @subheading Example ## ## @example ## @group ## n = 1:6; ## [m, v] = chi2stat (n) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the chi-square distribution function [m, v] = chi2stat (n) # Check arguments if (nargin != 1) print_usage (); endif if (! isempty (n) && ! ismatrix (n)) error ("chi2stat: n must be a numeric matrix"); endif # Calculate moments m = n; v = 2 .* n; # Continue argument check k = find (! (n > 0) | ! (n < Inf)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!test %! n = 1:6; %! [m, v] = chi2stat (n); %! assert (m, n); %! assert (v, [2, 4, 6, 8, 10, 12], 0.001); statistics-1.4.1/inst/PaxHeaders.29769/hist3.m0000644000000000000000000000006213443447555015671 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/hist3.m0000644000175000017500000003105113443447555016400 0ustar00johndjohnd00000000000000## Copyright (C) 2015 Carnë Draug ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {} hist3 (@var{X}) ## @deftypefnx {Function File} {} hist3 (@var{X}, @var{nbins}) ## @deftypefnx {Function File} {} hist3 (@var{X}, @qcode{"Nbins"}, @var{nbins}) ## @deftypefnx {Function File} {} hist3 (@var{X}, @var{centers}) ## @deftypefnx {Function File} {} hist3 (@var{X}, @qcode{"Ctrs"}, @var{centers}) ## @deftypefnx {Function File} {} hist3 (@var{X}, @qcode{"Edges"}, @var{edges}) ## @deftypefnx {Function File} {[@var{N}, @var{C}] =} hist3 (@dots{}) ## @deftypefnx {Function File} {} hist3 (@dots{}, @var{prop}, @var{val}, @dots{}) ## @deftypefnx {Function File} {} hist3 (@var{hax}, @dots{}) ## Produce bivariate (2D) histogram counts or plots. ## ## The elements to produce the histogram are taken from the Nx2 matrix ## @var{X}. Any row with NaN values are ignored. The actual bins can ## be configured in 3 different: number, centers, or edges of the bins: ## ## @table @asis ## @item Number of bins (default) ## Produces equally spaced bins between the minimum and maximum values ## of @var{X}. Defined as a 2 element vector, @var{nbins}, one for each ## dimension. Defaults to @code{[10 10]}. ## ## @item Center of bins ## Defined as a cell array of 2 monotonically increasing vectors, ## @var{centers}. The width of each bin is determined from the adjacent ## values in the vector with the initial and final bin, extending to Infinity. ## ## @item Edge of bins ## Defined as a cell array of 2 monotonically increasing vectors, ## @var{edges}. @code{@var{N}(i,j)} contains the number of elements ## in @var{X} for which: ## ## @itemize @w{} ## @item ## @var{edges}@{1@}(i) <= @var{X}(:,1) < @var{edges}@{1@}(i+1) ## @item ## @var{edges}@{2@}(j) <= @var{X}(:,2) < @var{edges}@{2@}(j+1) ## @end itemize ## ## The consequence of this definition is that values outside the initial ## and final edge values are ignored, and that the final bin only contains ## the number of elements exactly equal to the final edge. ## ## @end table ## ## The return values, @var{N} and @var{C}, are the bin counts and centers ## respectively. These are specially useful to produce intensity maps: ## ## @example ## [counts, centers] = hist3 (data); ## imagesc (centers@{1@}, centers@{2@}, counts) ## @end example ## ## If there is no output argument, or if the axes graphics handle ## @var{hax} is defined, the function will plot a 3 dimensional bar ## graph. Any extra property/value pairs are passed directly to the ## underlying surface object. ## ## @seealso{hist, histc, lookup, mesh} ## @end deftypefn function [N, C] = hist3 (X, varargin) if (nargin < 1) print_usage (); endif next_argin = 1; should_draw = true; if (isaxes (X)) hax = X; X = varargin{next_argin++}; elseif (nargout == 0) hax = gca (); else should_draw = false; endif if (! ismatrix (X) || columns (X) != 2) error ("hist3: X must be a 2 columns matrix"); endif method = "nbins"; val = [10 10]; if (numel (varargin) >= next_argin) this_arg = varargin{next_argin++}; if (isnumeric (this_arg)) method = "nbins"; val = this_arg; elseif (iscell (this_arg)) method = "ctrs"; val = this_arg; elseif (numel (varargin) >= next_argin && any (strcmpi ({"nbins", "ctrs", "edges"}, this_arg))) method = tolower (this_arg); val = varargin{next_argin++}; else next_argin--; endif endif have_centers = false; switch (tolower (method)) case "nbins" [r_edges, c_edges] = edges_from_nbins (X, val); case "ctrs" have_centers = true; centers = val; [r_edges, c_edges] = edges_from_centers (val); case "centers" ## This was supported until 1.2.4 when the Matlab compatible option ## 'Ctrs' was added. persistent warned = false; if (! warned) warning ("hist3: option `centers' is deprecated. Use `ctrs'"); endif have_centers = true; centers = val; [r_edges, c_edges] = edges_from_centers (val); case "edges" if (! iscell (val) || numel (val) != 2 || ! all (cellfun (@isvector, val))) error ("hist3: EDGES must be a cell array with 2 vectors"); endif [r_edges] = vec (val{1}, 2); [c_edges] = vec (val{2}, 2); out_rows = any (X < [r_edges(1) c_edges(1)] | X > [r_edges(end) c_edges(end)], 2); X(out_rows,:) = []; otherwise ## we should never get here... error ("hist3: invalid binning method `%s'", method); endswitch ## We only remove the NaN now, after having computed the bin edges, ## because the extremes from each column that define the edges may ## be paired with a NaN. While such values do not appear on the ## histogram, they must still be used to compute the histogram ## edges. X(any (isnan (X), 2), :) = []; r_idx = lookup (r_edges, X(:,1), "l"); c_idx = lookup (c_edges, X(:,2), "l"); counts_size = [numel(r_edges) numel(c_edges)]; counts = accumarray ([r_idx, c_idx], 1, counts_size); if (should_draw) counts = counts.'; z = zeros ((size (counts) +1) *2); z(2:end-1,2:end-1) = kron (counts, ones (2, 2)); ## Setting the values for the end of the histogram bin like this ## seems straight wrong but that's hwo Matlab plots look. y = [kron(c_edges, ones (1, 2)) (c_edges(end)*2-c_edges(end-1))([1 1])]; x = [kron(r_edges, ones (1, 2)) (r_edges(end)*2-r_edges(end-1))([1 1])]; mesh (hax, x, y, z, "facecolor", [.75 .85 .95], varargin{next_argin:end}); else N = counts; if (isargout (2)) if (! have_centers) C = {(r_edges + [diff(r_edges)([1:end end])]/ 2) ... (c_edges + [diff(c_edges)([1:end end])]/ 2)}; else C = centers(:)'; C{1} = vec (C{1}, 2); C{2} = vec (C{2}, 2); endif endif endif endfunction function [r_edges, c_edges] = edges_from_nbins (X, nbins) if (! isnumeric (nbins) || numel (nbins) != 2) error ("hist3: NBINS must be a 2 element vector"); endif inits = min (X, [], 1); ends = max (X, [], 1); ends -= (ends - inits) ./ vec (nbins, 2); ## If any histogram side has an empty range, then still make NBINS ## but then place that value at the centre of the centre bin so that ## they appear in the centre in the plot. single_bins = inits == ends; if (any (single_bins)) inits(single_bins) -= (floor (nbins(single_bins) ./2)) + 0.5; ends(single_bins) = inits(single_bins) + nbins(single_bins) -1; endif r_edges = linspace (inits(1), ends(1), nbins(1)); c_edges = linspace (inits(2), ends(2), nbins(2)); endfunction function [r_edges, c_edges] = edges_from_centers (ctrs) if (! iscell (ctrs) || numel (ctrs) != 2 || ! all (cellfun (@isvector, ctrs))) error ("hist3: CTRS must be a cell array with 2 vectors"); endif r_edges = vec (ctrs{1}, 2); c_edges = vec (ctrs{2}, 2); r_edges(2:end) -= diff (r_edges) / 2; c_edges(2:end) -= diff (c_edges) / 2; endfunction %!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 (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 (N, N_exp); ## bug 44987 %!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 (c, exp_c); %! assert (nn, {0:4, 0:4}); %!test %! for i = 10 %! assert (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 (c, exp_c); %! %! assert (nn{1}, edge_1 + edge_1(2)/2, eps*10^4) %! assert (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 (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 (nthargout ([1 2], @hist3, X, [5 7]), {N C}, eps*10^3) %! assert (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 (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 (nthargout ([1 2], @hist3, X, "Ctrs", C), {N C}) %! assert (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 (C, C_exp, eps*10^2) ## Test how handling of out of borders is different whether we are ## defining Centers or Edges. %!test %! Xv = repmat ([1:10]', [1 2]); %! %! ## Test Centers %! assert (hist3 (Xv, "Ctrs", {1:10, 1:10}), eye (10)) %! %! N_exp = eye (6); %! N_exp([1 end]) = 3; %! assert (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 (hist3 (Xv, "Ctrs", {2:9, 3:8}), N_exp) %! %! ## Test Edges %! assert (hist3 (Xv, "Edges", {1:10, 1:10}), eye (10)) %! assert (hist3 (Xv, "Edges", {3:8, 3:8}), eye (6)) %! assert (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 (hist3 (Xv, "Edges", {-1:12, -1:12}), N_exp) %! %! ## Test for Nbins %! assert (hist3 (Xv), eye (10)) %! assert (hist3 (Xv, [10 10]), eye (10)) %! assert (hist3 (Xv, "nbins", [10 10]), eye (10)) %! assert (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 (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 (c, exp_c) %! assert (nn, {0:4, 0:4}) ## Single row of data or cases where all elements have the same value ## on one side of the histogram. %!test %! [c, nn] = hist3 ([1 8]); %! exp_c = zeros (10, 10); %! exp_c(6, 6) = 1; %! exp_nn = {-4:5, 3:12}; %! assert (c, exp_c) %! assert (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 (c, exp_c) %! assert (nn, exp_nn, eps) ## NaNs paired with values defining the histogram edges. %!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 (c, exp_c) %! assert (nn, exp_nn, eps*100) ## Columns full of NaNs (recent Matlab versions seem to throw an error ## but this did work like this on R2010b at least). %!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 (c, exp_c) %! assert (nn, exp_nn, eps*100) ## Behaviour of an empty X after removal of rows with NaN. %!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 (c, exp_c) %! assert (nn, exp_nn, eps*100) statistics-1.4.1/inst/PaxHeaders.29769/tripdf.m0000644000000000000000000000006213443447555016127 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/tripdf.m0000644000175000017500000000736713443447555016653 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1997-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} tripdf (@var{x}, @var{a}, @var{b}, @var{c}) ## Compute the probability density function (PDF) at @var{x} of the triangular ## distribution with parameters @var{a}, @var{b}, and @var{c} on the interval ## [@var{a}, @var{b}]. ## @end deftypefn ## Author: Dag Lyberg ## Description: PDF of the triangular distribution function pdf = tripdf (x, a, b, c) if (nargin != 4) print_usage (); endif if (! isscalar (a) || ! isscalar (b) || ! isscalar (c)) [retval, x, a, b, c] = common_size (x, a, b, c); if (retval > 0) error ("tripdf: X, A, B, and C must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (a) || iscomplex (b) || iscomplex (c)) error ("tripdf: X, A, B, and C must not be complex"); endif if (isa (x, "single") || isa (a, "single") ... || isa (b, "single") || isa (c, "single")) pdf = zeros (size (x), "single"); else pdf = zeros (size (x)); endif k = isnan (x) | !(a < b) | !(c >= a) | !(c <= b) ; pdf(k) = NaN; k = (x >= a) & (x <= b) & (a < b) & (a <= c) & (c <= b); h = 2 ./ (b-a); if (isscalar (a) && isscalar (b) && isscalar (c)) j = k & (a <= x) & (x < c); pdf(j) = h * (x(j)-a) / (c-a); j = k & (x == c); pdf(j) = h; j = k & (c < x) & (x <= b); pdf(j) = h * (b-x(j)) / (b-c); else j = k & (a <= x) & (x < c); pdf(j) = h(j) .* (x(j)-a(j)) ./ (c(j)-a(j)); j = k & (x == c); pdf(j) = h(j); j = k & (c < x) & (x <= b); pdf(j) = h(j) .* (b(j)-x(j)) ./ (b(j)-c(j)); endif endfunction %!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 (tripdf (x, ones (1,7), 2*ones (1,7), 1.5*ones (1,7)), y, deps) %!assert (tripdf (x, 1*ones (1,7), 2, 1.5), y, deps) %!assert (tripdf (x, 1, 2*ones (1,7), 1.5), y, deps) %!assert (tripdf (x, 1, 2, 1.5*ones (1,7)), y, deps) %!assert (tripdf (x, 1, 2, 1.5), y, deps) %!assert (tripdf (x, [1, 1, NaN, 1, 1, 1, 1], 2, 1.5), [y(1:2), NaN, y(4:7)], deps) %!assert (tripdf (x, 1, 2*[1, 1, NaN, 1, 1, 1, 1], 1.5), [y(1:2), NaN, y(4:7)], deps) %!assert (tripdf (x, 1, 2, 1.5*[1, 1, NaN, 1, 1, 1, 1]), [y(1:2), NaN, y(4:7)], deps) %!assert (tripdf ([x, NaN], 1, 2, 1.5), [y, NaN], deps) ## Test class of input preserved %!assert (tripdf (single ([x, NaN]), 1, 2, 1.5), single ([y, NaN]), eps('single')) %!assert (tripdf ([x, NaN], single (1), 2, 1.5), single ([y, NaN]), eps('single')) %!assert (tripdf ([x, NaN], 1, single (2), 1.5), single ([y, NaN]), eps('single')) %!assert (tripdf ([x, NaN], 1, 2, single (1.5)), single ([y, NaN]), eps('single')) ## Test input validation %!error tripdf () %!error tripdf (1) %!error tripdf (1,2) %!error tripdf (1,2,3) %!error tripdf (1,2,3,4,5) %!error tripdf (1, ones (3), ones (2), ones (2)) %!error tripdf (1, ones (2), ones (3), ones (2)) %!error tripdf (1, ones (2), ones (2), ones (3)) %!error tripdf (i, 2, 2, 2) %!error tripdf (2, i, 2, 2) %!error tripdf (2, 2, i, 2) %!error tripdf (2, 2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/raylrnd.m0000644000000000000000000000006213443447555016312 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/raylrnd.m0000644000175000017500000001053513443447555017025 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{x} =} raylrnd (@var{sigma}) ## @deftypefnx {Function File} {@var{x} =} raylrnd (@var{sigma}, @var{sz}) ## @deftypefnx {Function File} {@var{x} =} raylrnd (@var{sigma}, @var{r}, @var{c}) ## Generate a matrix of random samples from the Rayleigh distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{sigma} is the parameter of the Rayleigh distribution. The elements ## of @var{sigma} must be positive. ## ## @item ## @var{sz} is the size of the matrix to be generated. @var{sz} must be a ## vector of non-negative integers. ## ## @item ## @var{r} is the number of rows of the matrix to be generated. @var{r} must ## be a non-negative integer. ## ## @item ## @var{c} is the number of columns of the matrix to be generated. @var{c} ## must be a non-negative integer. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{x} is a matrix of random samples from the Rayleigh distribution with ## corresponding parameter @var{sigma}. If neither @var{sz} nor @var{r} and ## @var{c} are specified, then @var{x} is of the same size as @var{sigma}. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## sigma = 1:6; ## x = raylrnd (sigma) ## @end group ## ## @group ## sz = [2, 3]; ## x = raylrnd (0.5, sz) ## @end group ## ## @group ## r = 2; ## c = 3; ## x = raylrnd (0.5, r, c) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. pages 104 and 148, McGraw-Hill, New York, second edition, ## 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Random samples from the Rayleigh distribution function x = raylrnd (sigma, r, c) # Check arguments if (nargin == 1) sz = size (sigma); elseif (nargin == 2) if (! isvector (r) || any ((r < 0) | round (r) != r)) error ("raylrnd: sz must be a vector of non-negative integers") endif sz = r(:)'; if (! isscalar (sigma) && ! isempty (sigma) && (length (size (sigma)) != length (sz) || any (size (sigma) != sz))) error ("raylrnd: sigma must be scalar or of size sz"); endif elseif (nargin == 3) if (! isscalar (r) || any ((r < 0) | round (r) != r)) error ("raylrnd: r must be a non-negative integer") endif if (! isscalar (c) || any ((c < 0) | round (c) != c)) error ("raylrnd: c must be a non-negative integer") endif sz = [r, c]; if (! isscalar (sigma) && ! isempty (sigma) && (length (size (sigma)) != length (sz) || any (size (sigma) != sz))) error ("raylrnd: sigma must be scalar or of size [r, c]"); endif else print_usage (); endif if (! isempty (sigma) && ! ismatrix (sigma)) error ("raylrnd: sigma must be a numeric matrix"); endif if (isempty (sigma)) x = []; elseif (isscalar (sigma) && ! (sigma > 0)) x = NaN .* ones (sz); else # Draw random samples x = sqrt (-2 .* log (1 - rand (sz)) .* sigma .^ 2); # Continue argument check k = find (! (sigma > 0)); if (any (k)) x(k) = NaN; endif endif endfunction %!test %! sigma = 1:6; %! x = raylrnd (sigma); %! assert (size (x), size (sigma)); %! assert (all (x >= 0)); %!test %! sigma = 0.5; %! sz = [2, 3]; %! x = raylrnd (sigma, sz); %! assert (size (x), sz); %! assert (all (x >= 0)); %!test %! sigma = 0.5; %! r = 2; %! c = 3; %! x = raylrnd (sigma, r, c); %! assert (size (x), [r, c]); %! assert (all (x >= 0)); statistics-1.4.1/inst/PaxHeaders.29769/qrandn.m0000644000000000000000000000006213443447555016122 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/qrandn.m0000644000175000017500000000533713443447555016641 0ustar00johndjohnd00000000000000## Copyright (C) 2014 - Juan Pablo Carbajal ## ## This progrm is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## Author: Juan Pablo Carbajal ## -*- texinfo -*- ## @deftypefn {Function File} {@var{z} =} qrandn (@var{q}, @var{r},@var{c}) ## @deftypefnx {Function File} {@var{z} =} qrandn (@var{q}, [@var{r},@var{c}]) ## Returns random deviates drawn from a q-Gaussian distribution. ## ## Parameter @var{q} charcterizes the q-Gaussian distribution. ## The result has the size indicated by @var{s}. ## ## Reference: ## W. Thistleton, J. A. Marsh, K. Nelson, C. Tsallis (2006) ## "Generalized Box-Muller method for generating q-Gaussian random deviates" ## arXiv:cond-mat/0605570 http://arxiv.org/abs/cond-mat/0605570 ## ## @seealso{rand, randn} ## @end deftypefn function z = qrandn(q,R,C=[]) if !isscalar (q) error ('Octave:invalid-input-arg', 'The parameter q must be a scalar.') endif # Check that q < 3 if q > 3 error ('Octave:invalid-input-arg', 'The parameter q must be lower than 3.'); endif if numel (R) > 1 S = R; elseif numel (R) ==1 && isempty (C) S = [R,1]; elseif numel (R) ==1 && !isempty (C) S = [R,C]; endif # Calaulate the q to be used on the q-log qGen = (1 + q) / (3 - q); # Initialize the output vector z = sqrt (-2 * log_q (rand (S),qGen)) .* sin (2*pi*rand (S)); endfunction function a = log_q (x,q) # # Returns the q-log of x, using q # dq = 1 - q; # Check to see if q = 1 (to double precision) if abs (dq) < 10*eps # If q is 1, use the usual natural logarithm a = log (x); else # If q differs from 1, use the definition of the q-log a = ( x .^ dq - 1 ) ./ dq; endif endfunction %!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. statistics-1.4.1/inst/PaxHeaders.29769/geomean.m0000644000000000000000000000006213443447555016252 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/geomean.m0000644000175000017500000000214713443447555016765 0ustar00johndjohnd00000000000000## Copyright (C) 2001 Paul Kienzle ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} geomean (@var{x}) ## @deftypefnx{Function File} geomean (@var{x}, @var{dim}) ## Compute the geometric mean. ## ## This function does the same as @code{mean (x, "g")}. ## ## @seealso{mean} ## @end deftypefn function a = geomean(x, dim) if (nargin == 1) a = mean(x, "g"); elseif (nargin == 2) a = mean(x, "g", dim); else print_usage; endif endfunction statistics-1.4.1/inst/PaxHeaders.29769/ff2n.m0000644000000000000000000000006213443447555015472 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/ff2n.m0000644000175000017500000000047613443447555016210 0ustar00johndjohnd00000000000000## Author: Paul Kienzle ## This program is granted to the public domain. ## -*- texinfo -*- ## @deftypefn {Function File} ff2n (@var{n}) ## Full-factor design with n binary terms. ## ## @seealso {fullfact} ## @end deftypefn function A=ff2n(n) A = fullfact (2 * ones (1,n)) - 1; endfunction statistics-1.4.1/inst/PaxHeaders.29769/@cvpartition0000644000000000000000000000013213444214613017030 xustar0030 mtime=1553013131.065838056 30 atime=1553013131.677852968 30 ctime=1553013131.677852968 statistics-1.4.1/inst/@cvpartition/0000755000175000017500000000000013444214613017616 5ustar00johndjohnd00000000000000statistics-1.4.1/inst/@cvpartition/PaxHeaders.29769/repartition.m0000644000000000000000000000006213443447555021641 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/@cvpartition/repartition.m0000644000175000017500000000453413443447555022356 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see . ## -*- texinfo -*- ## @deftypefn{Function File}{@var{Cnew} =} repartition (@var{C}) ## Return a new cvpartition object. ## ## @var{C} should be a cvpartition object. @var{Cnew} will use the same partition_type as @var{C} but redo any randomization performed (currently, only the HoldOut type uses randomization). ## ## @seealso{cvpartition} ## @end deftypefn ## Author: Nir Krakauer function Cnew = repartition (C) if (nargin < 1 || nargin > 2) print_usage (); endif Cnew = C; switch C.Type case 'kfold' case 'given' case 'holdout' #currently, only the HoldOut method uses randomization n = C.NumObservations; k = C.TestSize; n_classes = C.n_classes; if k < 1 f = k; #target fraction to sample k = round (k * n); #number of samples else f = k / n; endif inds = zeros (n, 1, "logical"); if n_classes == 1 inds(randsample(n, k)) = true; #indices for test set else #sample from each class j = C.classes; #integer class labels n_per_class = accumarray (j, 1); n_classes = numel (n_per_class); k_check = 0; for i = 1:n_classes ki = round(f*n_per_class(i)); inds(find(j == i)(randsample(n_per_class(i), ki))) = true; k_check += ki; endfor if k_check < k #add random elements to test set to make it k inds(find(!inds)(randsample(n - k_check, k - k_check))) = true; elseif k_check > k #remove random elements from test set inds(find(inds)(randsample(k_check, k_check - k))) = false; endif endif Cnew.inds = inds; case 'leaveout' case 'resubstitution' endswitch statistics-1.4.1/inst/@cvpartition/PaxHeaders.29769/training.m0000644000000000000000000000006213443447555021114 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/@cvpartition/training.m0000644000175000017500000000271413443447555021627 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see . ## -*- texinfo -*- ## @deftypefn{Function File}{@var{inds} =} training (@var{C}, [@var{i}]) ## Return logical vector for training-subset indices from a cvpartition object. ## ## @var{C} should be a cvpartition object. @var{i} is the fold index (default is 1). ## ## @seealso{cvpartition, @@cvpartition/test} ## @end deftypefn ## Author: Nir Krakauer function inds = training (C, i = []) if (nargin < 1 || nargin > 2) print_usage (); endif if nargin < 2 || isempty (i) i = 1; endif switch C.Type case {'kfold' 'given'} inds = C.inds != i; case 'holdout' inds = !C.inds; case 'leaveout' inds = ones (C.NumObservations, 1, "logical"); inds(i) = false; case 'resubstitution' inds = ones (C.NumObservations, 1, "logical"); endswitch statistics-1.4.1/inst/@cvpartition/PaxHeaders.29769/get.m0000644000000000000000000000006213443447555020060 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/@cvpartition/get.m0000644000175000017500000000247013443447555020572 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see . ## -*- texinfo -*- ## @deftypefn{Function File}@var{s} = get (@var{c}, [@var{f}]) ## Get a field from a @samp{cvpartition} object. ## ## @seealso{cvpartition} ## @end deftypefn function s = get (c, f) if (nargin == 1) s = c; elseif (nargin == 2) if (ischar (f)) switch (f) case {"classes", "inds", "n_classes", "NumObservations", "NumTestSets", "TestSize", "TrainSize", "Type"} s = eval(["struct(c)." f]); otherwise error ("get: invalid property %s", f); endswitch else error ("get: expecting the property to be a string"); endif else print_usage (); endif endfunction statistics-1.4.1/inst/@cvpartition/PaxHeaders.29769/set.m0000644000000000000000000000006213443447555020074 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/@cvpartition/set.m0000644000175000017500000000302113443447555020577 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see . ## -*- texinfo -*- ## @deftypefn{Function File}@var{s} = set (@var{c}, @var{varargin}) ## Set field(s) in a @samp{cvpartition} object. ## ## @seealso{cvpartition} ## @end deftypefn function s = set (c, varargin) s = struct(c); if (length (varargin) < 2 || rem (length (varargin), 2) != 0) error ("set: expecting property/value pairs"); endif while (length (varargin) > 1) prop = varargin{1}; val = varargin{2}; varargin(1:2) = []; if (ischar (prop)) switch (prop) case {"classes", "inds", "n_classes", "NumObservations", "NumTestSets", "TestSize", "TrainSize", "Type"} s = setfield (s, prop, val); otherwise error ("set: invalid property %s", f); endswitch else error ("set: expecting the property to be a string"); endif endwhile s = class (s, "cvpartition"); endfunction statistics-1.4.1/inst/@cvpartition/PaxHeaders.29769/display.m0000644000000000000000000000006213443447555020746 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/@cvpartition/display.m0000644000175000017500000000265613443447555021466 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see . ## -*- texinfo -*- ## @deftypefn{Function File} display (@var{C}) ## Display a cvpartition object. ## ## @seealso{cvpartition} ## @end deftypefn ## Author: Nir Krakauer function display (C) if nargin != 1 print_usage (); endif switch C.Type case 'kfold' str = 'K-fold'; case 'given' str = 'Given'; case 'holdout' str = 'HoldOut'; case 'leaveout' str = 'Leave-One-Out'; case 'resubstitution' str = 'Resubstitution'; otherwise str = 'Unknown-type'; endswitch disp([str ' cross validation partition']) disp([' N: ' num2str(C.NumObservations)]) disp(['NumTestSets: ' num2str(C.NumTestSets)]) disp([' TrainSize: ' num2str(C.TrainSize')]) disp([' TestSize: ' num2str(C.TestSize')]) statistics-1.4.1/inst/@cvpartition/PaxHeaders.29769/test.m0000644000000000000000000000006213443447555020260 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/@cvpartition/test.m0000644000175000017500000000270313443447555020771 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see . ## -*- texinfo -*- ## @deftypefn{Function File}{@var{inds} =} test (@var{C}, [@var{i}]) ## Return logical vector for testing-subset indices from a cvpartition object. ## ## @var{C} should be a cvpartition object. @var{i} is the fold index (default is 1). ## ## @seealso{cvpartition, @@cvpartition/training} ## @end deftypefn ## Author: Nir Krakauer function inds = test (C, i = []) if (nargin < 1 || nargin > 2) print_usage (); endif if nargin < 2 || isempty (i) i = 1; endif switch C.Type case {'kfold' 'given'} inds = C.inds == i; case 'holdout' inds = C.inds; case 'leaveout' inds = zeros(C.NumObservations, 1, "logical"); inds(i) = true; case 'resubstitution' inds = ones(C.NumObservations, 1, "logical"); endswitch statistics-1.4.1/inst/@cvpartition/PaxHeaders.29769/cvpartition.m0000644000000000000000000000006213443447555021643 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/@cvpartition/cvpartition.m0000644000175000017500000001406513443447555022360 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see . ## -*- texinfo -*- ## @deftypefn{Function File}{@var{C} =} cvpartition (@var{X}, [@var{partition_type}, [@var{k}]]) ## Create a partition object for cross validation. ## ## @var{X} may be a positive integer, interpreted as the number of values @var{n} to partition, or a vector of length @var{n} containing class designations for the elements, in which case the partitioning types @var{KFold} and @var{HoldOut} attempt to ensure each partition represents the classes proportionately. ## ## @var{partition_type} must be one of the following: ## ## @table @asis ## @item @samp{KFold} ## Divide set into @var{k} equal-size subsets (this is the default, with @var{k}=10). ## @item @samp{HoldOut} ## Divide set into two subsets, "training" and "validation". If @var{k} is a fraction, that is the fraction of values put in the validation subset; if it is a positive integer, that is the number of values in the validation subset (by default @var{k}=0.1). ## @item @samp{LeaveOut} ## Leave-one-out partition (each element is placed in its own subset). ## @item @samp{resubstitution} ## Training and validation subsets that both contain all the original elements. ## @item @samp{Given} ## Subset indices are as given in @var{X}. ## @end table ## ## The following fields are defined for the @samp{cvpartition} class: ## ## @table @asis ## @item @samp{classes} ## Class designations for the elements. ## @item @samp{inds} ## Subset indices for the elements. ## @item @samp{n_classes} ## Number of different classes. ## @item @samp{NumObservations} ## @var{n}, number of elements in data set. ## @item @samp{NumTestSets} ## Number of testing subsets. ## @item @samp{TestSize} ## Number of elements in (each) testing subset. ## @item @samp{TrainSize} ## Number of elements in (each) training subset. ## @item @samp{Type} ## Partition type. ## @end table ## ## @seealso{crossval} ## @end deftypefn ## Author: Nir Krakauer function C = cvpartition (X, partition_type = 'KFold', k = []) if (nargin < 1 || nargin > 3 || !isvector(X)) print_usage (); endif if isscalar (X) n = X; n_classes = 1; else n = numel (X); endif switch tolower(partition_type) case {'kfold' 'holdout' 'leaveout' 'resubstitution' 'given'} otherwise warning ('unrecognized type, using KFold') partition_type = 'KFold'; endswitch switch tolower(partition_type) case {'kfold' 'holdout' 'given'} if !isscalar (X) [y, ~, j] = unique (X(:)); n_per_class = accumarray (j, 1); n_classes = numel (n_per_class); endif endswitch C = struct ("classes", [], "inds", [], "n_classes", [], "NumObservations", [], "NumTestSets", [], "TestSize", [], "TrainSize", [], "Type", []); #The non-Matlab fields classes, inds, n_classes are only useful for some methods switch tolower(partition_type) case 'kfold' if isempty (k) k = 10; endif if n_classes == 1 inds = floor((0:(n-1))' * (k / n)) + 1; else inds = nan(n, 1); for i = 1:n_classes if mod (i, 2) #alternate ordering over classes so that the subsets are more nearly the same size inds(j == i) = floor((0:(n_per_class(i)-1))' * (k / n_per_class(i))) + 1; else inds(j == i) = floor(((n_per_class(i)-1):-1:0)' * (k / n_per_class(i))) + 1; endif endfor endif C.inds = inds; C.NumTestSets = k; [~, ~, jj] = unique (inds); n_per_subset = accumarray (jj, 1); C.TrainSize = n - n_per_subset; C.TestSize = n_per_subset; case 'given' C.inds = j; C.NumTestSets = n_classes; C.TrainSize = n - n_per_class; C.TestSize = n_per_class; case 'holdout' if isempty (k) k = 0.1; endif if k < 1 f = k; #target fraction to sample k = round (k * n); #number of samples else f = k / n; endif inds = zeros (n, 1, "logical"); if n_classes == 1 inds(randsample(n, k)) = true; #indices for test set else #sample from each class k_check = 0; for i = 1:n_classes ki = round(f*n_per_class(i)); inds(find(j == i)(randsample(n_per_class(i), ki))) = true; k_check += ki; endfor if k_check < k #add random elements to test set to make it k inds(find(!inds)(randsample(n - k_check, k - k_check))) = true; elseif k_check > k #remove random elements from test set inds(find(inds)(randsample(k_check, k_check - k))) = false; endif C.classes = j; endif C.n_classes = n_classes; C.TrainSize = n - k; C.TestSize = k; C.NumTestSets = 1; C.inds = inds; case 'leaveout' C.TrainSize = ones (n, 1); C.TestSize = (n-1) * ones (n, 1); C.NumTestSets = n; case 'resubstitution' C.TrainSize = C.TestSize = n; C.NumTestSets = 1; endswitch C.NumObservations = n; C.Type = tolower (partition_type); C = class (C, "cvpartition"); endfunction %!demo %! # Partition with Fisher iris dataset (n = 150) %! # Stratified by species %! load fisheriris.txt %! y = fisheriris(:, 1); %! # 10-fold cross-validation partition %! c = cvpartition (y, 'KFold', 10) %! # leave-10-out partition %! c1 = cvpartition (y, 'HoldOut', 10) %! idx1 = test (c, 2); %! idx2 = training (c, 2); %! # another leave-10-out partition %! c2 = repartition (c1) #plot(struct(c).inds, '*') statistics-1.4.1/inst/PaxHeaders.29769/tstat.m0000644000000000000000000000006213443447555015776 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/tstat.m0000644000175000017500000000474313443447555016515 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} tstat (@var{n}) ## Compute mean and variance of the t (Student) distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{n} is the parameter of the t (Student) distribution. The elements ## of @var{n} must be positive ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the t (Student) distribution ## ## @item ## @var{v} is the variance of the t (Student) distribution ## @end itemize ## ## @subheading Example ## ## @example ## @group ## n = 3:8; ## [m, v] = tstat (n) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the t (Student) distribution function [m, v] = tstat (n) # Check arguments if (nargin != 1) print_usage (); endif if (! isempty (n) && ! ismatrix (n)) error ("tstat: n must be a numeric matrix"); endif # Calculate moments m = zeros (size (n)); v = n ./ (n - 2); # Continue argument check k = find (! (n > 1) | ! (n < Inf)); if (any (k)) m(k) = NaN; v(k) = NaN; endif k = find (! (n > 2) & (n < Inf)); if (any (k)) v(k) = Inf; endif endfunction %!test %! n = 3:8; %! [m, v] = tstat (n); %! expected_m = [0, 0, 0, 0, 0, 0]; %! expected_v = [3.0000, 2.0000, 1.6667, 1.5000, 1.4000, 1.3333]; %! assert (m, expected_m); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/plsregress.m0000644000000000000000000000006213443447555017030 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/plsregress.m0000644000175000017500000000706713443447555017551 0ustar00johndjohnd00000000000000## Copyright (C) 2012-2019 Fernando Damian Nieuwveldt ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version 3 ## of the License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{XLOADINGS},@var{YLOADINGS},@var{XSCORES},@var{YSCORES},@var{coefficients},@var{fitted}] =} plsregress(@var{X}, @var{Y}, @var{NCOMP}) ## Calculate partial least squares regression ## ## @itemize @bullet ## @item ## @var{X}: Matrix of observations ## @item ## @var{Y}: Is a vector or matrix of responses ## @item ## @var{NCOMP}: number of components used for modelling ## @item ## @var{X} and @var{Y} will be mean centered to improve accuracy ## @end itemize ## ## @subheading References ## ## @enumerate ## @item ## SIMPLS: An alternative approach to partial least squares regression. Chemometrics and Intelligent Laboratory ## Systems (1993) ## ## @end enumerate ## @end deftypefn ## Author: Fernando Damian Nieuwveldt ## Description: Partial least squares regression using SIMPLS algorithm function [XLOADINGS, YLOADINGS, XSCORES, YSCORES, coefficients, fitted] = plsregress (X, Y, NCOMP) if nargout != 6 print_usage(); end nobs = rows (X); # Number of observations npred = columns (X); # Number of predictor variables nresp = columns (Y); # Number of responses if (! isnumeric (X) || ! isnumeric (Y)) error ("plsregress:Data matrix X and reponse matrix Y must be real matrices"); elseif (nobs != rows (Y)) error ("plsregress:Number of observations for Data matrix X and Response Matrix Y must be equal"); elseif(! isscalar (NCOMP)) error ("plsregress: Third argument must be a scalar"); end ## Mean centering Data matrix Xmeans = mean (X); X = bsxfun (@minus, X, Xmeans); ## Mean centering responses Ymeans = mean (Y); Y = bsxfun (@minus, Y, Ymeans); S = X'*Y; R = P = V = zeros (npred, NCOMP); T = U = zeros (nobs, NCOMP); Q = zeros (nresp, NCOMP); for a = 1:NCOMP [eigvec eigval] = eig (S'*S); # Y factor weights domindex = find (diag (eigval) == max (diag (eigval))); # get dominant eigenvector q = eigvec(:,domindex); r = S*q; # X block factor weights t = X*r; # X block factor scores t = t - mean (t); nt = sqrt (t'*t); # compute norm t = t/nt; r = r/nt; # normalize p = X'*t; # X block factor loadings q = Y'*t; # Y block factor loadings u = Y*q; # Y block factor scores v = p; ## Ensure orthogonality if a > 1 v = v - V*(V'*p); u = u - T*(T'*u); endif v = v/sqrt(v'*v); # normalize orthogonal loadings S = S - v*(v'*S); # deflate S wrt loadings ## Store data R(:,a) = r; T(:,a) = t; P(:,a) = p; Q(:,a) = q; U(:,a) = u; V(:,a) = v; endfor ## Regression coefficients B = R*Q'; fitted = bsxfun (@plus, T*Q', Ymeans); # Add mean ## Return coefficients = B; XSCORES = T; XLOADINGS = P; YSCORES = U; YLOADINGS = Q; projection = R; endfunction statistics-1.4.1/inst/PaxHeaders.29769/anderson_darling_test.m0000644000000000000000000000006213443447555021207 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/anderson_darling_test.m0000644000175000017500000001235013443447555021717 0ustar00johndjohnd00000000000000## Author: Paul Kienzle ## This program is granted to the public domain. ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{q}, @var{Asq}, @var{info}] = } = @ ## anderson_darling_test (@var{x}, @var{distribution}) ## ## Test the hypothesis that @var{x} is selected from the given distribution ## using the Anderson-Darling test. If the returned @var{q} is small, reject ## the hypothesis at the @var{q}*100% level. ## ## The Anderson-Darling @math{@var{A}^2} statistic is calculated as follows: ## ## @example ## @iftex ## A^2_n = -n - \sum_{i=1}^n (2i-1)/n log(z_i (1-z_{n-i+1})) ## @end iftex ## @ifnottex ## n ## A^2_n = -n - SUM (2i-1)/n log(@math{z_i} (1 - @math{z_@{n-i+1@}})) ## i=1 ## @end ifnottex ## @end example ## ## where @math{z_i} is the ordered position of the @var{x}'s in the CDF of the ## distribution. Unlike the Kolmogorov-Smirnov statistic, the ## Anderson-Darling statistic is sensitive to the tails of the ## distribution. ## ## The @var{distribution} argument must be a either @t{"uniform"}, @t{"normal"}, ## or @t{"exponential"}. ## ## For @t{"normal"}' and @t{"exponential"} distributions, estimate the ## distribution parameters from the data, convert the values ## to CDF values, and compare the result to tabluated critical ## values. This includes an correction for small @var{n} which ## works well enough for @var{n} >= 8, but less so from smaller @var{n}. The ## returned @code{info.Asq_corrected} contains the adjusted statistic. ## ## For @t{"uniform"}, assume the values are uniformly distributed ## in (0,1), compute @math{@var{A}^2} and return the corresponding @math{p}-value from ## @code{1-anderson_darling_cdf(A^2,n)}. ## ## If you are selecting from a known distribution, convert your ## values into CDF values for the distribution and use @t{"uniform"}. ## Do not use @t{"uniform"} if the distribution parameters are estimated ## from the data itself, as this sharply biases the @math{A^2} statistic ## toward smaller values. ## ## [1] Stephens, MA; (1986), "Tests based on EDF statistics", in ## D'Agostino, RB; Stephens, MA; (eds.) Goodness-of-fit Techinques. ## New York: Dekker. ## ## @seealso{anderson_darling_cdf} ## @end deftypefn function [q,Asq,info] = anderson_darling_test(x,dist) if size(x,1) == 1, x=x(:); end x = sort(x); n = size(x,1); use_cdf = 0; # Compute adjustment and critical values to use for stats. switch dist case 'normal', # This expression for adj is used in R. # Note that the values from NIST dataplot don't work nearly as well. adj = 1 + (.75 + 2.25/n)/n; qvals = [ 0.1, 0.05, 0.025, 0.01 ]; Acrit = [ 0.631, 0.752, 0.873, 1.035]; x = stdnormal_cdf(zscore(x)); case 'uniform', ## Put invalid data at the limits of the distribution ## This will drive the statistic to infinity. x(x<0) = 0; x(x>1) = 1; adj = 1.; qvals = [ 0.1, 0.05, 0.025, 0.01 ]; Acrit = [ 1.933, 2.492, 3.070, 3.857 ]; use_cdf = 1; case 'XXXweibull', adj = 1 + 0.2/sqrt(n); qvals = [ 0.1, 0.05, 0.025, 0.01 ]; Acrit = [ 0.637, 0.757, 0.877, 1.038]; ## XXX FIXME XXX how to fit alpha and sigma? x = wblcdf (x, ones(n,1)*sigma, ones(n,1)*alpha); case 'exponential', adj = 1 + 0.6/n; qvals = [ 0.1, 0.05, 0.025, 0.01 ]; # Critical values depend on n. Choose the appropriate critical set. # These values come from NIST dataplot/src/dp8.f. Acritn = [ 0, 1.022, 1.265, 1.515, 1.888 11, 1.045, 1.300, 1.556, 1.927; 21, 1.062, 1.323, 1.582, 1.945; 51, 1.070, 1.330, 1.595, 1.951; 101, 1.078, 1.341, 1.606, 1.957; ]; # FIXME: consider interpolating in the critical value table. Acrit = Acritn(lookup(Acritn(:,1),n),2:5); lambda = 1./mean(x); # exponential parameter estimation x = expcdf(x, 1./(ones(n,1)*lambda)); otherwise # FIXME consider implementing more of distributions; a number # of them are defined in NIST dataplot/src/dp8.f. error("Anderson-Darling test for %s not implemented", dist); endswitch if any(x<0 | x>1) error('Anderson-Darling test requires data in CDF form'); endif i = [1:n]'*ones(1,size(x,2)); Asq = -n - sum( (2*i-1) .* (log(x) + log(1-x(n:-1:1,:))) )/n; # Lookup adjusted critical value in the cdf (if uniform) or in the # the critical table. if use_cdf q = 1-anderson_darling_cdf(Asq*adj, n); else idx = lookup([-Inf,Acrit],Asq*adj); q = [1,qvals](idx); endif if nargout > 2, info.Asq = Asq; info.Asq_corrected = Asq*adj; info.Asq_critical = [100*(1-qvals); Acrit]'; info.p = 1-q; info.p_is_precise = use_cdf; endif endfunction %!demo %! c = anderson_darling_test(10*rande(12,10000),'exponential'); %! tabulate(100*c,100*[unique(c),1]); %! % The Fc column should report 100, 250, 500, 1000, 10000 more or less. %!demo %! c = anderson_darling_test(randn(12,10000),'normal'); %! tabulate(100*c,100*[unique(c),1]); %! % The Fc column should report 100, 250, 500, 1000, 10000 more or less. %!demo %! c = anderson_darling_test(rand(12,10000),'uniform'); %! hist(100*c,1:2:99); %! % The histogram should be flat more or less. statistics-1.4.1/inst/PaxHeaders.29769/trirnd.m0000644000000000000000000000006213443447555016141 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/trirnd.m0000644000175000017500000001242713443447555016656 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} trirnd (@var{a}, @var{b}, @var{c}) ## @deftypefnx {} {} trirnd (@var{a}, @var{b}, @var{c}, @var{r}) ## @deftypefnx {} {} trirnd (@var{a}, @var{b}, @var{c}, @var{r}, @var{c}, @dots{}) ## @deftypefnx {} {} trirnd (@var{a}, @var{b}, @var{c}, [@var{sz}]) ## Return a matrix of random samples from the rectangular distribution with ## parameters @var{a}, @var{b}, and @var{c} on the interval [@var{a}, @var{b}]. ## ## When called with a single size argument, return a square matrix with ## the dimension specified. When called with more than one scalar argument the ## first two arguments are taken as the number of rows and columns and any ## further arguments specify additional matrix dimensions. The size may also ## be specified with a vector of dimensions @var{sz}. ## ## If no size arguments are given then the result matrix is the common size of ## @var{a}, @var{b} and @var{c}. ## @end deftypefn ## Author: Dag Lyberg ## Description: Random deviates from the triangular distribution function rnd = trirnd (a, b, c, varargin) if (nargin < 3) print_usage (); endif if (! isscalar (a) || ! isscalar (b) || ! isscalar (c)) [retval, a, b, c] = common_size (a, b, c); if (retval > 0) error ("trirnd: A, B, and C must be of common size or scalars"); endif endif if (iscomplex (a) || iscomplex (b) || iscomplex (c)) error ("trirnd: A, B, and C must not be complex"); endif if (nargin == 3) sz = size (a); elseif (nargin == 4) if (isscalar (varargin{1}) && varargin{1} >= 0) sz = [varargin{1}, varargin{1}]; elseif (isrow (varargin{1}) && all (varargin{1} >= 0)) sz = varargin{1}; else error ("trirnd: dimension vector must be row vector of non-negative integers"); endif elseif (nargin > 4) if (any (cellfun (@(x) (! isscalar (x) || x < 0), varargin))) error ("trirnd: dimensions must be non-negative integers"); endif sz = [varargin{:}]; endif if (! isscalar (a) && ! isequal (size (b), sz)) error ("trirnd: A, B, and C must be scalar or of size SZ"); endif if (isa (a, "single") || isa (b, "single") || isa (c, "single")) cls = "single"; else cls = "double"; endif if (isscalar (a) && isscalar (b) && isscalar (c)) if ((-Inf < a) && (a < b) && (a <= c) && (c <= b) && (b < Inf)) w = b-a; left_width = c-a; right_width = b-c; h = 2 / w; left_area = h * left_width / 2; rnd = rand (sz, cls); idx = rnd < left_area; rnd(idx) = a + (rnd(idx) * w * left_width).^0.5; rnd(~idx) = b - ((1-rnd(~idx)) * w * right_width).^0.5; else rnd = NaN (sz, cls); endif else w = b-a; left_width = c-a; right_width = b-c; h = 2 ./ w; left_area = h .* left_width / 2; rnd = rand (sz, cls); k = rnd < left_area; rnd(k) = a(k) + (rnd(k) .* w(k) .* left_width(k)).^0.5; rnd(~k) = b(~k) - ((1-rnd(~k)) .* w(~k) .* right_width(~k)).^0.5; k = ! (-Inf < a) | ! (a < b) | ! (a <= c) | ! (c <= b) | ! (b < Inf); rnd(k) = NaN; endif endfunction %!assert (size (trirnd (1,2,1.5)), [1, 1]) %!assert (size (trirnd (1*ones (2,1), 2,1.5)), [2, 1]) %!assert (size (trirnd (1*ones (2,2), 2,1.5)), [2, 2]) %!assert (size (trirnd (1, 2*ones (2,1), 1.5)), [2, 1]) %!assert (size (trirnd (1, 2*ones (2,2), 1.5)), [2, 2]) %!assert (size (trirnd (1, 2, 1.5*ones (2,1))), [2, 1]) %!assert (size (trirnd (1, 2, 1.5*ones (2,2))), [2, 2]) %!assert (size (trirnd (1, 2, 1.5, 3)), [3, 3]) %!assert (size (trirnd (1, 2, 1.5, [4 1])), [4, 1]) %!assert (size (trirnd (1, 2, 1.5, 4, 1)), [4, 1]) ## Test class of input preserved %!assert (class (trirnd (1,2,1.5)), "double") %!assert (class (trirnd (single (1),2,1.5)), "single") %!assert (class (trirnd (single ([1 1]),2,1.5)), "single") %!assert (class (trirnd (1,single (2),1.5)), "single") %!assert (class (trirnd (1,single ([2 2]),1.5)), "single") %!assert (class (trirnd (1,2,single (1.5))), "single") %!assert (class (trirnd (1,2,single ([1.5 1.5]))), "single") ## Test input validation %!error trirnd () %!error trirnd (1) %!error trirnd (1,2) %!error trirnd (ones (3), 2*ones (2), 1.5*ones (2), 2) %!error trirnd (ones (2), 2*ones (3), 1.5*ones (2), 2) %!error trirnd (ones (2), 2*ones (2), 1.5*ones (3), 2) %!error trirnd (i, 2, 1.5) %!error trirnd (1, i, 1.5) %!error trirnd (1, 2, i) %!error trirnd (1,2,1.5, -1) %!error trirnd (1,2,1.5, ones (2)) %!error trirnd (1,2,1.5, [2 -1 2]) %!error trirnd (1*ones (2),2,1.5, 3) %!error trirnd (1*ones (2),2,1.5, [3, 2]) %!error trirnd (1*ones (2),2,1.5, 3, 2) statistics-1.4.1/inst/PaxHeaders.29769/hmmgenerate.m0000644000000000000000000000006213443447555017133 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/hmmgenerate.m0000644000175000017500000002102413443447555017641 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{sequence}, @var{states}] =} hmmgenerate (@var{len}, @var{transprob}, @var{outprob}) ## @deftypefnx {Function File} {} hmmgenerate (@dots{}, 'symbols', @var{symbols}) ## @deftypefnx {Function File} {} hmmgenerate (@dots{}, 'statenames', @var{statenames}) ## Generate an output sequence and hidden states of a hidden Markov model. ## The model starts in state @code{1} at step @code{0} but will not include ## step @code{0} in the generated states and sequence. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{len} is the number of steps to generate. @var{sequence} and ## @var{states} will have @var{len} entries each. ## ## @item ## @var{transprob} is the matrix of transition probabilities of the states. ## @code{transprob(i, j)} is the probability of a transition to state ## @code{j} given state @code{i}. ## ## @item ## @var{outprob} is the matrix of output probabilities. ## @code{outprob(i, j)} is the probability of generating output @code{j} ## given state @code{i}. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{sequence} is a vector of length @var{len} of the generated ## outputs. The outputs are integers ranging from @code{1} to ## @code{columns (outprob)}. ## ## @item ## @var{states} is a vector of length @var{len} of the generated hidden ## states. The states are integers ranging from @code{1} to ## @code{columns (transprob)}. ## @end itemize ## ## If @code{'symbols'} is specified, then the elements of @var{symbols} are ## used for the output sequence instead of integers ranging from @code{1} to ## @code{columns (outprob)}. @var{symbols} can be a cell array. ## ## If @code{'statenames'} is specified, then the elements of ## @var{statenames} are used for the states instead of integers ranging from ## @code{1} to @code{columns (transprob)}. @var{statenames} can be a cell ## array. ## ## @subheading Examples ## ## @example ## @group ## 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 (25, transprob, outprob) ## @end group ## ## @group ## symbols = @{'A', 'B', 'C'@}; ## statenames = @{'One', 'Two'@}; ## [sequence, states] = hmmgenerate (25, transprob, outprob, ## 'symbols', symbols, 'statenames', statenames) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Lawrence R. Rabiner. A Tutorial on Hidden Markov Models and Selected ## Applications in Speech Recognition. @cite{Proceedings of the IEEE}, ## 77(2), pages 257-286, February 1989. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Output sequence and hidden states of a hidden Markov model function [sequence, states] = hmmgenerate (len, transprob, outprob, varargin) # Check arguments if (nargin < 3 || mod (length (varargin), 2) != 0) print_usage (); endif if (! isscalar (len) || len < 0 || round (len) != len) error ("hmmgenerate: len must be a non-negative scalar integer") endif if (! ismatrix (transprob)) error ("hmmgenerate: transprob must be a non-empty numeric matrix"); endif if (! ismatrix (outprob)) error ("hmmgenerate: outprob must be a non-empty numeric matrix"); endif # nstate is the number of states of the hidden Markov model nstate = rows (transprob); # noutput is the number of different outputs that the hidden Markov model # can generate noutput = columns (outprob); # Check whether transprob and outprob are feasible for a hidden Markov # model if (columns (transprob) != nstate) error ("hmmgenerate: transprob must be a square matrix"); endif if (rows (outprob) != nstate) error ("hmmgenerate: outprob must have the same number of rows as transprob"); endif # Flag for symbols usesym = false; # Flag for statenames usesn = false; # Process varargin for i = 1:2:length (varargin) # There must be an identifier: 'symbols' or 'statenames' if (! ischar (varargin{i})) print_usage (); endif # Upper case is also fine lowerarg = lower (varargin{i}); if (strcmp (lowerarg, 'symbols')) if (length (varargin{i + 1}) != noutput) error ("hmmgenerate: number of symbols does not match number of possible outputs"); endif usesym = true; # Use the following argument as symbols symbols = varargin{i + 1}; # The same for statenames elseif (strcmp (lowerarg, 'statenames')) if (length (varargin{i + 1}) != nstate) error ("hmmgenerate: number of statenames does not match number of states"); endif usesn = true; # Use the following argument as statenames statenames = varargin{i + 1}; else error ("hmmgenerate: expected 'symbols' or 'statenames' but found '%s'", varargin{i}); endif endfor # Each row in transprob and outprob should contain probabilities # => scale so that the sum is 1 # A zero row remains zero # - for transprob s = sum (transprob, 2); s(s == 0) = 1; transprob = transprob ./ repmat (s, 1, nstate); # - for outprob s = sum (outprob, 2); s(s == 0) = 1; outprob = outprob ./ repmat (s, 1, noutput); # Generate sequences of uniformly distributed random numbers between 0 and # 1 # - for the state transitions transdraw = rand (1, len); # - for the outputs outdraw = rand (1, len); # Generate the return vectors # They remain unchanged if the according probability row of transprob # and outprob contain, respectively, only zeros sequence = ones (1, len); states = ones (1, len); if (len > 0) # Calculate cumulated probabilities backwards for easy comparison with # the generated random numbers # Cumulated probability in first column must always be 1 # We might have a zero row # - for transprob transprob(:, end:-1:1) = cumsum (transprob(:, end:-1:1), 2); transprob(:, 1) = 1; # - for outprob outprob(:, end:-1:1) = cumsum (outprob(:, end:-1:1), 2); outprob(:, 1) = 1; # cstate is the current state # Start in state 1 but do not include it in the states vector cstate = 1; for i = 1:len # Compare the randon number i of transdraw to the cumulated # probability of the state transition and set the transition # accordingly states(i) = sum (transdraw(i) <= transprob(cstate, :)); cstate = states(i); endfor # Compare the random numbers of outdraw to the cumulated probabilities # of the outputs and set the sequence vector accordingly sequence = sum (repmat (outdraw, noutput, 1) <= outprob(states, :)', 1); # Transform default matrices into symbols/statenames if requested if (usesym) sequence = reshape (symbols(sequence), 1, len); endif if (usesn) states = reshape (statenames(states), 1, len); endif endif endfunction %!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 (length (sequence), len); %! assert (length (states), len); %! assert (min (sequence) >= 1); %! assert (max (sequence) <= columns (outprob)); %! assert (min (states) >= 1); %! assert (max (states) <= rows (transprob)); %!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 (length (sequence), len); %! assert (length (states), len); %! assert (strcmp (sequence, 'A') + strcmp (sequence, 'B') + strcmp (sequence, 'C') == ones (1, len)); %! assert (strcmp (states, 'One') + strcmp (states, 'Two') == ones (1, len)); statistics-1.4.1/inst/PaxHeaders.29769/unifstat.m0000644000000000000000000000006213443447555016474 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/unifstat.m0000644000175000017500000000645013443447555017210 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} unifstat (@var{a}, @var{b}) ## Compute mean and variance of the continuous uniform distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{a} is the first parameter of the continuous uniform distribution ## ## @item ## @var{b} is the second parameter of the continuous uniform distribution ## @end itemize ## @var{a} and @var{b} must be of common size or one of them must be scalar ## and @var{a} must be less than @var{b} ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the continuous uniform distribution ## ## @item ## @var{v} is the variance of the continuous uniform distribution ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## a = 1:6; ## b = 2:2:12; ## [m, v] = unifstat (a, b) ## @end group ## ## @group ## [m, v] = unifstat (a, 10) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the continuous uniform distribution function [m, v] = unifstat (a, b) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (a) && ! ismatrix (a)) error ("unifstat: a must be a numeric matrix"); endif if (! isempty (b) && ! ismatrix (b)) error ("unifstat: b must be a numeric matrix"); endif if (! isscalar (a) || ! isscalar (b)) [retval, a, b] = common_size (a, b); if (retval > 0) error ("unifstat: a and b must be of common size or scalar"); endif endif # Calculate moments m = (a + b) ./ 2; v = ((b - a) .^ 2) ./ 12; # Continue argument check k = find (! (-Inf < a) | ! (a < b) | ! (b < Inf)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!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 (m, expected_m, 0.001); %! assert (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 (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/violin.m0000644000000000000000000000006213443447555016137 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/violin.m0000644000175000017500000002316013443447555016650 0ustar00johndjohnd00000000000000## Copyright (C) 2016 - Juan Pablo Carbajal ## ## This progrm is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## Author: Juan Pablo Carbajal ## -*- texinfo -*- ## @defun {@var{h} =} violin (@var{x}) ## @defunx {@var{h} =} violin (@dots{}, @var{property}, @var{value}, @dots{}) ## @defunx {@var{h} =} violin (@var{hax}, @dots{}) ## @defunx {@var{h} =} violin (@dots{}, @asis{"horizontal"}) ## Produce a Violin plot of the data @var{x}. ## ## The input data @var{x} can be a N-by-m array containg N observations of m variables. ## It can also be a cell with m elements, for the case in which the varibales ## are not uniformly sampled. ## ## The following @var{property} can be set using @var{property}/@var{value} pairs ## (default values in parenthesis). ## The value of the property can be a scalar indicating that it applies ## to all the variables in the data. ## It can also be a cell/array, indicating the property for each variable. ## In this case it should have m columns (as many as variables). ## ## @table @asis ## ## @item Color ## (@asis{"y"}) Indicates the filling color of the violins. ## ## @item Nbins ## (50) Internally, the function calls @command{hist} to compute the histogram of the data. ## This property indicates how many bins to use. See @command{help hist} ## for more details. ## ## @item SmoothFactor ## (4) The fuction performs simple kernel density estimation and automatically ## finds the bandwith of the kernel function that best approximates the histogram ## using optimization (@command{sqp}). ## The result is in general very noisy. To smooth the result the bandwidth is ## multiplied by the value of this property. The higher the value the smoother ## the violings, but values too high might remove features from the data distribution. ## ## @item Bandwidth ## (NA) If this property is given a value other than NA, it sets the bandwith of the ## kernel function. No optimization is peformed and the property @asis{SmoothFactor} ## is ignored. ## ## @item Width ## (0.5) Sets the maximum width of the violins. Violins are centered at integer axis ## values. The distance between two violin middle axis is 1. Setting a value ## higher thna 1 in this property will cause the violins to overlap. ## @end table ## ## If the string @asis{"Horizontal"} is among the input arguments, the violin ## plot is rendered along the x axis with the variables in the y axis. ## ## The returned structure @var{h} has handles to the plot elements, allowing ## customization of the visualization using set/get functions. ## ## Example: ## ## @example ## title ("Grade 3 heights"); ## axis ([0,3]); ## set (gca, "xtick", 1:2, "xticklabel", @{"girls"; "boys"@}); ## h = violin (@{randn(100,1)*5+140, randn(130,1)*8+135@}, "Nbins", 10); ## set (h.violin, "linewidth", 2) ## @end example ## ## @seealso{boxplot, hist} ## @end defun function h = violin (ax, varargin) old_hold = ishold (); # First argument is not an axis if (~ishandle (ax) || ~isscalar (ax)) x = ax; ax = gca (); else x = varargin{1}; varargin(1) = []; endif ###################### ## Parse parameters ## parser = inputParser (); parser.CaseSensitive = false; parser.FunctionName = 'violin'; parser.addParamValue ('Nbins', 50); parser.addParamValue ('SmoothFactor', 4); parser.addParamValue ('Bandwidth', NA); parser.addParamValue ('Width', 0.5); parser.addParamValue ('Color', "y"); parser.addSwitch ('Horizontal'); parser.parse (varargin{:}); res = parser.Results; c = res.Color; # Color of violins if (ischar (c)) c = c(:); endif nb = res.Nbins; # Number of bins in histogram sf = res.SmoothFactor; # Smoothing factor for kernel estimation r0 = res.Bandwidth; # User value for KDE bandwth to prevent optimization is_horiz = res.Horizontal; # Whether the plot must be rotated width = res.Width; # Width of the violins clear parser res ###################### ## Make everything a cell for code simplicity if (~iscell (x)) [N Nc] = size (x); x = mat2cell (x, N, ones (1, Nc)); else Nc = numel (x); endif try [nb, c, sf, r0, width] = to_cell (nb, c, sf, r0, width, Nc); catch err if strcmp (err.identifier, "to_cell:element_idx") n = str2num (err.message); txt = {"Nbins", "Color", "SmoothFactor", "Bandwidth", "Width"}; error ("Octave:invaid-input-arg", ... ["options should be scalars or call/array with as many values as" ... " numbers of variables in the data (wrong size of %s)."], txt{n}); else rethrow (lasterror()) endif end ## Build violins [px py mx] = cellfun (@(y,n,s,r)build_polygon(y, n, s, r), ... x, nb, sf, r0, "unif", 0); Nc = 1:numel (px); Ncc = mat2cell (Nc, 1, ones (1, Nc(end))); # get hold state old_hold = ishold (); # Draw plain violins tmp = cellfun (@(x,y,n,u, w)patch(ax, (w * x + n)(:), y(:) ,u), ... px, py, Ncc, c, width); h.violin = tmp; hold on # Overlay mean value tmp = cellfun (@(z,y)plot(ax, z, y,'.k', "markersize", 6), Ncc, mx); h.mean = tmp; # Overlay median Mx = cellfun (@median, x, "unif", 0); tmp = cellfun (@(z,y)plot(ax, z, y, 'ok'), Ncc, Mx); h.median = tmp; # Overlay 1nd and 3th quartiles LUBU = cellfun (@(x,y)abs(quantile(x,[0.25 0.75])-y), x, Mx, "unif", 0); tmp = cellfun (@(x,y,z)errorbar(ax, x, y, z(1),z(2)), Ncc, Mx, LUBU)(:); # Flatten errorbar output handles tmp2 = allchild (tmp); if (~iscell (tmp2)) tmp2 = mat2cell (tmp2, ones(length (tmp2), 1), 1); endif tmp = mat2cell (tmp, ones (length (tmp), 1), 1); tmp = cellfun (@vertcat, tmp, tmp2, "unif", 0); h.quartile = cell2mat (tmp); hold off # Rotate the plot if it is horizontal if (is_horiz) structfun (@swap_axes, h); set (ax, "ytick", Nc); else set (ax, "xtick", Nc); endif if (nargout < 1); clear h; endif # restore hold state if (old_hold) hold on endif endfunction function k = kde(x,r) k = mean (stdnormal_pdf (x / r)) / r; k /= max (k); endfunction function [px py mx] = build_polygon (x, nb, sf, r) N = size (x, 1); mx = mean (x); sx = std (x); X = (x - mx ) / sx; [count bin] = hist (X, nb); count /= max (count); Y = X - bin; if isna (r) r0 = 1.06 * N^(1/5); r = sqp (r0, @(r)sumsq (kde(Y,r) - count), [], [], 1e-3, 1e2); else sf = 1; endif sig = sf * r; ## Create violin polygon # smooth tails: extend to 1.83 sigmas, i.e. ~99% of data. xx = linspace (0, 1.83 * sig, 5); bin = [bin(1)-fliplr(xx) bin bin(end)+xx]; py = [bin; fliplr(bin)].' * sx + mx; v = kde (X-bin, sig).'; px = [v -flipud(v)]; endfunction function tf = swap_axes (h) tmp = mat2cell (h(:), ones (length (h),1), 1); % tmp = cellfun (@(x)[x; allchild(x)], tmp, "unif", 0); tmpy = cellfun(@(x)get(x, "ydata"), tmp, "unif", 0); tmpx = cellfun(@(x)get(x, "xdata"), tmp, "unif", 0); cellfun (@(h,x,y)set (h, "xdata", y, "ydata", x), tmp, tmpx, tmpy); tf = true; endfunction function varargout = to_cell (varargin) m = varargin{end}; varargin(end) = []; for i = 1:numel(varargin) x = varargin{i}; if (isscalar (x)) x = repmat (x, m, 1); endif if (iscell (x)) if (numel(x) ~= m) # no dimension equals m error ("to_cell:element_idx", "%d\n",i); endif varargout{i} = x; continue endif sz = size (x); d = find (sz == m); if (isempty (d)) # no dimension equals m error ("to_cell:element_idx", "%d\n",i); elseif (length (d) == 2) #both dims are m, choose 1st elseif (d == 1) # 2nd dimension is m --> transpose x = x.'; sz = fliplr (sz); endif varargout{i} = mat2cell (x, sz(1), ones (m,1)); endfor endfunction %!demo %! 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 %! 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 %! clf %! data = exprnd (0.1, 500,4); %! violin (data, "nbins", {5,10,50,100}); %! axis ([0 5 0 max(data(:))]) %!demo %! clf %! data = exprnd (0.1, 500,4); %! violin (data, "color", jet(4)); %! axis ([0 5 0 max(data(:))]) %!demo %! 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 %! 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(:))]) statistics-1.4.1/inst/PaxHeaders.29769/gamstat.m0000644000000000000000000000006213443447555016277 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gamstat.m0000644000175000017500000000627613443447555017021 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} gamstat (@var{a}, @var{b}) ## Compute mean and variance of the gamma distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{a} is the first parameter of the gamma distribution. @var{a} must be ## positive ## ## @item ## @var{b} is the second parameter of the gamma distribution. @var{b} must be ## positive ## @end itemize ## @var{a} and @var{b} must be of common size or one of them must be scalar ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the gamma distribution ## ## @item ## @var{v} is the variance of the gamma distribution ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## a = 1:6; ## b = 1:0.2:2; ## [m, v] = gamstat (a, b) ## @end group ## ## @group ## [m, v] = gamstat (a, 1.5) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the gamma distribution function [m, v] = gamstat (a, b) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (a) && ! ismatrix (a)) error ("gamstat: a must be a numeric matrix"); endif if (! isempty (b) && ! ismatrix (b)) error ("gamstat: b must be a numeric matrix"); endif if (! isscalar (a) || ! isscalar (b)) [retval, a, b] = common_size (a, b); if (retval > 0) error ("gamstat: a and b must be of common size or scalar"); endif endif # Calculate moments m = a .* b; v = a .* (b .^ 2); # Continue argument check k = find (! (a > 0) | ! (a < Inf) | ! (b > 0) | ! (b < Inf)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!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 (m, expected_m, 0.001); %! assert (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 (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/stepwisefit.m0000644000000000000000000000006213443447555017205 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/stepwisefit.m0000644000175000017500000001127213443447555017717 0ustar00johndjohnd00000000000000## Copyright (C) 2013-2014 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{X_use}, @var{b}, @var{bint}, @var{r}, @var{rint}, @var{stats} =} stepwisefit (@var{y}, @var{X}, @var{penter} = 0.05, @var{premove} = 0.1) ## Linear regression with stepwise variable selection. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{y} is an @var{n} by 1 vector of data to fit. ## @item ## @var{X} is an @var{n} by @var{k} matrix containing the values of @var{k} potential predictors. No constant term should be included (one will always be added to the regression automatically). ## @item ## @var{penter} is the maximum p-value to enter a new variable into the regression (default: 0.05). ## @item ## @var{premove} is the minimum p-value to remove a variable from the regression (default: 0.1). ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{X_use} contains the indices of the predictors included in the final regression model. The predictors are listed in the order they were added, so typically the first ones listed are the most significant. ## @item ## @var{b}, @var{bint}, @var{r}, @var{rint}, @var{stats} are the results of @code{[b, bint, r, rint, stats] = regress(y, [ones(size(y)) X(:, X_use)], penter);} ## @end itemize ## @subheading References ## ## @enumerate ## @item ## N. R. Draper and H. Smith (1966). @cite{Applied Regression Analysis}. Wiley. Chapter 6. ## ## @end enumerate ## @seealso{regress} ## @end deftypefn ## Author: Nir Krakauer ## Description: Linear regression with stepwise variable selection function [X_use, b, bint, r, rint, stats] = stepwisefit(y, X, penter = 0.05, premove = 0.1) #remove any rows with missing entries notnans = !any (isnan ([y X]) , 2); y = y(notnans); X = X(notnans,:); n = numel(y); #number of data points k = size(X, 2); #number of predictors X_use = []; v = 0; #number of predictor variables in regression model iter = 0; max_iters = 100; #maximum number of interations to do r = y; while 1 iter++; #decide which variable to add to regression, if any added = false; if numel(X_use) < k X_inds = zeros(k, 1, "logical"); X_inds(X_use) = 1; [~, i_max_corr] = max(abs(corr(X(:, ~X_inds), r))); #try adding the variable with the highest correlation to the residual from current regression i_max_corr = (1:k)(~X_inds)(i_max_corr); #index within the original predictor set [b_new, bint_new, r_new, rint_new, stats_new] = regress(y, [ones(n, 1) X(:, [X_use i_max_corr])], penter); z_new = abs(b_new(end)) / (bint_new(end, 2) - b_new(end)); if z_new > 1 #accept new variable added = true; X_use = [X_use i_max_corr]; b = b_new; bint = bint_new; r = r_new; rint = rint_new; stats = stats_new; v = v + 1; endif endif #decide which variable to drop from regression, if any dropped = false; if v > 0 t_ratio = tinv(1 - premove/2, n - v - 1) / tinv(1 - penter/2, n - v - 1); #estimate the ratio between the z score corresponding to premove to that corresponding to penter [z_min, i_min] = min(abs(b(2:end)) ./ (bint(2:end, 2) - b(2:end))); if z_min < t_ratio #drop a variable dropped = true; X_use(i_min) = []; [b, bint, r, rint, stats] = regress(y, [ones(n, 1) X(:, X_use)], penter); v = v - 1; endif endif #terminate if no change in the list of regression variables if ~added && ~dropped break endif if iter >= max_iters warning('stepwisefit: maximum iteration count exceeded before convergence') break endif endwhile endfunction %!test %! % Sample data from Draper and Smith (n = 13, k = 4) %! X = [7 1 11 11 7 11 3 1 2 21 1 11 10; ... %! 26 29 56 31 52 55 71 31 54 47 40 66 68; ... %! 6 15 8 8 6 9 17 22 18 4 23 9 8; ... %! 60 52 20 47 33 22 6 44 22 26 34 12 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]'; %! [X_use, b, bint, r, rint, stats] = stepwisefit(y, X); %! assert(X_use, [4 1]) %! assert(b, regress(y, [ones(size(y)) X(:, X_use)], 0.05)) statistics-1.4.1/inst/PaxHeaders.29769/gevstat.m0000644000000000000000000000006213443447555016314 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gevstat.m0000644000175000017500000000570313443447555017030 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} gevstat (@var{k}, @var{sigma}, @var{mu}) ## Compute the mean and variance of the generalized extreme value (GEV) distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{k} is the shape parameter of the GEV distribution. (Also denoted gamma or xi.) ## @item ## @var{sigma} is the scale parameter of the GEV distribution. The elements ## of @var{sigma} must be positive. ## @item ## @var{mu} is the location parameter of the GEV distribution. ## @end itemize ## The inputs must be of common size, or some of them must be scalar. ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the GEV distribution ## ## @item ## @var{v} is the variance of the GEV distribution ## @end itemize ## @seealso{gevcdf, gevfit, gevinv, gevlike, gevpdf, gevrnd} ## @end deftypefn ## Author: Nir Krakauer ## Description: Moments of the generalized extreme value distribution function [m, v] = gevstat (k, sigma, mu) # Check arguments if (nargin < 3) print_usage (); endif if (isempty (k) || isempty (sigma) || isempty (mu) || ~ismatrix (k) || ~ismatrix (sigma) || ~ismatrix (mu)) error ("gevstat: inputs must be numeric matrices"); endif [retval, k, sigma, mu] = common_size (k, sigma, mu); if (retval > 0) error ("gevstat: inputs must be of common size or scalars"); endif eg = 0.57721566490153286; %Euler-Mascheroni constant m = v = k; #find the mean m(k >= 1) = Inf; m(k == 0) = mu(k == 0) + eg*sigma(k == 0); m(k < 1 & k ~= 0) = mu(k < 1 & k ~= 0) + sigma(k < 1 & k ~= 0) .* (gamma(1-k(k < 1 & k ~= 0)) - 1) ./ k(k < 1 & k ~= 0); #find the variance v(k >= 0.5) = Inf; v(k == 0) = (pi^2 / 6) * sigma(k == 0) .^ 2; v(k < 0.5 & k ~= 0) = (gamma(1-2*k(k < 0.5 & k ~= 0)) - gamma(1-k(k < 0.5 & k ~= 0)).^2) .* (sigma(k < 0.5 & k ~= 0) ./ k(k < 0.5 & k ~= 0)) .^ 2; endfunction %!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 (m, expected_m, -0.001); %! assert (v, expected_v, -0.001); statistics-1.4.1/inst/PaxHeaders.29769/fstat.m0000644000000000000000000000006213443447555015760 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/fstat.m0000644000175000017500000000672413443447555016500 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{mn}, @var{v}] =} fstat (@var{m}, @var{n}) ## Compute mean and variance of the F distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{m} is the first parameter of the F distribution. The elements ## of @var{m} must be positive ## ## @item ## @var{n} is the second parameter of the F distribution. The ## elements of @var{n} must be positive ## @end itemize ## @var{m} and @var{n} must be of common size or one of them must be scalar ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{mn} is the mean of the F distribution. The mean is undefined for ## @var{n} not greater than 2 ## ## @item ## @var{v} is the variance of the F distribution. The variance is undefined ## for @var{n} not greater than 4 ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## m = 1:6; ## n = 5:10; ## [mn, v] = fstat (m, n) ## @end group ## ## @group ## [mn, v] = fstat (m, 5) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the F distribution function [mn, v] = fstat (m, n) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (m) && ! ismatrix (m)) error ("fstat: m must be a numeric matrix"); endif if (! isempty (n) && ! ismatrix (n)) error ("fstat: n must be a numeric matrix"); endif if (! isscalar (m) || ! isscalar (n)) [retval, m, n] = common_size (m, n); if (retval > 0) error ("fstat: m and n must be of common size or scalar"); endif endif # Calculate moments mn = n ./ (n - 2); v = (2 .* (n .^ 2) .* (m + n - 2)) ./ (m .* ((n - 2) .^ 2) .* (n - 4)); # Continue argument check k = find (! (m > 0) | ! (m < Inf) | ! (n > 2) | ! (n < Inf)); if (any (k)) mn(k) = NaN; v(k) = NaN; endif k = find (! (n > 4)); if (any (k)) v(k) = NaN; endif endfunction %!test %! m = 1:6; %! n = 5:10; %! [mn, v] = fstat (m, n); %! 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 (mn, expected_mn, 0.001); %! assert (v, expected_v, 0.001); %!test %! m = 1:6; %! [mn, v] = fstat (m, 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 (mn, expected_mn, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/betastat.m0000644000000000000000000000006213443447555016446 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/betastat.m0000644000175000017500000000710013443447555017153 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} betastat (@var{a}, @var{b}) ## Compute mean and variance of the beta distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{a} is the first parameter of the beta distribution. @var{a} must be ## positive ## ## @item ## @var{b} is the second parameter of the beta distribution. @var{b} must be ## positive ## @end itemize ## @var{a} and @var{b} must be of common size or one of them must be scalar ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the beta distribution ## ## @item ## @var{v} is the variance of the beta distribution ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## a = 1:6; ## b = 1:0.2:2; ## [m, v] = betastat (a, b) ## @end group ## ## @group ## [m, v] = betastat (a, 1.5) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the beta distribution function [m, v] = betastat (a, b) if (nargin != 2) print_usage (); elseif (! isscalar (a) && ! isscalar (b) && ! size_equal (a, b)) error ("betastat: a and b must be of common size or scalar"); endif k = find (! (a > 0 & b > 0)); # Calculate moments a_b = a + b; m = a ./ (a_b); m(k) = NaN; if (nargout > 1) v = (a .* b) ./ ((a_b .^ 2) .* (a_b + 1)); v(k) = NaN; endif endfunction %!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 (m, expected_m, eps*100); %! assert (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 (m, expected_m); %! assert (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 (m, expected_m); %! assert (v, expected_v); %!assert (nthargout (1:2, @betastat, 5, []), {[], []}) %!assert (nthargout (1:2, @betastat, [], 5), {[], []}) %!assert (nthargout (1:2, @betastat, "", 5), {[], []}) %!assert (nthargout (1:2, @betastat, true, 5), {1/6, 5/252}) %!assert (size (betastat (rand (10, 5, 4), rand (10, 5, 4))), [10 5 4]) %!assert (size (betastat (rand (10, 5, 4), 7)), [10 5 4]) statistics-1.4.1/inst/PaxHeaders.29769/gevrnd.m0000644000000000000000000000006213443447555016124 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gevrnd.m0000644000175000017500000001021513443447555016632 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {} gevrnd (@var{k}, @var{sigma}, @var{mu}) ## @deftypefnx {Function File} {} gevrnd (@var{k}, @var{sigma}, @var{mu}, @var{r}) ## @deftypefnx {Function File} {} gevrnd (@var{k}, @var{sigma}, @var{mu}, @var{r}, @var{c}, @dots{}) ## @deftypefnx {Function File} {} gevrnd (@var{k}, @var{sigma}, @var{mu}, [@var{sz}]) ## Return a matrix of random samples from the generalized extreme value (GEV) distribution with parameters ## @var{k}, @var{sigma}, @var{mu}. ## ## When called with a single size argument, returns a square matrix with ## the dimension specified. When called with more than one scalar argument the ## first two arguments are taken as the number of rows and columns and any ## further arguments specify additional matrix dimensions. The size may also ## be specified with a vector @var{sz} of dimensions. ## ## If no size arguments are given, then the result matrix is the common size of ## the input parameters. ## @seealso{gevcdf, gevfit, gevinv, gevlike, gevpdf, gevstat} ## @end deftypefn ## Author: Nir Krakauer ## Description: Random deviates from the generalized extreme value distribution function rnd = gevrnd (k, sigma, mu, varargin) if (nargin < 3) print_usage (); endif if any (sigma <= 0) error ("gevrnd: sigma must be positive"); endif if (!isscalar (k) || !isscalar (sigma) || !isscalar (mu)) [retval, k, sigma, mu] = common_size (k, sigma, mu); if (retval > 0) error ("gevrnd: k, sigma, mu must be of common size or scalars"); endif endif if (iscomplex (k) || iscomplex (sigma) || iscomplex (mu)) error ("gevrnd: k, sigma, mu must not be complex"); endif if (nargin == 3) sz = size (k); elseif (nargin == 4) if (isscalar (varargin{1}) && varargin{1} >= 0) sz = [varargin{1}, varargin{1}]; elseif (isrow (varargin{1}) && all (varargin{1} >= 0)) sz = varargin{1}; else error ("gevrnd: dimension vector must be row vector of non-negative integers"); endif elseif (nargin > 4) if (any (cellfun (@(x) (!isscalar (x) || x < 0), varargin))) error ("gevrnd: dimensions must be non-negative integers"); endif sz = [varargin{:}]; endif if (!isscalar (k) && !isequal (size (k), sz)) error ("gevrnd: k, sigma, mu must be scalar or of size SZ"); endif if (isa (k, "single") || isa (sigma, "single") || isa (mu, "single")) cls = "single"; else cls = "double"; endif rnd = gevinv (rand(sz), k, sigma, mu); if (strcmp (cls, "single")) rnd = single (rnd); endif endfunction %!assert(size (gevrnd (1,2,1)), [1, 1]); %!assert(size (gevrnd (ones(2,1), 2, 1)), [2, 1]); %!assert(size (gevrnd (ones(2,2), 2, 1)), [2, 2]); %!assert(size (gevrnd (1, 2*ones(2,1), 1)), [2, 1]); %!assert(size (gevrnd (1, 2*ones(2,2), 1)), [2, 2]); %!assert(size (gevrnd (1, 2, 1, 3)), [3, 3]); %!assert(size (gevrnd (1, 2, 1, [4 1])), [4, 1]); %!assert(size (gevrnd (1, 2, 1, 4, 1)), [4, 1]); %% Test input validation %!error gevrnd () %!error gevrnd (1, 2) %!error gevrnd (ones(3),ones(2),1) %!error gevrnd (ones(2),ones(3),1) %!error gevrnd (i, 2, 1) %!error gevrnd (2, i, 1) %!error gevrnd (2, 0, 1) %!error gevrnd (1,2, 1, -1) %!error gevrnd (1,2, 1, ones(2)) %!error gevrnd (1,2, 1, [2 -1 2]) %!error gevrnd (1,2, 1, 1, ones(2)) %!error gevrnd (1,2, 1, 1, -1) %!error gevrnd (ones(2,2), 2, 1, 3) %!error gevrnd (ones(2,2), 2, 1, [3, 2]) %!error gevrnd (ones(2,2), 2, 1, 2, 3) statistics-1.4.1/inst/PaxHeaders.29769/bbspdf.m0000644000000000000000000000006213443447555016077 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/bbspdf.m0000644000175000017500000001003213443447555016602 0ustar00johndjohnd00000000000000## Copyright (C) 2018 John Donoghue ## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} bbspdf (@var{x}, @var{shape}, @var{scale}, @var{location}) ## For each element of @var{x}, compute the probability density function (PDF) ## at @var{x} of the Birnbaum-Saunders distribution with parameters ## @var{location}, @var{scale} and @var{shape}. ## @end deftypefn ## Author: Dag Lyberg ## Description: PDF of the Birnbaum-Saunders distribution function pdf = bbspdf (x, shape, scale, location) if (nargin != 4) print_usage (); endif if (! isscalar (location) || ! isscalar (scale) || ! isscalar(shape)) [retval, x, location, scale, shape] = ... common_size (x, location, scale, shape); if (retval > 0) error ("bbspdf: X, LOCATION, SCALE and SHAPE must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (location) ... || iscomplex (scale) || iscomplex(shape)) error ("bbspdf: X, LOCATION, SCALE and SHAPE must not be complex"); endif if (isa (x, "single") || isa (location, "single") || isa (scale, "single") ... || isa (shape, "single")) pdf = zeros (size (x), "single"); else pdf = zeros (size (x)); endif k = isnan (x) | ! (-Inf < location) | ! (location < Inf) ... | ! (scale > 0) | ! (scale < Inf) ... | ! (shape > 0) | ! (shape < Inf); pdf(k) = NaN; k = (x > location) & (x < Inf) & (-Inf < location) ... & (location < Inf) & (0 < scale) & (scale < Inf) ... & (0 < shape) & (shape < Inf); if (isscalar (location) && isscalar(scale) && isscalar(shape)) a = x(k) - location; b = sqrt(a ./ scale); pdf(k) = ((b + b.^-1) ./ (2 * shape * a)) ... .* normpdf ((b - b.^-1) / shape); else a = x(k) - location(k); b = sqrt(a ./ scale(k)); pdf(k) = ((b + b.^-1) ./ (2 * shape(k).* a)) ... .* normpdf ((b - b.^-1) ./ shape(k)); endif endfunction %!shared x,y %! x = [-1, 0, 1, 2, Inf]; %! y = [0, 0, 0.3989422804014327, 0.1647717335503959, 0]; %!assert (bbspdf (x, ones (1,5), ones (1,5), zeros (1,5)), y, eps) %!assert (bbspdf (x, 1, 1, zeros (1,5)), y, eps) %!assert (bbspdf (x, 1, ones (1,5), 0), y, eps) %!assert (bbspdf (x, ones (1,5), 1, 0), y, eps) %!assert (bbspdf (x, 1, 1, 0), y, eps) %!assert (bbspdf (x, 1, 1, [0, 0, NaN, 0, 0]), [y(1:2), NaN, y(4:5)], eps) %!assert (bbspdf (x, 1, [1, 1, NaN, 1, 1], 0), [y(1:2), NaN, y(4:5)], eps) %!assert (bbspdf (x, [1, 1, NaN, 1, 1], 1, 0), [y(1:2), NaN, y(4:5)], eps) %!assert (bbspdf ([x, NaN], 1, 1, 0), [y, NaN], eps) ## Test class of input preserved %!assert (bbspdf (single ([x, NaN]), 1, 1, 0), single ([y, NaN]), eps('single')) %!assert (bbspdf ([x, NaN], 1, 1, single (0)), single ([y, NaN]), eps('single')) %!assert (bbspdf ([x, NaN], 1, single (1), 0), single ([y, NaN]), eps('single')) %!assert (bbspdf ([x, NaN], single (1), 1, 0), single ([y, NaN]), eps('single')) ## Test input validation %!error bbspdf () %!error bbspdf (1) %!error bbspdf (1,2,3) %!error bbspdf (1,2,3,4,5) %!error bbspdf (ones (3), ones (2), ones(2), ones(2)) %!error bbspdf (ones (2), ones (3), ones(2), ones(2)) %!error bbspdf (ones (2), ones (2), ones(3), ones(2)) %!error bbspdf (ones (2), ones (2), ones(2), ones(3)) %!error bbspdf (i, 4, 3, 2) %!error bbspdf (1, i, 3, 2) %!error bbspdf (1, 4, i, 2) %!error bbspdf (1, 4, 3, i) statistics-1.4.1/inst/PaxHeaders.29769/vmpdf.m0000644000000000000000000000006213443447555015753 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/vmpdf.m0000644000175000017500000000303713443447555016465 0ustar00johndjohnd00000000000000## Copyright (C) 2009 Soren Hauberg ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} @var{theta} = vmpdf (@var{x}, @var{mu}, @var{k}) ## Evaluates the Von Mises probability density function. ## ## The Von Mises distribution has probability density function ## @example ## f (@var{x}) = exp (@var{k} * cos (@var{x} - @var{mu})) / @var{Z} , ## @end example ## where @var{Z} is a normalisation constant. By default, @var{mu} is 0 and ## @var{k} is 1. ## @seealso{vmrnd} ## @end deftypefn function p = vmpdf (x, mu = 0, k = 1) ## Check input if (!isreal (x)) error ("vmpdf: first input must be real"); endif if (!isreal (mu)) error ("vmpdf: second input must be a scalar"); endif if (!isreal (k) || k <= 0) error ("vmpdf: third input must be a real positive scalar"); endif ## Evaluate PDF Z = 2 * pi * besseli (0, k); p = exp (k * cos (x-mu)) / Z; endfunction statistics-1.4.1/inst/PaxHeaders.29769/wblstat.m0000644000000000000000000000006213443447555016317 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/wblstat.m0000644000175000017500000000667713443447555017046 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} wblstat (@var{scale}, @var{shape}) ## Compute mean and variance of the Weibull distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{scale} is the scale parameter of the Weibull distribution. ## @var{scale} must be positive ## ## @item ## @var{shape} is the shape parameter of the Weibull distribution. ## @var{shape} must be positive ## @end itemize ## @var{scale} and @var{shape} must be of common size or one of them must be ## scalar ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the Weibull distribution ## ## @item ## @var{v} is the variance of the Weibull distribution ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## scale = 3:8; ## shape = 1:6; ## [m, v] = wblstat (scale, shape) ## @end group ## ## @group ## [m, v] = wblstat (6, shape) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the Weibull distribution function [m, v] = wblstat (scale, shape) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (scale) && ! ismatrix (scale)) error ("wblstat: scale must be a numeric matrix"); endif if (! isempty (shape) && ! ismatrix (shape)) error ("wblstat: shape must be a numeric matrix"); endif if (! isscalar (scale) || ! isscalar (shape)) [retval, scale, shape] = common_size (scale, shape); if (retval > 0) error ("wblstat: scale and shape must be of common size or scalar"); endif endif # Calculate moments m = scale .* gamma (1 + 1 ./ shape); v = (scale .^ 2) .* gamma (1 + 2 ./ shape) - m .^ 2; # Continue argument check k = find (! (scale > 0) | ! (scale < Inf) | ! (shape > 0) | ! (shape < Inf)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!test %! scale = 3:8; %! shape = 1:6; %! [m, v] = wblstat (scale, shape); %! 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 (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); %!test %! shape = 1:6; %! [m, v] = wblstat (6, shape); %! 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 (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/bbscdf.m0000644000000000000000000000006213443447555016062 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/bbscdf.m0000644000175000017500000000762713443447555016605 0ustar00johndjohnd00000000000000## Copyright (C) 2018 John Donoghue ## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} bbscdf (@var{x}, @var{shape}, @var{scale}, @var{location}) ## For each element of @var{x}, compute the cumulative distribution function ## (CDF) at @var{x} of the Birnbaum-Saunders distribution with parameters ## @var{location}, @var{scale} and @var{shape}. ## @end deftypefn ## Author: Dag Lyberg ## Description: CDF of the Birnbaum-Saunders distribution function cdf = bbscdf (x, shape, scale, location) if (nargin != 4) print_usage (); endif if (! isscalar (location) || ! isscalar (scale) || ! isscalar(shape)) [retval, x, location, scale, shape] = ... common_size (x, location, scale, shape); if (retval > 0) error ("bbscdf: X, LOCATION, SCALE and SHAPE must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (location) || iscomplex (scale) ... || iscomplex(shape)) error ("bbscdf: X, LOCATION, SCALE and SHAPE must not be complex"); endif if (isa (x, "single") || isa (location, "single") || isa (scale, "single") ... || isa (shape, "single")) cdf = zeros (size (x), "single"); else cdf = zeros (size (x)); endif k = isnan(x) | ! (-Inf < location) | ! (location < Inf) ... | ! (scale > 0) | ! (scale < Inf) | ! (shape > 0) | ! (shape < Inf); cdf(k) = NaN; k = (x > location) & (x <= Inf) & (-Inf < location) & (location < Inf) ... & (0 < scale) & (scale < Inf) & (0 < shape) & (shape < Inf); if (isscalar (location) && isscalar(scale) && isscalar(shape)) a = x(k) - location; b = sqrt(a ./ scale); cdf(k) = normcdf ((b - b.^-1) / shape); else a = x(k) - location(k); b = sqrt(a ./ scale(k)); cdf(k) = normcdf ((b - b.^-1) ./ shape(k)); endif endfunction %!shared x,y %! x = [-1, 0, 1, 2, Inf]; %! y = [0, 0, 1/2, 0.76024993890652337, 1]; %!assert (bbscdf (x, ones (1,5), ones (1,5), zeros (1,5)), y, eps) %!assert (bbscdf (x, 1, 1, zeros (1,5)), y, eps) %!assert (bbscdf (x, 1, ones (1,5), 0), y, eps) %!assert (bbscdf (x, ones (1,5), 1, 0), y, eps) %!assert (bbscdf (x, 1, 1, 0), y, eps) %!assert (bbscdf (x, 1, 1, [0, 0, NaN, 0, 0]), [y(1:2), NaN, y(4:5)], eps) %!assert (bbscdf (x, 1, [1, 1, NaN, 1, 1], 0), [y(1:2), NaN, y(4:5)], eps) %!assert (bbscdf (x, [1, 1, NaN, 1, 1], 1, 0), [y(1:2), NaN, y(4:5)], eps) %!assert (bbscdf ([x, NaN], 1, 1, 0), [y, NaN], eps) ## Test class of input preserved %!assert (bbscdf (single ([x, NaN]), 1, 1, 0), single ([y, NaN]), eps('single')) %!assert (bbscdf ([x, NaN], 1, 1, single (0)), single ([y, NaN]), eps('single')) %!assert (bbscdf ([x, NaN], 1, single (1), 0), single ([y, NaN]), eps('single')) %!assert (bbscdf ([x, NaN], single (1), 1, 0), single ([y, NaN]), eps('single')) ## Test input validation %!error bbscdf () %!error bbscdf (1) %!error bbscdf (1,2,3) %!error bbscdf (1,2,3,4,5) %!error bbscdf (ones (3), ones (2), ones(2), ones(2)) %!error bbscdf (ones (2), ones (3), ones(2), ones(2)) %!error bbscdf (ones (2), ones (2), ones(3), ones(2)) %!error bbscdf (ones (2), ones (2), ones(2), ones(3)) %!error bbscdf (i, 4, 3, 2) %!error bbscdf (1, i, 3, 2) %!error bbscdf (1, 4, i, 2) %!error bbscdf (1, 4, 3, i) statistics-1.4.1/inst/PaxHeaders.29769/binotest.m0000644000000000000000000000006213443447555016466 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/binotest.m0000644000175000017500000001225613443447555017203 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Andreas Stahel ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{h}, @var{pval}, @var{ci}] =} binotest (@var{pos},@var{N},@var{p0}) ## @deftypefnx {Function File} {[@var{h}, @var{pval}, @var{ci}] =} binotest (@var{pos},@var{N},@var{p0},@var{Name},@var{Value}) ## Test for probability @var{p} of a binomial sample ## ## Perform a test of the null hypothesis @var{p} == @var{p0} for a sample ## of size @var{N} with @var{pos} positive results ## ## ## Name-Value pair arguments can be used to set various options. ## @qcode{"alpha"} can be used to specify the significance level ## of the test (the default value is 0.05). The option @qcode{"tail"}, ## can be used to select the desired alternative hypotheses. If the ## value is @qcode{"both"} (default) the null is tested against the two-sided ## alternative @code{@var{p} != @var{p0}}. The value of @var{pval} is ## determined by adding the probabilities of all event less or equally ## likely than the observed number @var{pos} of positive events. ## If the value of @qcode{"tail"} is @qcode{"right"} ## the one-sided alternative @code{@var{p} > @var{p0}} is considered. ## Similarly for @qcode{"left"}, the one-sided alternative ## @code{@var{p} < @var{p0}} is considered. ## ## If @var{h} is 0 the null hypothesis is accepted, if it is 1 the null ## hypothesis is rejected. The p-value of the test is returned in @var{pval}. ## A 100(1-alpha)% confidence interval is returned in @var{ci}. ## ## @end deftypefn ## Author: Andreas Stahel function [h, p, ci] = binotest(pos,n,p0,varargin) % Set default arguments alpha = 0.05; tail = 'both'; i = 1; while ( i <= length(varargin) ) switch lower(varargin{i}) case 'alpha' i = i + 1; alpha = varargin{i}; case 'tail' i = i + 1; tail = varargin{i}; otherwise error('Invalid Name argument.',[]); end i = i + 1; end if ~isa(tail,'char') error('tail argument to vartest must be a string\n',[]); end if (n<=0) error('binotest: required n>0\n',[]); end if (p0<0)|(p0>1) error('binotest: required 0<= p0 <= 1\n',[]); end if (pos<0)|(pos>n) error('binotest: required 0<= pos <= n\n',[]); end % Based on the "tail" argument determine the P-value, the critical values, % and the confidence interval. switch lower(tail) case 'both' A_low = binoinv(alpha/2,n,p0)/n; A_high = binoinv(1-alpha/2,n,p0)/n; p_pos = binopdf(pos,n,p0); p_all = binopdf([0:n],n,p0); ind = find(p_all <=p_pos); % p = min(1,sum(p_all(ind))); p = sum(p_all(ind)); if pos==0 p_low = 0; else p_low = fzero(@(pl)1-binocdf(pos-1,n,pl)-alpha/2,[0 1]); endif if pos==n p_high = 1; else p_high = fzero(@(ph) binocdf(pos,n,ph) -alpha/2,[0,1]); endif ci = [p_low,p_high]; case 'left' p = 1-binocdf(pos-1,n,p0); if pos==n p_high = 1; else p_high = fzero(@(ph) binocdf(pos,n,ph) -alpha,[0,1]); endif ci = [0, p_high]; case 'right' p = binocdf(pos,n,p0); if pos==0 p_low = 0; else p_low = fzero(@(pl)1-binocdf(pos-1,n,pl)-alpha,[0 1]); endif ci = [p_low 1]; otherwise error('Invalid fifth (tail) argument to binotest\n',[]); end % Determine the test outcome % MATLAB returns this a double instead of a logical array h = double(p < alpha); end %!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 %! % Hypothesis: coin shows less than 50% heads, i.e. p<=1/2 %! [h,p_val,ci] = binotest(65,100,0.5,'tail','left','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 <= p <= 0.76 with 99% confidence %!test #example from https://en.wikipedia.org/wiki/Binomial_test %! [h,p_val,ci] = binotest (51,235,1/6); %! assert (p_val, 0.0437, 0.00005) %! [h,p_val,ci] = binotest (51,235,1/6,'tail','left'); %! assert (p_val, 0.027, 0.0005) statistics-1.4.1/inst/PaxHeaders.29769/gevfit_lmom.m0000644000000000000000000000006213443447555017147 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gevfit_lmom.m0000644000175000017500000000677313443447555017673 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{paramhat}, @var{paramci} =} gevfit_lmom (@var{data}) ## Find an estimator (@var{paramhat}) of the generalized extreme value (GEV) distribution fitting @var{data} using the method of L-moments. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{data} is the vector of given values. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{parmhat} is the 3-parameter maximum-likelihood parameter vector [@var{k}; @var{sigma}; @var{mu}], where @var{k} is the shape parameter of the GEV distribution, @var{sigma} is the scale parameter of the GEV distribution, and @var{mu} is the location parameter of the GEV distribution. ## @item ## @var{paramci} has the approximate 95% confidence intervals of the parameter values (currently not implemented). ## ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## data = gevrnd (0.1, 1, 0, 100, 1); ## [pfit, pci] = gevfit_lmom (data); ## p1 = gevcdf (data,pfit(1),pfit(2),pfit(3)); ## [f, x] = ecdf (data); ## plot(data, p1, 's', x, f) ## @end group ## @end example ## @seealso{gevfit} ## @subheading References ## ## @enumerate ## @item ## Ailliot, P.; Thompson, C. & Thomson, P. Mixed methods for fitting the GEV distribution, Water Resources Research, 2011, 47, W05551 ## ## @end enumerate ## @end deftypefn ## Author: Nir Krakauer ## Description: L-moments parameter estimation for the generalized extreme value distribution function [paramhat, paramci] = gevfit_lmom (data) # Check arguments if (nargin < 1) print_usage; endif # find the L-moments data = sort (data(:))'; n = numel(data); L1 = mean(data); L2 = sum(data .* (2*(1:n) - n - 1)) / (2*nchoosek(n, 2)); # or mean(triu(data' - data, 1, 'pack')) / 2; b = bincoeff((1:n) - 1, 2); L3 = sum(data .* (b - 2 * ((1:n) - 1) .* (n - (1:n)) + fliplr(b))) / (3*nchoosek(n, 3)); #match the moments to the GEV distribution #first find k based on L3/L2 f = @(k) (L3/L2 + 3)/2 - limdiv((1 - 3^(k)), (1 - 2^(k))); k = fzero(f, 0); #next find sigma and mu given k if abs(k) < 1E-8 sigma = L2 / log(2); eg = 0.57721566490153286; %Euler-Mascheroni constant mu = L1 - sigma * eg; else sigma = -k*L2 / (gamma(1 - k) * (1 - 2^(k))); mu = L1 - sigma * ((gamma(1 - k) - 1) / k); endif paramhat = [k; sigma; mu]; if nargout > 1 paramci = NaN; endif endfunction #internal function to accurately evaluate (1 - 3^k)/(1 - 2^k) in the limit as k --> 0 function c = limdiv(a, b) # c = ifelse (abs(b) < 1E-8, log(3)/log(2), a ./ b); if abs(b) < 1E-8 c = log(3)/log(2); else c = a / b; endif endfunction %!xtest <31070> %! data = 1:50; %! [pfit, pci] = gevfit_lmom (data); %! expected_p = [-0.28 15.01 20.22]'; %! assert (pfit, expected_p, 0.1); statistics-1.4.1/inst/PaxHeaders.29769/gevfit.m0000644000000000000000000000006213443447555016123 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gevfit.m0000644000175000017500000000654213443447555016641 0ustar00johndjohnd00000000000000## Copyright (C) 2012-2016 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{paramhat}, @var{paramci} =} gevfit (@var{data}, @var{parmguess}) ## Find the maximum likelihood estimator (@var{paramhat}) of the generalized extreme value (GEV) distribution to fit @var{data}. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{data} is the vector of given values. ## @item ## @var{parmguess} is an initial guess for the maximum likelihood parameter vector. If not given, this defaults to @var{k}=0 and @var{sigma}, @var{mu} determined by matching the data mean and standard deviation to their expected values. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{parmhat} is the 3-parameter maximum-likelihood parameter vector [@var{k}; @var{sigma}; @var{mu}], where @var{k} is the shape parameter of the GEV distribution, @var{sigma} is the scale parameter of the GEV distribution, and @var{mu} is the location parameter of the GEV distribution. ## @item ## @var{paramci} has the approximate 95% confidence intervals of the parameter values based on the Fisher information matrix at the maximum-likelihood position. ## ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## data = 1:50; ## [pfit, pci] = gevfit (data); ## p1 = gevcdf(data,pfit(1),pfit(2),pfit(3)); ## plot(data, p1) ## @end group ## @end example ## @seealso{gevcdf, gevinv, gevlike, gevpdf, gevrnd, gevstat} ## @end deftypefn ## Author: Nir Krakauer ## Description: Maximum likelihood parameter estimation for the generalized extreme value distribution function [paramhat, paramci] = gevfit (data, paramguess) # Check arguments if (nargin < 1) print_usage; endif if (nargin < 2) || isempty(paramguess) paramguess = zeros (3, 1); paramguess(2) = (sqrt(6)/pi) * std (data); paramguess(3) = mean(data) - 0.5772156649*paramguess(2); #expectation involves Euler–Mascheroni constant endif #cost function to minimize f = @(p) gevlike (p, data); paramhat = fminunc(f, paramguess, optimset("GradObj", "on")); if nargout > 1 [nlogL, ~, ACOV] = gevlike (paramhat, data); param_se = sqrt(diag(inv(ACOV))); if any(iscomplex(param_se)) warning ('gevfit: Fisher information matrix not positive definite; parameter optimization likely did not converge') paramci = nan (3, 2); else paramci(:, 1) = paramhat - 1.96*param_se; paramci(:, 2) = paramhat + 1.96*param_se; endif endif endfunction %!test %! data = 1:50; %! [pfit, pci] = gevfit (data); %! expected_p = [-0.44 15.19 21.53]'; %! expected_pu = [-0.13 19.31 26.49]'; %! assert (pfit, expected_p, 0.1); %! assert (pci(:, 2), expected_pu, 0.1); statistics-1.4.1/inst/PaxHeaders.29769/runstest.m0000644000000000000000000000006213443447555016526 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/runstest.m0000644000175000017500000001243113443447555017236 0ustar00johndjohnd00000000000000## Copyright (C) 2013 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{h}, @var{p}, @var{stats} =} runstest (@var{x}, @var{v}) ## Runs test for detecting serial correlation in the vector @var{x}. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} is the vector of given values. ## @item ## @var{v} is the value to subtract from @var{x} to get runs (defaults to @code{median(x)}) ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{h} is true if serial correlation is detected at the 95% confidence level (two-tailed), false otherwise. ## @item ## @var{p} is the probablity of obtaining a test statistic of the magnitude found under the null hypothesis of no serial correlation. ## @item ## @var{stats} is the structure containing as fields the number of runs @var{nruns}; the numbers of positive and negative values of @code{x - v}, @var{n1} and @var{n0}; and the test statistic @var{z}. ## ## @end itemize ## ## Note: the large-sample normal approximation is used to find @var{h} and @var{p}. This is accurate if @var{n1}, @var{n0} are both greater than 10. ## ## Reference: ## NIST Engineering Statistics Handbook, 1.3.5.13. Runs Test for Detecting Non-randomness, http://www.itl.nist.gov/div898/handbook/eda/section3/eda35d.htm ## ## @seealso{} ## @end deftypefn ## Author: Nir Krakauer ## Description: Runs test for detecting serial correlation function [h, p, stats] = runstest (x, x2) # Check arguments if (nargin < 1) print_usage; endif if nargin > 1 && isnumeric(x2) v = x2; else v = median(x); endif x = x(~isnan(x)); #delete missing values x = sign(x - v); x = x(x ~= 0); #delete any zeros R = sum((x(1:(end-1)) .* x(2:end)) < 0) + 1; #number of runs #expected number of runs for an iid sequence n1 = sum(x > 0); n2 = sum(x < 0); R_bar = 1 + 2*n1*n2/(n1 + n2); #standard deviation of number of runs for an iid sequence s_R = sqrt(2*n1*n2*(2*n1*n2 - n1 - n2)/((n1 + n2)^2 * (n1 + n2 - 1))); #desired significance level alpha = 0.05; Z = (R - R_bar) / s_R; #test statistic p = 2 * normcdf(-abs(Z)); h = p < alpha; if nargout > 2 stats.nruns = R; stats.n1 = n1; stats.n0 = n2; stats.z = Z; endif endfunction %!test %! 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]; #NIST beam deflection data, http://www.itl.nist.gov/div898/handbook/eda/section4/eda425.htm %! [h, p, stats] = runstest (data); %! expected_h = true; %! expected_p = 0.0070646; %! expected_z = 2.6938; %! assert (h, expected_h); %! assert (p, expected_p, 1E-6); %! assert (stats.z, expected_z, 1E-4); statistics-1.4.1/inst/PaxHeaders.29769/canoncorr.m0000644000000000000000000000006213443447555016623 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/canoncorr.m0000644000175000017500000000645513443447555017344 0ustar00johndjohnd00000000000000function [A,B,r,U,V,stats] = canoncorr (X,Y) ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{A} @var{B} @var{r} @var{U} @var{V}] =} canoncorr (@var{X}, @var{Y}) ## Canonical correlation analysis ## ## Given @var{X} (size @var{k}*@var{m}) and @var{Y} (@var{k}*@var{n}), returns projection matrices of canonical coefficients @var{A} (size @var{m}*@var{d}, where @var{d}=@code{min}(@var{m}, @var{n})) and @var{B} (size @var{m}*@var{d}); the canonical correlations @var{r} (1*@var{d}, arranged in decreasing order); the canonical variables @var{U}, @var{V} (both @var{k}*@var{d}, with orthonormal columns); and @var{stats}, a structure containing results from Bartlett's chi-square and Rao's F tests of significance. ## ## References: @* ## William H. Press (2011), Canonical Correlation Clarified by Singular Value Decomposition, http://numerical.recipes/whp/notes/CanonCorrBySVD.pdf @* ## Philip B. Ender, Multivariate Analysis: Canonical Correlation Analysis, http://www.philender.com/courses/multivariate/notes2/can1.html ## ## @seealso{princomp} ## @end deftypefn # Copyright (C) 2016 by Nir Krakauer # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; If not, see . k = size (X, 1); #should also be size (Y, 1) m = size (X, 2); n = size (Y, 2); d = min (m, n); X = center (X); Y = center (Y); [Qx Rx] = qr (X, 0); [Qy Ry] = qr (Y, 0); [U S V] = svd (Qx' * Qy, 0); A = Rx \ U(:, 1:d); B = Ry \ V(:, 1:d); #A, B are scaled to make the covariance matrices of the outputs U, V identity matrices f = sqrt (k-1); A .*= f; B .*= f; if isargout(3) || isargout(6) r = max(0, min(diag(S), 1))'; endif if isargout (4) U = X * A; endif if isargout (5) V = Y * B; endif if isargout (6) Wilks = fliplr(cumprod(fliplr((1 - r .^ 2)))); chisq = - (k - 1 - (m + n + 1)/2) * log(Wilks); df1 = (m - (1:d) + 1) .* (n - (1:d) + 1); pChisq = 1 - chi2cdf (chisq, df1); s = sqrt((df1.^2 - 4) ./ ((m - (1:d) + 1).^2 + (n - (1:d) + 1).^2 - 5)); df2 = (k - 1 - (m + n + 1)/2) * s - df1/2 + 1; ls = Wilks .^ (1 ./ s); F = (1 ./ ls - 1) .* (df2 ./ df1); pF = 1 - fcdf (F, df1, df2); stats.Wilks = Wilks; stats.df1 = df1; stats.df2 = df2; stats.F = F; stats.pF = pF; stats.chisq = chisq; stats.pChisq = pChisq; endif %!shared X,Y,A,B,r,U,V,k %! 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); %!assert (A, [-0.329229 0.072908; 0.074870 1.389318; -0.069302 -0.024109], 1E-6); %!assert (B, [-0.017086 -0.398402; -4.475049 -0.824538], 1E-6); %!assert (r, [0.99590 0.26754], 1E-5); %!assert (U, center(X) * A, 10*eps); %!assert (V, center(Y) * B, 10*eps); %!assert (cov(U), eye(size(U, 2)), 10*eps); %!assert (cov(V), eye(size(V, 2)), 10*eps); statistics-1.4.1/inst/PaxHeaders.29769/pdf.m0000644000000000000000000000006213443447555015410 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/pdf.m0000644000175000017500000001005413443447555016117 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Andreas Stahel ## strongly based on cdf.m by 2013 Pantxo Diribarne ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} pdf (@var{name}, @var{X}, @dots{}) ## Return probability density function of @var{name} function for value ## @var{x}. ## This is a wrapper around various @var{name}pdf and @var{name}_pdf ## functions. See the individual functions help to learn the signification of ## the arguments after @var{x}. Supported functions and corresponding number of ## additional arguments are: ## ## @multitable @columnfractions 0.02 0.3 0.45 0.2 ## @headitem @tab function @tab alternative @tab args ## @item @tab "beta" @tab "beta" @tab 2 ## @item @tab "bino" @tab "binomial" @tab 2 ## @item @tab "cauchy" @tab @tab 2 ## @item @tab "chi2" @tab "chisquare" @tab 1 ## @item @tab "discrete" @tab @tab 2 ## @item @tab "exp" @tab "exponential" @tab 1 ## @item @tab "f" @tab @tab 2 ## @item @tab "gam" @tab "gamma" @tab 2 ## @item @tab "geo" @tab "geometric" @tab 1 ## @item @tab "gev" @tab "generalized extreme value" @tab 3 ## @item @tab "hyge" @tab "hypergeometric" @tab 3 ## @item @tab "kolmogorov_smirnov" @tab @tab 1 ## @item @tab "laplace" @tab @tab 2 ## @item @tab "logistic" @tab @tab 0 ## @item @tab "logn" @tab "lognormal" @tab 2 ## @item @tab "norm" @tab "normal" @tab 2 ## @item @tab "poiss" @tab "poisson" @tab 1 ## @item @tab "rayl" @tab "rayleigh" @tab 1 ## @item @tab "t" @tab @tab 1 ## @item @tab "unif" @tab "uniform" @tab 2 ## @item @tab "wbl" @tab "weibull" @tab 2 ## @end multitable ## ## @seealso{betapdf, binopdf, cauchy_pdf, chi2pdf, discrete_pdf, ## exppdf, fpdf, gampdf, geopdf, gevpdf, hygepdf, laplace_pdf, ## logistic_pdf, lognpdf, normpdf, poisspdf, raylpdf, tpdf, ## unifpdf, wblpdf} ## @end deftypefn function [retval] = pdf (varargin) ## implemented functions persistent allpdf = {{"beta", "beta"}, @betapdf, 2, ... {"bino", "binomial"}, @binopdf, 2, ... {"cauchy"}, @cauchy_pdf, 2, ... {"chi2", "chisquare"}, @chi2pdf, 1, ... {"discrete"}, @discrete_pdf, 2, ... {"exp", "exponential"}, @exppdf, 1, ... {"f"}, @fpdf, 2, ... {"gam", "gamma"}, @gampdf, 2, ... {"geo", "geometric"}, @geopdf, 1, ... {"gev", "generalized extreme value"}, @gevpdf, 3, ... {"hyge", "hypergeometric"}, @hygepdf, 3, ... {"laplace"}, @laplace_pdf, 1, ... {"logistic"}, @logistic_pdf, 0, ... # ML has 2 args here {"logn", "lognormal"}, @lognpdf, 2, ... {"norm", "normal"}, @normpdf, 2, ... {"poiss", "poisson"}, @poisspdf, 1, ... {"rayl", "rayleigh"}, @raylpdf, 1, ... {"t"}, @tpdf, 1, ... {"unif", "uniform"}, @unifpdf, 2, ... {"wbl", "weibull"}, @wblpdf, 2}; if (numel (varargin) < 2 || ! ischar (varargin{1})) print_usage (); endif name = varargin{1}; x = varargin{2}; varargin(1:2) = []; nargs = numel (varargin); pdfnames = allpdf(1:3:end); pdfhdl = allpdf(2:3:end); pdfargs = allpdf(3:3:end); idx = cellfun (@(x) any (strcmpi (name, x)), pdfnames); if (any (idx)) if (nargs == pdfargs{idx}) retval = feval (pdfhdl{idx}, x, varargin{:}); else error ("pdf: %s requires %d arguments", name, pdfargs{idx}) endif else error ("pdf: %s not implemented", name); endif endfunction %!test %! assert(pdf ('norm', 1, 0, 1), normpdf (1, 0, 1))statistics-1.4.1/inst/PaxHeaders.29769/signtest.m0000644000000000000000000000006213443447555016477 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/signtest.m0000644000175000017500000001236213443447555017212 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Tony Richardson ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{pval}, @var{h}, @var{stats}] =} signtest (@var{x}) ## @deftypefnx {Function File} {[@var{pval}, @var{h}, @var{stats}] =} signtest (@var{x}, @var{m}) ## @deftypefnx {Function File} {[@var{pval}, @var{h}, @var{stats}] =} signtest (@var{x}, @var{y}) ## @deftypefnx {Function File} {[@var{pval}, @var{h}, @var{stats}] =} signtest (@var{x}, @var{y}, @var{Name}, @var{Value}) ## Test for median. ## ## Perform a signtest of the null hypothesis that @var{x} is from a distribution ## that has a zero median. ## ## If the second argument @var{m} is a scalar, the null hypothesis is that ## X has median m. ## ## If the second argument @var{y} is a vector, the null hypothesis is that ## the distribution of @code{@var{x} - @var{y}} has zero median. ## ## The argument @qcode{"alpha"} can be used to specify the significance level ## of the test (the default value is 0.05). The string ## argument @qcode{"tail"}, can be used to select the desired alternative ## hypotheses. If @qcode{"alt"} is @qcode{"both"} (default) the null is ## tested against the two-sided alternative @code{median (@var{x}) != @var{m}}. ## If @qcode{"alt"} is @qcode{"right"} the one-sided ## alternative @code{median (@var{x}) > @var{m}} is considered. ## Similarly for @qcode{"left"}, the one-sided alternative @code{median ## (@var{x}) < @var{m}} is considered. When @qcode{"method"} is @qcode{"exact"} ## the p-value is computed using an exact method (this is the default). When ## @qcode{"method"} is @qcode{"approximate"} a normal approximation is used for the ## test statistic. ## ## The p-value of the test is returned in @var{pval}. If @var{h} is 0 the ## null hypothesis is accepted, if it is 1 the null hypothesis is rejected. ## @var{stats} is a structure containing the value of the test statistic ## (@var{sign}) and the value of the z statistic (@var{zval}) (only computed ## when the 'method' is 'approximate'. ## ## @end deftypefn ## Author: Tony Richardson function [p, h, stats] = signtest(x, my, varargin) my_default = 0; alpha = 0.05; tail = 'both'; method = 'exact'; % Find the first non-singleton dimension of x dim = min(find(size(x)~=1)); if isempty(dim), dim = 1; end if (nargin == 1) my = my_default; end i = 1; while ( i <= length(varargin) ) switch lower(varargin{i}) case 'alpha' i = i + 1; alpha = varargin{i}; case 'tail' i = i + 1; tail = varargin{i}; case 'method' i = i + 1; method = varargin{i}; case 'dim' i = i + 1; dim = varargin{i}; otherwise error('Invalid Name argument.',[]); end i = i + 1; end if ~isa(tail, 'char') error('tail argument to signtest must be a string\n',[]); end if ~isa(method, 'char') error('method argument to signtest must be a string\n',[]); end % Set default values if arguments are present but empty if isempty(my) my = my_default; end % This adjustment allows everything else to remain the % same for both the one-sample t test and paired tests. % If second argument is a vector if ~isscalar(my) x = x - my; my = my_default; end n = size(x, dim); switch lower(method) case 'exact' stats.zval = nan; switch lower(tail) case 'both' w = min(sum(xmy)); pl = binocdf(w, n, 0.5); p = 2*min(pl,1-pl); case 'left' w = sum(xmy); p = 1 - binocdf(w, n, 0.5); otherwise error('Invalid tail argument to signtest\n',[]); end case 'approximate' switch lower(tail) case 'both' npos = sum(x>my); nneg = sum(xmy); nneg = sum(xmy); nneg = sum(xmy); stats.zval = (w - 0.5*n - 0.5*sign(npos-nneg))/sqrt(0.25*n); p = 1-normcdf(stats.zval); otherwise error('Invalid tail argument to signtest\n',[]); end otherwise error('Invalid method argument to signtest\n',[]); end stats.sign = w; h = double(p < alpha); end statistics-1.4.1/inst/PaxHeaders.29769/anderson_darling_cdf.m0000644000000000000000000000006213443447555020764 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/anderson_darling_cdf.m0000644000175000017500000000726613443447555021506 0ustar00johndjohnd00000000000000## Author: Paul Kienzle ## This program is granted to the public domain. ## -*- texinfo -*- ## @deftypefn {Function File} @var{p} = anderson_darling_cdf (@var{A}, @var{n}) ## ## Return the CDF for the given Anderson-Darling coefficient @var{A} ## computed from @var{n} values sampled from a distribution. For a ## vector of random variables @var{x} of length @var{n}, compute the CDF ## of the values from the distribution from which they are drawn. ## You can uses these values to compute @var{A} as follows: ## ## @example ## @var{A} = -@var{n} - sum( (2*i-1) .* (log(@var{x}) + log(1 - @var{x}(@var{n}:-1:1,:))) )/@var{n}; ## @end example ## ## From the value @var{A}, @code{anderson_darling_cdf} returns the probability ## that @var{A} could be returned from a set of samples. ## ## The algorithm given in [1] claims to be an approximation for the ## Anderson-Darling CDF accurate to 6 decimal points. ## ## Demonstrate using: ## ## @example ## n = 300; reps = 10000; ## z = randn(n, reps); ## x = sort ((1 + erf (z/sqrt (2)))/2); ## i = [1:n]' * ones (1, size (x, 2)); ## A = -n - sum ((2*i-1) .* (log (x) + log (1 - x (n:-1:1, :))))/n; ## p = anderson_darling_cdf (A, n); ## hist (100 * p, [1:100] - 0.5); ## @end example ## ## You will see that the histogram is basically flat, which is to ## say that the probabilities returned by the Anderson-Darling CDF ## are distributed uniformly. ## ## You can easily determine the extreme values of @var{p}: ## ## @example ## [junk, idx] = sort (p); ## @end example ## ## The histograms of various @var{p} aren't very informative: ## ## @example ## histfit (z (:, idx (1)), linspace (-3, 3, 15)); ## histfit (z (:, idx (end/2)), linspace (-3, 3, 15)); ## histfit (z (:, idx (end)), linspace (-3, 3, 15)); ## @end example ## ## More telling is the qqplot: ## ## @example ## qqplot (z (:, idx (1))); hold on; plot ([-3, 3], [-3, 3], ';;'); hold off; ## qqplot (z (:, idx (end/2))); hold on; plot ([-3, 3], [-3, 3], ';;'); hold off; ## qqplot (z (:, idx (end))); hold on; plot ([-3, 3], [-3, 3], ';;'); hold off; ## @end example ## ## Try a similarly analysis for @var{z} uniform: ## ## @example ## z = rand (n, reps); x = sort(z); ## @end example ## ## and for @var{z} exponential: ## ## @example ## z = rande (n, reps); x = sort (1 - exp (-z)); ## @end example ## ## [1] Marsaglia, G; Marsaglia JCW; (2004) "Evaluating the Anderson Darling ## distribution", Journal of Statistical Software, 9(2). ## ## @seealso{anderson_darling_test} ## @end deftypefn function y = anderson_darling_cdf(z,n) y = ADinf(z); y += ADerrfix(y,n); end function y = ADinf(z) y = zeros(size(z)); idx = (z < 2); if any(idx(:)) p = [.00168691, -.0116720, .0347962, -.0649821, .247105, 2.00012]; z1 = z(idx); y(idx) = exp(-1.2337141./z1)./sqrt(z1).*polyval(p,z1); end idx = (z >= 2); if any(idx(:)) p = [-.0003146, +.008056, -.082433, +.43424, -2.30695, 1.0776]; y(idx) = exp(-exp(polyval(p,z(idx)))); end end function y = ADerrfix(x,n) if isscalar(n), n = n*ones(size(x)); elseif isscalar(x), x = x*ones(size(n)); end y = zeros(size(x)); c = .01265 + .1757./n; idx = (x >= 0.8); if any(idx(:)) p = [255.7844, -1116.360, 1950.646, -1705.091, 745.2337, -130.2137]; g3 = polyval(p,x(idx)); y(idx) = g3./n(idx); end idx = (x < 0.8 & x > c); if any(idx(:)) p = [1.91864, -8.259, 14.458, -14.6538, 6.54034, -.00022633]; n1 = 1./n(idx); c1 = c(idx); g2 = polyval(p,(x(idx)-c1)./(.8-c1)); y(idx) = (.04213 + .01365*n1).*n1 .* g2; end idx = (x <= c); if any(idx(:)) x1 = x(idx)./c(idx); n1 = 1./n(idx); g1 = sqrt(x1).*(1-x1).*(49*x1-102); y(idx) = ((.0037*n1+.00078).*n1+.00006).*n1 .* g1; end end statistics-1.4.1/inst/PaxHeaders.29769/normplot.m0000644000000000000000000000006213443447555016511 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/normplot.m0000644000175000017500000000435113443447555017223 0ustar00johndjohnd00000000000000## Author: Paul Kienzle ## This program is granted to the public domain. ## -*- texinfo -*- ## @deftypefn {Function File} normplot (@var{X}) ## Produce normal probability plot for each column of @var{X}. ## ## The line joing the 1st and 3rd quantile is drawn on the ## graph. If the underlying distribution is normal, the ## points will cluster around this line. ## ## Note that this function sets the title, xlabel, ylabel, ## axis, grid, tics and hold properties of the graph. These ## need to be cleared before subsequent graphs using 'clf'. ## @end deftypefn function normplot(X) if nargin!=1, print_usage; end if (rows(X) == 1), X=X(:); end # Transform data n = rows(X); if n<2, error("normplot requires a vector"); end q = norminv([1:n]'/(n+1)); Y = sort(X); # Find the line joining the first to the third quartile for each column q1 = ceil(n/4); q3 = n-q1+1; m = (q(q3)-q(q1))./(Y(q3,:)-Y(q1,:)); p = [ m; q(q1)-m.*Y(q1,:) ]; # Plot the lines one at a time. Plot the lines before overlaying the # normals so that the default label is 'line n'. if columns(Y)==1, leg = "+;;"; else leg = "%d+;Column %d;"; endif for i=1:columns(Y) plot(Y(:,i),q,sprintf(leg,i,i)); hold on; # estimate the mean and standard deviation by linear regression # [v,dv] = wpolyfit(q,Y(:,i),1) end # Overlay the estimated normal lines. for i=1:columns(Y) # Use the end points and one point guaranteed to be in the view since # gnuplot skips any lines whose points are all outside the view. pts = [Y(1,i);Y(q1,i);Y(end,i)]; plot(pts, polyval(p(:,i),pts), [num2str(i),";;"]); end hold off; # plot labels title "Normal Probability Plot" ylabel "% Probability" xlabel "Data" # plot grid t = [0.00001;0.0001;0.001;0.01;0.1;0.3;1;2;5;10;25;50; 75;90;95;98;99;99.7;99.9;99.99;99.999;99.9999;99.99999]; set(gca, "ytick", norminv(t/100), "yticklabel", num2str(t)); grid on # Set view range with a bit of space around data miny = min(Y(:)); minq = min(q(1),norminv(0.05)); maxy = max(Y(:)); maxq = max(q(end),norminv(0.95)); yspace = (maxy-miny)*0.05; qspace = (q(end)-q(1))*0.05; axis ([miny-yspace, maxy+yspace, minq-qspace, maxq+qspace]); end statistics-1.4.1/inst/PaxHeaders.29769/pdist2.m0000644000000000000000000000006213443447555016044 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/pdist2.m0000644000175000017500000001264113443447555016557 0ustar00johndjohnd00000000000000## Copyright (C) 2014-2019 Piotr Dollar ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {} pdist2 (@var{x}, @var{y}) ## @deftypefnx {Function File} {} pdist2 (@var{x}, @var{y}, @var{metric}) ## Compute pairwise distance between two sets of vectors. ## ## Let @var{X} be an MxP matrix representing m points in P-dimensional space ## and @var{Y} be an NxP matrix representing another set of points in the same ## space. This function computes the M-by-N distance matrix @var{D} where ## @code{@var{D}(i,j)} is the distance between @code{@var{X}(i,:)} and ## @code{@var{Y}(j,:)}. ## ## The optional argument @var{metric} can be used to select different ## distances: ## ## @table @asis ## @item @qcode{"euclidean"} (default) ## ## @item @qcode{"sqeuclidean"} ## Compute the squared euclidean distance, i.e., the euclidean distance ## before computing square root. This is ideal when the interest is on the ## order of the euclidean distances rather than the actual distance value ## because it performs significantly faster while preserving the order. ## ## @item @qcode{"chisq'"} ## The chi-squared distance between two vectors is defined as: ## @code{d(x, y) = sum ((xi-yi)^2 / (xi+yi)) / 2}. ## The chi-squared distance is useful when comparing histograms. ## ## @item @qcode{"cosine"} ## Distance is defined as the cosine of the angle between two vectors. ## ## @item @qcode{"emd"} ## Earth Mover's Distance (EMD) between positive vectors (histograms). ## Note for 1D, with all histograms having equal weight, there is a simple ## closed form for the calculation of the EMD. The EMD between histograms ## @var{x} and @var{y} is given by @code{sum (abs (cdf (x) - cdf (y)))}, ## where @code{cdf} is the cumulative distribution function (computed ## simply by @code{cumsum}). ## ## @item @qcode{"L1"} ## The L1 distance between two vectors is defined as: @code{sum (abs (x-y))} ## ## @end table ## ## @seealso{pdist} ## @end deftypefn ## Taken from Piotr's Computer Vision Matlab Toolbox Version 2.52, with ## author permission to distribute under GPLv3 function D = pdist2 (X, Y, metric = "euclidean") if (nargin < 2 || nargin > 3) print_usage (); elseif (columns (X) != columns (Y)) error ("pdist2: X and Y must have equal number of columns"); elseif (ndims (X) != 2 || ndims (Y) != 2) error ("pdist2: X and Y must be 2 dimensional matrices"); endif switch (tolower (metric)) case "sqeuclidean", D = distEucSq (X, Y); case "euclidean", D = sqrt (distEucSq (X, Y)); case "l1", D = distL1 (X, Y); case "cosine", D = distCosine (X, Y); case "emd", D = distEmd (X, Y); case "chisq", D = distChiSq (X, Y); otherwise error ("pdist2: unknown distance METRIC %s", metric); endswitch D = max (0, D); endfunction ## TODO we could check the value of p and n first, and choose one ## or the other loop accordingly. ## L1 COMPUTATION WITH LOOP OVER p, FAST FOR SMALL p. ## function D = distL1( X, Y ) ## m = size(X,1); n = size(Y,1); p = size(X,2); ## mOnes = ones(1,m); nOnes = ones(1,n); D = zeros(m,n); ## for i=1:p ## yi = Y(:,i); yi = yi( :, mOnes ); ## xi = X(:,i); xi = xi( :, nOnes ); ## D = D + abs( xi-yi' ); ## end function D = distL1 (X, Y) m = rows (X); n = rows (Y); mOnes = ones (1, m); D = zeros (m, n); for i = 1:n yi = Y(i,:); yi = yi(mOnes,:); D(:,i) = sum (abs (X-yi), 2); endfor endfunction function D = distCosine (X, Y) p = columns (X); X = X ./ repmat (sqrt (sumsq (X, 2)), [1 p]); Y = Y ./ repmat (sqrt (sumsq (Y, 2)), [1 p]); D = 1 - X*Y'; endfunction function D = distEmd (X, Y) Xcdf = cumsum (X,2); Ycdf = cumsum (Y,2); m = rows (X); n = rows (Y); mOnes = ones (1, m); D = zeros (m, n); for i=1:n ycdf = Ycdf(i,:); ycdfRep = ycdf(mOnes,:); D(:,i) = sum (abs (Xcdf - ycdfRep), 2); endfor endfunction function D = distChiSq (X, Y) ## note: supposedly it's possible to implement this without a loop! m = rows (X); n = rows (Y); mOnes = ones (1, m); D = zeros (m, n); for i = 1:n yi = Y(i, :); yiRep = yi(mOnes, :); s = yiRep + X; d = yiRep - X; D(:,i) = sum (d.^2 ./ (s+eps), 2); endfor D = D/2; endfunction function dists = distEucSq (x, y) xx = sumsq (x, 2); yy = sumsq (y, 2)'; dists = max (0, bsxfun (@plus, xx, yy) - 2 * x * (y')); endfunction ## euclidean distance as loop for testing purposes %!function dist = euclidean_distance (x, y) %! [m, p] = size (X); %! [n, p] = size (Y); %! D = zeros (m, n); %! for i = 1:n %! d = X - repmat (Y(i,:), [m 1]); %! D(:,i) = sumsq (d, 2); %! endfor %!endfunction %!test %! x = [1 1 1; 2 2 2; 3 3 3]; %! y = [0 0 0; 1 2 3; 0 2 4; 4 7 1]; %! d = sqrt([ 3 5 11 45 %! 12 2 8 30 %! 27 5 11 21]); %! assert (pdist2 (x, y), d) statistics-1.4.1/inst/PaxHeaders.29769/boxplot.m0000644000000000000000000000006213443447555016326 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/boxplot.m0000644000175000017500000002521413443447555017041 0ustar00johndjohnd00000000000000## Copyright (C) 2002 Alberto Terruzzi ## Copyright (C) 2006 Alberto Pose ## Copyright (C) 2011 Pascal Dupuis ## Copyright (C) 2012 Juan Pablo Carbajal ## Copyright (C) 2016 Pascal Dupuis ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{s} =} boxplot (@var{data}, @var{notched}, @ ## @var{symbol}, @var{vertical}, @var{maxwhisker}, @dots{}) ## @deftypefnx {Function File} {@var{s} =} boxplot (@var{data}, @var{group}) ## @deftypefnx {Function File} {[@dots{} @var{h}]=} boxplot (@dots{}) ## ## Produce a box plot. ## ## The box plot is a graphical display that simultaneously describes several ## important features of a data set, such as center, spread, departure from ## symmetry, and identification of observations that lie unusually far from ## the bulk of the data. ## ## @var{data} is a matrix with one column for each data set, or data is a cell ## vector with one cell for each data set. ## ## @var{notched} = 1 produces a notched-box plot. Notches represent a robust ## estimate of the uncertainty about the median. ## ## @var{notched} = 0 (default) produces a rectangular box plot. ## ## @var{notched} in (0,1) produces a notch of the specified depth. ## notched values outside (0,1) are amusing if not exactly practical. ## ## @var{symbol} sets the symbol for the outlier values, default symbol for ## points that lie outside 3 times the interquartile range is 'o', ## default symbol for points between 1.5 and 3 times the interquartile ## range is '+'. ## ## @var{symbol} = '.' points between 1.5 and 3 times the IQR is marked with ## '.' and points outside 3 times IQR with 'o'. ## ## @var{symbol} = ['x','*'] points between 1.5 and 3 times the IQR is marked with ## 'x' and points outside 3 times IQR with '*'. ## ## @var{vertical} = 0 makes the boxes horizontal, by default @var{vertical} = 1. ## ## @var{maxwhisker} defines the length of the whiskers as a function of the IQR ## (default = 1.5). If @var{maxwhisker} = 0 then @code{boxplot} displays all data ## values outside the box using the plotting symbol for points that lie ## outside 3 times the IQR. ## ## Supplemental arguments are concatenated and passed to plot. ## ## The returned matrix @var{s} has one column for each data set as follows: ## ## @multitable @columnfractions .1 .8 ## @item 1 @tab Minimum ## @item 2 @tab 1st quartile ## @item 3 @tab 2nd quartile (median) ## @item 4 @tab 3rd quartile ## @item 5 @tab Maximum ## @item 6 @tab Lower confidence limit for median ## @item 7 @tab Upper confidence limit for median ## @end multitable ## ## The returned structure @var{h} has handles to the plot elements, allowing ## customization of the visualization using set/get functions. ## ## Example ## ## @example ## title ("Grade 3 heights"); ## axis ([0,3]); ## set(gca (), "xtick", [1 2], "xticklabel", @{"girls", "boys"@}); ## boxplot (@{randn(10,1)*5+140, randn(13,1)*8+135@}); ## @end example ## ## @end deftypefn function [s hs] = boxplot (data, varargin) ## assign parameter defaults if (nargin < 1) print_usage; endif %# default values maxwhisker = 1.5; vertical = 1; symbol = ['+', 'o']; notched = 0; plot_opts = {}; groups = []; %# Optional arguments analysis numarg = nargin - 1; option_args = ['Notch'; 'Symbol'; 'Vertical'; 'Maxwhisker']; indopt = 1; while (numarg) dummy = varargin{indopt++}; if (!ischar (dummy)) %# MatLAB allows passing the second argument as a grouping vector if (length (dummy) > 1) if (2 ~= indopt) error ('Boxplot.m: grouping vector may only be passed as second arg'); endif groups = dummy; else %# old way: positional argument switch indopt case 2 notched = dummy; case 4 vertical = dummy; case 5 maxwhisker = dummy; otherwise error("No positional argument allowed at position %d", --indopt); endswitch endif numarg--; continue; else if (3 == indopt && length (dummy) <= 2) symbol = dummy; numarg--; continue; else tt = strmatch(dummy, option_args); switch (tt) case 1 notched = varargin{indopt}; case 2 symbol = varargin{indopt}; case 3 vertical = varargin{indopt}; case 4 maxwhisker = varargin{indopt}; otherwise %# take two args and append them to plot_opts plot_opts(1, end+1:end+2) = {dummy, varargin{indopt}}; endswitch endif indopt++; numarg -= 2; endif endwhile if (1 == length (symbol)) symbol(2) = symbol(1); endif if (1 == notched) notched = 0.25; endif a = 1-notched; ## figure out how many data sets we have if (isempty (groups)) if (iscell (data)) nc = length (data); else if (isvector (data)) data = data(:); endif nc = columns (data); endif groups = (1:nc); else if (~isvector (data)) error ('Boxplot.m: with the formalism (data, group), both must be vectors'); end nc = unique (groups); dummy = cell (1, length (nc)); for indopt = (1:length (nc)) dummy(indopt) = data(groups == nc(indopt)); end data = dummy; groups = nc(:).'; nc = length (nc); end ## compute statistics ## s will contain ## 1,5 min and max ## 2,3,4 1st, 2nd and 3rd quartile ## 6,7 lower and upper confidence intervals for median s = zeros (7, nc); box = zeros (1, nc); whisker_x = ones (2,1)*[groups, groups]; whisker_y = zeros (2, 2*nc); outliers_x = []; outliers_y = []; outliers2_x = []; outliers2_y = []; for indi = (1:nc) ## Get the next data set from the array or cell array if (iscell (data)) col = data{indi}(:); else col = data(:, indi); endif ## Skip missing data col(isnan (col) | isna (col)) = []; ## Remember the data length nd = length (col); box(indi) = nd; if (nd > 1) ## min,max and quartiles s(1:5, indi) = statistics (col)(1:5); ## confidence interval for the median est = 1.57*(s(4, indi)-s(2, indi))/sqrt (nd); s(6, indi) = max ([s(3, indi)-est, s(2, indi)]); s(7, indi) = min ([s(3, indi)+est, s(4, indi)]); ## whiskers out to the last point within the desired inter-quartile range IQR = maxwhisker*(s(4, indi)-s(2, indi)); whisker_y(:, indi) = [min(col(col >= s(2, indi)-IQR)); s(2, indi)]; whisker_y(:,nc+indi) = [max(col(col <= s(4, indi)+IQR)); s(4, indi)]; ## outliers beyond 1 and 2 inter-quartile ranges outliers = col((col < s(2, indi)-IQR & col >= s(2, indi)-2*IQR) | (col > s(4, indi)+IQR & col <= s(4, indi)+2*IQR)); outliers2 = col(col < s(2, indi)-2*IQR | col > s(4, indi)+2*IQR); outliers_x = [outliers_x; groups(indi)*ones(size(outliers))]; outliers_y = [outliers_y; outliers]; outliers2_x = [outliers2_x; groups(indi)*ones(size(outliers2))]; outliers2_y = [outliers2_y; outliers2]; elseif (1 == nd) ## all statistics collapse to the value of the point s(:, indi) = col; ## single point data sets are plotted as outliers. outliers_x = [outliers_x; groups(indi)]; outliers_y = [outliers_y; col]; else ## no statistics if no points s(:, indi) = NaN; end end ## Note which boxes don't have enough stats chop = find (box <= 1); ## Draw a box around the quartiles, with width proportional to the number of ## items in the box. Draw notches if desired. box *= 0.4/max (box); quartile_x = ones (11,1)*groups + [-a;-1;-1;1;1;a;1;1;-1;-1;-a]*box; quartile_y = s([3,7,4,4,7,3,6,2,2,6,3],:); ## Draw a line through the median median_x = ones (2,1)*groups + [-a;+a]*box; median_y = s([3,3],:); ## Chop all boxes which don't have enough stats quartile_x(:, chop) = []; quartile_y(:, chop) = []; whisker_x(:,[chop, chop+nc]) = []; whisker_y(:,[chop, chop+nc]) = []; median_x(:, chop) = []; median_y(:, chop) = []; ## Add caps to the remaining whiskers cap_x = whisker_x; cap_x(1, :) -= 0.05; cap_x(2, :) += 0.05; cap_y = whisker_y([1, 1], :); #quartile_x,quartile_y #whisker_x,whisker_y #median_x,median_y #cap_x,cap_y ## Do the plot if (vertical) if (isempty (plot_opts)) h = plot (quartile_x, quartile_y, "b;;", whisker_x, whisker_y, "b;;", cap_x, cap_y, "b;;", median_x, median_y, "r;;", outliers_x, outliers_y, [symbol(1), "r;;"], outliers2_x, outliers2_y, [symbol(2), "r;;"]); else h = plot (quartile_x, quartile_y, "b;;", whisker_x, whisker_y, "b;;", cap_x, cap_y, "b;;", median_x, median_y, "r;;", outliers_x, outliers_y, [symbol(1), "r;;"], outliers2_x, outliers2_y, [symbol(2), "r;;"], plot_opts{:}); endif else if (isempty (plot_opts)) h = plot (quartile_y, quartile_x, "b;;", whisker_y, whisker_x, "b;;", cap_y, cap_x, "b;;", median_y, median_x, "r;;", outliers_y, outliers_x, [symbol(1), "r;;"], outliers2_y, outliers2_x, [symbol(2), "r;;"]); else h = plot (quartile_y, quartile_x, "b;;", whisker_y, whisker_x, "b;;", cap_y, cap_x, "b;;", median_y, median_x, "r;;", outliers_y, outliers_x, [symbol(1), "r;;"], outliers2_y, outliers2_x, [symbol(2), "r;;"], plot_opts{:}); endif endif % Distribute handles nq = 1:size(quartile_x,2); hs.box = h(nq); nw = nq(end) + [1:2*size(whisker_x,2)]; hs.whisker = h(nw); nm = nw(end)+ [1:size(median_x,2)]; hs.median = h(nm); no = nm; if ~isempty (outliers_y) no = nm(end) + [1:size(outliers_y,2)]; hs.outliers = h(no); end if ~isempty (outliers2_y) no2 = no(end) + [1:size(outliers2_y,2)]; hs.outliers2 = h(no2); end endfunction %!demo %! axis ([0,3]); %! boxplot ({randn(10,1)*5+140, randn(13,1)*8+135}); %! set(gca (), "xtick", [1 2], "xticklabel", {"girls", "boys"}) %! title ("Grade 3 heights"); statistics-1.4.1/inst/PaxHeaders.29769/mvtpdf.m0000644000000000000000000000006213443447555016137 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/mvtpdf.m0000644000175000017500000000746213443447555016657 0ustar00johndjohnd00000000000000## Copyright (C) 2015 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{p} =} mvtpdf (@var{x}, @var{sigma}, @var{nu}) ## Compute the probability density function of the multivariate Student's t distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} are the points at which to find the probability, where each row corresponds ## to an observation. (@var{n} by @var{d} matrix) ## ## @item ## @var{sigma} is the scale matrix. (@var{d} by @var{d} symmetric positive definite matrix) ## ## @item ## @var{nu} is the degrees of freedom. (scalar or @var{n} vector) ## ## @end itemize ## ## The distribution is assumed to be centered (zero mean). ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{p} is the probability density for each row of @var{x}. (@var{n} by 1 vector) ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = [1 2]; ## sigma = [1.0 0.5; 0.5 1.0]; ## nu = 4; ## p = mvtpdf (x, sigma, nu) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Michael Roth, On the Multivariate t Distribution, Technical report from Automatic Control at Linkoepings universitet, @url{http://users.isy.liu.se/en/rt/roth/student.pdf} ## @end enumerate ## @end deftypefn ## Author: Nir Krakauer ## Description: PDF of the multivariate Student's t distribution function [p] = mvtpdf (x, sigma, nu) if (nargin != 3) print_usage (); endif # Dimensions d = size (sigma, 1); n = size (x, 1); # Check parameters if (size (x, 2) != d) error ("mvtpdf: x must have the same number of columns as sigma"); endif if (! isscalar (nu) && (! isvector (nu) || numel (nu) != n)) error ("mvtpdf: nu must be a scalar or a vector with the same number of rows as x"); endif if (d < 1 || size (sigma, 2) != d || ! issymmetric (sigma)) error ("mvtpdf: sigma must be nonempty and symmetric"); endif try U = chol (sigma); catch error ("mvtpdf: sigma must be positive definite"); end_try_catch nu = nu(:); sqrt_det_sigma = prod(diag(U)); #square root of determinant of sigma c = (gamma((nu+d)/2) ./ gamma(nu/2)) ./ (sqrt_det_sigma * (nu*pi).^(d/2)); #scale factor for PDF p = c ./ ((1 + sumsq(U' \ x') ./ nu') .^ ((nu' + d)/2))'; #note: sumsq(U' \ x') is equivalent to the quadratic form x*inv(sigma)*x' endfunction #test results verified with R mvtnorm package dmvt function %!assert (mvtpdf ([0 0], eye(2), 1), 0.1591549, 1E-7) #dmvt(x = c(0,0), sigma = diag(2), log = FALSE) %!assert (mvtpdf ([1 0], [1 0.5; 0.5 1], 2), 0.06615947, 1E-7) #dmvt(x = c(1,0), sigma = matrix(c(1, 0.5, 0.5, 1), nrow=2, ncol=2), df = 2, log = FALSE) %!assert (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) #dmvt(x = c(1,0.4,0), sigma = matrix(c(1, 0.5, 0.3, 0.5, 1, 0.6, 0.3, 0.6, 1), nrow=3, ncol=3), df = 5, log = FALSE); dmvt(x = c(1.2,0.5,0.5), sigma = matrix(c(1, 0.5, 0.3, 0.5, 1, 0.6, 0.3, 0.6, 1), nrow=3, ncol=3), df = 6, log = FALSE); dmvt(x = c(1.4,0.6,1), sigma = matrix(c(1, 0.5, 0.3, 0.5, 1, 0.6, 0.3, 0.6, 1), nrow=3, ncol=3), df = 7, log = FALSE) statistics-1.4.1/inst/PaxHeaders.29769/jsucdf.m0000644000000000000000000000006213443447555016115 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/jsucdf.m0000644000175000017500000000402513443447555016625 0ustar00johndjohnd00000000000000## Copyright (C) 2006 Frederick (Rick) A Niles ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {} jsucdf (@var{x}, @var{alpha1}, @var{alpha2}) ## For each element of @var{x}, compute the cumulative distribution ## function (CDF) at @var{x} of the Johnson SU distribution with shape parameters ## @var{alpha1} and @var{alpha2}. ## ## Default values are @var{alpha1} = 1, @var{alpha2} = 1. ## @end deftypefn ## Author: Frederick (Rick) A Niles ## Description: CDF of the Johnson SU distribution ## This function is derived from normcdf.m ## This is the TeX equation of this function: ## ## \[ F(x) = \Phi\left(\alpha_1 + \alpha_2 ## \log\left(x + \sqrt{x^2 + 1} \right)\right) \] ## ## where \[ -\infty < x < \infty ; \alpha_2 > 0 \] and $\Phi$ is the ## standard normal cumulative distribution function. $\alpha_1$ and ## $\alpha_2$ are shape parameters. function cdf = jsucdf (x, alpha1, alpha2) if (! ((nargin == 1) || (nargin == 3))) print_usage; endif if (nargin == 1) m = 0; v = 1; endif if (!isscalar (alpha1) || !isscalar(alpha2)) [retval, x, alpha1, alpha2] = common_size (x, alpha1, alpha2); if (retval > 0) error ("normcdf: x, alpha1 and alpha2 must be of common size or scalar"); endif endif one = ones (size (x)); cdf = stdnormal_cdf (alpha1 .* one + alpha2 .* log (x + sqrt(x.*x + one))); endfunction statistics-1.4.1/inst/PaxHeaders.29769/crossval.m0000644000000000000000000000006213443447555016473 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/crossval.m0000644000175000017500000001365613443447555017215 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{results} =} crossval (@var{f}, @var{X}, @var{y}[, @var{params}]) ## Perform cross validation on given data. ## ## @var{f} should be a function that takes 4 inputs @var{xtrain}, @var{ytrain}, ## @var{xtest}, @var{ytest}, fits a model based on @var{xtrain}, @var{ytrain}, ## applies the fitted model to @var{xtest}, and returns a goodness of fit ## measure based on comparing the predicted and actual @var{ytest}. ## @code{crossval} returns an array containing the values returned by @var{f} ## for every cross-validation fold or resampling applied to the given data. ## ## @var{X} should be an @var{n} by @var{m} matrix of predictor values ## ## @var{y} should be an @var{n} by @var{1} vector of predicand values ## ## @var{params} may include parameter-value pairs as follows: ## ## @table @asis ## @item @qcode{"KFold"} ## Divide set into @var{k} equal-size subsets, using each one successively ## for validation. ## ## @item @qcode{"HoldOut"} ## Divide set into two subsets, training and validation. If the value ## @var{k} is a fraction, that is the fraction of values put in the ## validation subset (by default @var{k}=0.1); if it is a positive integer, ## that is the number of values in the validation subset. ## ## @item @qcode{"LeaveOut"} ## Leave-one-out partition (each element is placed in its own subset). ## The value is ignored. ## ## @item @qcode{"Partition"} ## The value should be a @var{cvpartition} object. ## ## @item @qcode{"Given"} ## The value should be an @var{n} by @var{1} vector specifying in which ## partition to put each element. ## ## @item @qcode{"stratify"} ## The value should be an @var{n} by @var{1} vector containing class ## designations for the elements, in which case the @qcode{"KFold"} and ## @qcode{"HoldOut"} partitionings attempt to ensure each partition ## represents the classes proportionately. ## ## @item @qcode{"mcreps"} ## The value should be a positive integer specifying the number of times ## to resample based on different partitionings. Currently only works with ## the partition type @qcode{"HoldOut"}. ## ## @end table ## ## Only one of @qcode{"KFold"}, @qcode{"HoldOut"}, @qcode{"LeaveOut"}, ## @qcode{"Given"}, @qcode{"Partition"} should be specified. If none is ## specified, the default is @qcode{"KFold"} with @var{k} = 10. ## ## @seealso{cvpartition} ## @end deftypefn ## Author: Nir Krakauer function results = crossval (f, X, y, varargin) [n m] = size (X); if numel(y) != n error('X, y sizes incompatible') endif #extract optional parameter-value argument pairs if numel(varargin) > 1 vargs = varargin; nargs = numel (vargs); values = vargs(2:2:nargs); names = vargs(1:2:nargs)(1:numel(values)); validnames = {'KFold', 'HoldOut', 'LeaveOut', 'Partition', 'Given', 'stratify', 'mcreps'}; for i = 1:numel(names) names(i) = validatestring (names(i){:}, validnames); end for i = 1:numel(validnames) name = validnames(i){:}; name_pos = strmatch (name, names); if !isempty(name_pos) eval([name ' = values(name_pos){:};']) endif endfor endif #construct CV partition if exist ("Partition", "var") P = Partition; elseif exist ("Given", "var") P = cvpartition (Given, "Given"); elseif exist ("KFold", "var") if !exist ("stratify", "var") stratify = n; endif P = cvpartition (stratify, "KFold", KFold); elseif exist ("HoldOut", "var") if !exist ("stratify", "var") stratify = n; endif P = cvpartition (stratify, "HoldOut", HoldOut); if !exist ("mcreps", "var") || isempty (mcreps) mcreps = 1; endif elseif exist ("LeaveOut", "var") P = cvpartition (n, "LeaveOut"); else #KFold if !exist ("stratify", "var") stratify = n; endif P = cvpartition (stratify, "KFold"); endif nr = get(P, "NumTestSets"); #number of test sets to do cross validation on nreps = 1; if strcmp(get(P, "Type"), 'holdout') && exist("mcreps", "var") && mcreps > 1 nreps = mcreps; endif results = nan (nreps, nr); for rep = 1:nreps if rep > 1 P = repartition (P); endif for i = 1:nr inds_train = training (P, i); inds_test = test (P, i); result = f (X(inds_train, :), y(inds_train), X(inds_test, :), y(inds_test)); results(rep, i) = result; endfor endfor endfunction %!test %! load fisheriris.txt %! y = fisheriris(:, 2); %! X = [ones(size(y)) fisheriris(:, 3:5)]; %! f = @(X1, y1, X2, y2) meansq (y2 - X2*regress(y1, X1)); %! results0 = crossval (f, X, y); %! results1 = crossval (f, X, y, 'KFold', 10); %! folds = 5; %! results2 = crossval (f, X, y, 'KFold', folds); %! results3 = crossval (f, X, y, 'Partition', cvpartition (numel (y), 'KFold', folds)); %! results4 = crossval (f, X, y, 'LeaveOut', 1); %! mcreps = 2; n_holdout = 20; %! results5 = crossval (f, X, y, 'HoldOut', n_holdout, 'mcreps', mcreps); %! %! ## ensure equal representation of iris species in the training set -- tends %! ## to slightly reduce cross-validation mean square error %! results6 = crossval (f, X, y, 'KFold', 5, 'stratify', fisheriris(:, 1)); %! %! assert (results0, results1); %! assert (results2, results3); %! assert (size(results4), [1 numel(y)]); %! assert (mean(results4), 4.5304, 1E-4); %! assert (size(results5), [mcreps 1]); statistics-1.4.1/inst/PaxHeaders.29769/vartest2.m0000644000000000000000000000006213443447555016411 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/vartest2.m0000644000175000017500000001100413443447555017114 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Tony Richardson ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} vartest2 (@var{x}, @var{y}) ## @deftypefnx {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} vartest2 (@var{x}, @var{y}, @var{Name}, @var{Value}) ## Perform a F-test for equal variances. ## ## If the second argument @var{y} is a vector, a paired-t test of the ## hypothesis @code{mean (@var{x}) = mean (@var{y})} is performed. ## ## The argument @qcode{"alpha"} can be used to specify the significance level ## of the test (the default value is 0.05). The string ## argument @qcode{"tail"}, can be used to select the desired alternative ## hypotheses. If @qcode{"alt"} is @qcode{"both"} (default) the null is ## tested against the two-sided alternative @code{mean (@var{x}) != @var{m}}. ## If @qcode{"alt"} is @qcode{"right"} the one-sided ## alternative @code{mean (@var{x}) > @var{m}} is considered. ## Similarly for @qcode{"left"}, the one-sided alternative @code{mean ## (@var{x}) < @var{m}} is considered. When @qcode{"vartype"} is @qcode{"equal"} ## the variances are assumed to be equal (this is the default). When ## @qcode{"vartype"} is @qcode{"unequal"} the variances are not assumed equal. ## When argument @var{x} is a matrix the @qcode{"dim"} argument can be ## used to selection the dimension over which to perform the test. ## (The default is the first non-singleton dimension.) ## ## If @var{h} is 0 the null hypothesis is accepted, if it is 1 the null ## hypothesis is rejected. The p-value of the test is returned in @var{pval}. ## A 100(1-alpha)% confidence interval is returned in @var{ci}. @var{stats} ## is a structure containing the value of the test statistic (@var{tstat}), ## the degrees of freedom (@var{df}) and the sample standard deviation ## (@var{sd}). ## ## @end deftypefn ## Author: Tony Richardson ## Description: Test for mean of a normal sample with known variance function [h, p, ci, stats] = vartest2(x, y, varargin) % Set default arguments alpha = 0.05; tail = 'both'; % Find the first non-singleton dimension of x dim = min(find(size(x)~=1)); if isempty(dim), dim = 1; end i = 1; while ( i <= length(varargin) ) switch lower(varargin{i}) case 'alpha' i = i + 1; alpha = varargin{i}; case 'tail' i = i + 1; tail = varargin{i}; case 'dim' i = i + 1; dim = varargin{i}; otherwise error('Invalid Name argument.',[]); end i = i + 1; end if ~isa(tail, 'char') error('tail argument to vartest2 must be a string\n',[]); end s1_var = var(x, 0, dim); s2_var = var(y, 0, dim); stats.fstat = s1_var ./ s2_var; df1= size(x, dim) - 1; df2 = size(y, dim) - 1; % Based on the "tail" argument determine the P-value, the critical values, % and the confidence interval. switch lower(tail) case 'both' p = 2*min(fcdf(stats.fstat,df1,df2),1 - fcdf(stats.fstat,df1,df2)); fcrit = finv(1-alpha/2,df1,df2); ci = [s1_var ./ (fcrit*s2_var); fcrit*s1_var ./ s2_var]; case 'left' p = fcdf(stats.fstat,df1,df2); fcrit = finv(alpha,df1,df2); ci = [zeros(size(stats.fstat)); s1_var ./ (fcrit*s2_var)]; case 'right' p = 1 - fcdf(stats.fstat,df1,df2); fcrit = finv(1-alpha,df1,df2); ci = [s1_var ./ (fcrit*s2_var); inf*ones(size(stats.fstat))]; otherwise error('Invalid fourth (tail) argument to vartest2\n',[]); end % Reshape the ci array to match MATLAB shaping if and(isscalar(stats.fstat), dim==2) ci = ci(:)'; elseif size(stats.fstat,2). ## -*- texinfo -*- ## @deftypefn {} {} triinv (@var{x}, @var{a}, @var{b}, @var{c}) ## For each element of @var{x}, compute the quantile (the inverse of the CDF) ## at @var{x} of the triangular distribution with parameters ## @var{a}, @var{b}, and @var{c} on the interval [@var{a}, @var{b}]. ## @end deftypefn ## Author: Dag Lyberg ## Description: Quantile function of the triangular distribution function inv = triinv (x, a, b, c) if (nargin != 4) print_usage (); endif if (! isscalar (a) || ! isscalar (b) || ! isscalar (c)) [retval, x, a, b, c] = common_size (x, a, b, c); if (retval > 0) error ("triinv: X, A, B, and C must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (a) || iscomplex (b) || iscomplex (c)) error ("triinv: X, A, B, and C must not be complex"); endif if (isa (x, "single") || isa (a, "single") || isa (b, "single")) inv = NaN (size (x), "single"); else inv = NaN (size (x)); endif k = (x >= 0) & (x <= 1) & (a < b) & (a <= c) & (c <= b); inv(k) = 0; if (isscalar (a) && isscalar (b) && isscalar(c)) h = 2 / (b-a); w = c-a; area1 = h * w / 2; j = k & (x <= area1); inv(j) += (x(j) * (h/2) * w).^0.5 + a; w = b-c; j = k & (area1 < x) & (x < 1); inv(j) += b - ((1-x(j)) * (h/2) * w).^0.5; j = k & (x == 1); inv(j) = b; else h = 2 ./ (b-a); w = c-a; area1 = h .* w / 2; j = k & (x <= area1); inv(j) += (x(j) .* (h(j)/2) .* w(j)).^0.5 + a(j); w = b-c; j = k & (area1 < x) & (x < 1); inv(j) += b(j) - ((1-x(j)) .* (h(j)/2) .* w(j)).^0.5; j = k & (x == 1); inv(j) = b(j); endif endfunction %!shared x,y %! x = [-1, 0, 0.02, 0.5, 0.98, 1, 2]; %! y = [NaN, 0, 0.1, 0.5, 0.9, 1, NaN] + 1; %!assert (triinv (x, ones (1,7), 2*ones (1,7), 1.5*ones (1,7)), y, eps) %!assert (triinv (x, 1*ones (1,7), 2, 1.5), y, eps) %!assert (triinv (x, 1, 2*ones (1,7), 1.5), y, eps) %!assert (triinv (x, 1, 2, 1.5*ones (1,7)), y, eps) %!assert (triinv (x, 1, 2, 1.5), y, eps) %!assert (triinv (x, [1, 1, NaN, 1, 1, 1, 1], 2, 1.5), [y(1:2), NaN, y(4:7)], eps) %!assert (triinv (x, 1, 2*[1, 1, NaN, 1, 1, 1, 1], 1.5), [y(1:2), NaN, y(4:7)], eps) %!assert (triinv (x, 1, 2, 1.5*[1, 1, NaN, 1, 1, 1, 1]), [y(1:2), NaN, y(4:7)], eps) %!assert (triinv ([x, NaN], 1, 2, 1.5), [y, NaN], eps) ## Test class of input preserved %!assert (triinv (single ([x, NaN]), 1, 2, 1.5), single ([y, NaN]), eps('single')) %!assert (triinv ([x, NaN], single (1), 2, 1.5), single ([y, NaN]), eps('single')) %!assert (triinv ([x, NaN], 1, single (2), 1.5), single ([y, NaN]), eps('single')) %!assert (triinv ([x, NaN], 1, 2, single (1.5)), single ([y, NaN]), eps('single')) ## Test input validation %!error triinv () %!error triinv (1) %!error triinv (1,2) %!error triinv (1,2,3) %!error triinv (1,2,3,4,5) %!error triinv (1, ones (3), ones (2), ones (2)) %!error triinv (1, ones (2), ones (3), ones (2)) %!error triinv (1, ones (2), ones (2), ones (3)) %!error triinv (i, 2, 2, 2) %!error triinv (2, i, 2, 2) %!error triinv (2, 2, i, 2) %!error triinv (2, 2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/burrinv.m0000644000000000000000000000006213443447555016326 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/burrinv.m0000644000175000017500000000716613443447555017047 0ustar00johndjohnd00000000000000## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} burrinv (@var{x}, @var{alpha}, @var{c}, @var{k}) ## For each element of @var{x}, compute the quantile (the inverse of the CDF) ## at @var{x} of the Burr distribution with scale parameter @var{alpha} and ## shape parameters @var{c} and @var{k}. ## @end deftypefn ## Author: Dag Lyberg ## Description: Quantile function of the Burr distribution function inv = burrinv (x, alpha, c, k) if (nargin != 4) print_usage (); endif if (! isscalar (alpha) || ! isscalar (c) || ! isscalar (k) ) [retval, x, alpha, c, k] = common_size (x, alpha, c, k); if (retval > 0) error ("burrinv: X, ALPHA, C AND K must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex(alpha) || iscomplex (c) || iscomplex (k)) error ("burrinv: X, ALPHA, C AND K must not be complex"); endif if (isa (x, "single") || isa (alpha, "single") || isa (c, "single") ... || isa (k, "single")) inv = zeros (size (x), "single"); else inv = zeros (size (x)); endif j = isnan (x) | (x < 0) | (x > 1) | ! (alpha > 0) | ! (c > 0) | ! (k > 0); inv(j) = NaN; j = (x == 1) & (0 < alpha) & (alpha < Inf) & (0 < c) & (c < Inf) ... & (0 < k) & (k < Inf); inv(j) = Inf; j = (0 < x) & (x < 1) & (0 < alpha) & (alpha < Inf) & (0 < c) & (c < Inf) ... & (0 < k) & (k < Inf); if (isscalar (alpha) && isscalar(c) && isscalar(k)) inv(j) = ((1 - x(j) / alpha).^(-1 / k) - 1).^(1 / c) ; else inv(j) = ((1 - x(j) ./ alpha(j)).^(-1 ./ k(j)) - 1).^(1 ./ c(j)) ; endif endfunction %!shared x,y %! x = [-Inf, -1, 0, 1/2, 1, 2, Inf]; %! y = [NaN, NaN, 0, 1 , Inf, NaN, NaN]; %!assert (burrinv (x, ones (1,7), ones (1,7), ones(1,7)), y, eps) %!assert (burrinv (x, 1, 1, 1), y, eps) %!assert (burrinv (x, [1, 1, 1, NaN, 1, 1, 1], 1, 1), [y(1:3), NaN, y(5:7)], eps) %!assert (burrinv (x, 1, [1, 1, 1, NaN, 1, 1, 1], 1), [y(1:3), NaN, y(5:7)], eps) %!assert (burrinv (x, 1, 1, [1, 1, 1, NaN, 1, 1, 1]), [y(1:3), NaN, y(5:7)], eps) %!assert (burrinv ([x, NaN], 1, 1, 1), [y, NaN], eps) ## Test class of input preserved %!assert (burrinv (single ([x, NaN]), 1, 1, 1), single ([y, NaN]), eps('single')) %!assert (burrinv ([x, NaN], single (1), 1, 1), single ([y, NaN]), eps('single')) %!assert (burrinv ([x, NaN], 1, single (1), 1), single ([y, NaN]), eps('single')) %!assert (burrinv ([x, NaN], 1, 1, single (1)), single ([y, NaN]), eps('single')) ## Test input validation %!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 (i, 2, 2, 2) %!error burrinv (2, i, 2, 2) %!error burrinv (2, 2, i, 2) %!error burrinv (2, 2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/bbsinv.m0000644000000000000000000000006213443447555016122 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/bbsinv.m0000644000175000017500000001025613443447555016635 0ustar00johndjohnd00000000000000## Copyright (C) 2018 John Donoghue ## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1995-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} bbsinv (@var{x}, @var{shape}, @var{scale}, @var{location}) ## For each element of @var{x}, compute the quantile (the inverse of the CDF) ## at @var{x} of the Birnbaum-Saunders distribution with parameters ## @var{location}, @var{scale}, and @var{shape}. ## @end deftypefn ## Author: Dag Lyberg ## Description: Quantile function of the Birnbaum-Saunders distribution function inv = bbsinv (x, shape, scale, location) if (nargin != 4) print_usage (); endif if (! isscalar (location) || ! isscalar (scale) || ! isscalar(shape)) [retval, x, location, scale, shape] = ... common_size (x, location, scale, shape); if (retval > 0) error ("bbsinv: X, LOCATION, SCALE and SHAPE must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (location) ... || iscomplex (scale) || iscomplex(shape)) error ("bbsinv: X, LOCATION, SCALE and SHAPE must not be complex"); endif if (isa (x, "single") || isa (location, "single") ... || isa (scale, "single") || isa (shape, "single")) inv = zeros (size (x), "single"); else inv = zeros (size (x)); endif k = isnan (x) | (x < 0) | (x > 1) | ! (-Inf < location) | ! (location < Inf) ... | ! (scale > 0) | ! (scale < Inf) | ! (shape > 0) | ! (shape < Inf); inv(k) = NaN; k = (x <= 0) & (-Inf < location) & (location < Inf) ... & (scale > 0) & (scale < Inf) & (shape > 0) & (shape < Inf); inv(k) = 0; k = (x == 1) & (-Inf < location) & (location < Inf) ... & (scale > 0) & (scale < Inf) & (shape > 0) & (shape < Inf); inv(k) = Inf; k = (0 < x) & (x < 1) & (location < Inf) & (0 < scale) & (scale < Inf) ... & (0 < shape) & (shape < Inf); if (isscalar (location) && isscalar(scale) && isscalar(shape)) y = shape * norminv (x(k)); inv(k) = location + scale * (y + sqrt (4 + y.^2)).^2 / 4; else y = shape(k) .* norminv (x(k)); inv(k) = location(k) + scale(k) .* (y + sqrt (4 + y.^2)).^2 ./ 4; endif endfunction %!shared x,y,f %! f = @(x,a,b,c) (a + b * (c * norminv (x) + sqrt (4 + (c * norminv(x))^2))^2) / 4; %! x = [-1, 0, 1/4, 1/2, 1, 2]; %! y = [0, 0, f(1/4, 0, 1, 1), 1, Inf, NaN]; %!assert (bbsinv (x, ones (1,6), ones (1,6), zeros (1,6)), y) %!assert (bbsinv (x, 1, 1, zeros (1,6)), y) %!assert (bbsinv (x, 1, ones (1,6), 0), y) %!assert (bbsinv (x, ones (1,6), 1, 0), y) %!assert (bbsinv (x, 1, 1, 0), y) %!assert (bbsinv (x, 1, 1, [0, 0, 0, NaN, 0, 0]), [y(1:3), NaN, y(5:6)]) %!assert (bbsinv (x, 1, [1, 1, 1, NaN, 1, 1], 0), [y(1:3), NaN, y(5:6)]) %!assert (bbsinv (x, [1, 1, 1, NaN, 1, 1], 1, 0), [y(1:3), NaN, y(5:6)]) %!assert (bbsinv ([x, NaN], 1, 1, 0), [y, NaN]) ## Test class of input preserved %!assert (bbsinv (single ([x, NaN]), 1, 1, 0), single ([y, NaN])) %!assert (bbsinv ([x, NaN], 1, 1, single (0)), single ([y, NaN])) %!assert (bbsinv ([x, NaN], 1, single (1), 0), single ([y, NaN])) %!assert (bbsinv ([x, NaN], single (1), 1, 0), single ([y, NaN])) ## Test input validation %!error bbsinv () %!error bbsinv (1) %!error bbsinv (1,2,3) %!error bbsinv (1,2,3,4,5) %!error bbsinv (ones (3), ones (2), ones(2), ones(2)) %!error bbsinv (ones (2), ones (3), ones(2), ones(2)) %!error bbsinv (ones (2), ones (2), ones(3), ones(2)) %!error bbsinv (ones (2), ones (2), ones(2), ones(3)) %!error bbsinv (i, 4, 3, 2) %!error bbsinv (1, i, 3, 2) %!error bbsinv (1, 4, i, 2) %!error bbsinv (1, 4, 3, i) statistics-1.4.1/inst/PaxHeaders.29769/hmmestimate.m0000644000000000000000000000006213443447555017154 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/hmmestimate.m0000644000175000017500000003254413443447555017673 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{transprobest}, @var{outprobest}] =} hmmestimate (@var{sequence}, @var{states}) ## @deftypefnx {Function File} {} hmmestimate (@dots{}, 'statenames', @var{statenames}) ## @deftypefnx {Function File} {} hmmestimate (@dots{}, 'symbols', @var{symbols}) ## @deftypefnx {Function File} {} hmmestimate (@dots{}, 'pseudotransitions', @var{pseudotransitions}) ## @deftypefnx {Function File} {} hmmestimate (@dots{}, 'pseudoemissions', @var{pseudoemissions}) ## Estimate the matrix of transition probabilities and the matrix of output ## probabilities of a given sequence of outputs and states generated by a ## hidden Markov model. The model assumes that the generation starts in ## state @code{1} at step @code{0} but does not include step @code{0} in the ## generated states and sequence. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{sequence} is a vector of a sequence of given outputs. The outputs ## must be integers ranging from @code{1} to the number of outputs of the ## hidden Markov model. ## ## @item ## @var{states} is a vector of the same length as @var{sequence} of given ## states. The states must be integers ranging from @code{1} to the number ## of states of the hidden Markov model. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{transprobest} is the matrix of the estimated transition ## probabilities of the states. @code{transprobest(i, j)} is the estimated ## probability of a transition to state @code{j} given state @code{i}. ## ## @item ## @var{outprobest} is the matrix of the estimated output probabilities. ## @code{outprobest(i, j)} is the estimated probability of generating ## output @code{j} given state @code{i}. ## @end itemize ## ## If @code{'symbols'} is specified, then @var{sequence} is expected to be a ## sequence of the elements of @var{symbols} instead of integers. ## @var{symbols} can be a cell array. ## ## If @code{'statenames'} is specified, then @var{states} is expected to be ## a sequence of the elements of @var{statenames} instead of integers. ## @var{statenames} can be a cell array. ## ## If @code{'pseudotransitions'} is specified then the integer matrix ## @var{pseudotransitions} is used as an initial number of counted ## transitions. @code{pseudotransitions(i, j)} is the initial number of ## counted transitions from state @code{i} to state @code{j}. ## @var{transprobest} will have the same size as @var{pseudotransitions}. ## Use this if you have transitions that are very unlikely to occur. ## ## If @code{'pseudoemissions'} is specified then the integer matrix ## @var{pseudoemissions} is used as an initial number of counted outputs. ## @code{pseudoemissions(i, j)} is the initial number of counted outputs ## @code{j} given state @code{i}. If @code{'pseudoemissions'} is also ## specified then the number of rows of @var{pseudoemissions} must be the ## same as the number of rows of @var{pseudotransitions}. @var{outprobest} ## will have the same size as @var{pseudoemissions}. Use this if you have ## outputs or states that are very unlikely to occur. ## ## @subheading Examples ## ## @example ## @group ## 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 (25, transprob, outprob); ## [transprobest, outprobest] = hmmestimate (sequence, states) ## @end group ## ## @group ## symbols = @{'A', 'B', 'C'@}; ## statenames = @{'One', 'Two'@}; ## [sequence, states] = hmmgenerate (25, transprob, outprob, ## 'symbols', symbols, 'statenames', statenames); ## [transprobest, outprobest] = hmmestimate (sequence, states, ## 'symbols', symbols, ## 'statenames', statenames) ## @end group ## ## @group ## pseudotransitions = [8, 2; 4, 6]; ## pseudoemissions = [2, 4, 4; 7, 2, 1]; ## [sequence, states] = hmmgenerate (25, transprob, outprob); ## [transprobest, outprobest] = hmmestimate (sequence, states, 'pseudotransitions', pseudotransitions, 'pseudoemissions', pseudoemissions) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Lawrence R. Rabiner. A Tutorial on Hidden Markov Models and Selected ## Applications in Speech Recognition. @cite{Proceedings of the IEEE}, ## 77(2), pages 257-286, February 1989. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Estimation of a hidden Markov model for a given sequence function [transprobest, outprobest] = hmmestimate (sequence, states, varargin) # Check arguments if (nargin < 2 || mod (length (varargin), 2) != 0) print_usage (); endif len = length (sequence); if (length (states) != len) error ("hmmestimate: sequence and states must have equal length"); endif # Flag for symbols usesym = false; # Flag for statenames usesn = false; # Variables for return values transprobest = []; outprobest = []; # Process varargin for i = 1:2:length (varargin) # There must be an identifier: 'symbols', 'statenames', # 'pseudotransitions' or 'pseudoemissions' if (! ischar (varargin{i})) print_usage (); endif # Upper case is also fine lowerarg = lower (varargin{i}); if (strcmp (lowerarg, 'symbols')) usesym = true; # Use the following argument as symbols symbols = varargin{i + 1}; # The same for statenames elseif (strcmp (lowerarg, 'statenames')) usesn = true; # Use the following argument as statenames statenames = varargin{i + 1}; elseif (strcmp (lowerarg, 'pseudotransitions')) # Use the following argument as an initial count for transitions transprobest = varargin{i + 1}; if (! ismatrix (transprobest)) error ("hmmestimate: pseudotransitions must be a non-empty numeric matrix"); endif if (rows (transprobest) != columns (transprobest)) error ("hmmestimate: pseudotransitions must be a square matrix"); endif elseif (strcmp (lowerarg, 'pseudoemissions')) # Use the following argument as an initial count for outputs outprobest = varargin{i + 1}; if (! ismatrix (outprobest)) error ("hmmestimate: pseudoemissions must be a non-empty numeric matrix"); endif else error ("hmmestimate: expected 'symbols', 'statenames', 'pseudotransitions' or 'pseudoemissions' but found '%s'", varargin{i}); endif endfor # Transform sequence from symbols to integers if necessary if (usesym) # sequenceint is used to build the transformed sequence sequenceint = zeros (1, len); for i = 1:length (symbols) # Search for symbols(i) in the sequence, isequal will have 1 at # corresponding indices; i is the right integer for that symbol isequal = ismember (sequence, symbols(i)); # We do not want to change sequenceint if the symbol appears a second # time in symbols if (any ((sequenceint == 0) & (isequal == 1))) isequal *= i; sequenceint += isequal; endif endfor if (! all (sequenceint)) index = max ((sequenceint == 0) .* (1:len)); error (["hmmestimate: sequence(" int2str (index) ") not in symbols"]); endif sequence = sequenceint; else if (! isvector (sequence)) error ("hmmestimate: sequence must be a non-empty vector"); endif if (! all (ismember (sequence, 1:max (sequence)))) index = max ((ismember (sequence, 1:max (sequence)) == 0) .* (1:len)); error (["hmmestimate: sequence(" int2str (index) ") not feasible"]); endif endif # Transform states from statenames to integers if necessary if (usesn) # statesint is used to build the transformed states statesint = zeros (1, len); for i = 1:length (statenames) # Search for statenames(i) in states, isequal will have 1 at # corresponding indices; i is the right integer for that statename isequal = ismember (states, statenames(i)); # We do not want to change statesint if the statename appears a second # time in statenames if (any ((statesint == 0) & (isequal == 1))) isequal *= i; statesint += isequal; endif endfor if (! all (statesint)) index = max ((statesint == 0) .* (1:len)); error (["hmmestimate: states(" int2str (index) ") not in statenames"]); endif states = statesint; else if (! isvector (states)) error ("hmmestimate: states must be a non-empty vector"); endif if (! all (ismember (states, 1:max (states)))) index = max ((ismember (states, 1:max (states)) == 0) .* (1:len)); error (["hmmestimate: states(" int2str (index) ") not feasible"]); endif endif # Estimate the number of different states as the max of states nstate = max (states); # Estimate the number of different outputs as the max of sequence noutput = max (sequence); # transprobest is empty if pseudotransitions is not specified if (isempty (transprobest)) # outprobest is not empty if pseudoemissions is specified if (! isempty (outprobest)) if (nstate > rows (outprobest)) error ("hmmestimate: not enough rows in pseudoemissions"); endif # The number of states is specified by pseudoemissions nstate = rows (outprobest); endif transprobest = zeros (nstate, nstate); else if (nstate > rows (transprobest)) error ("hmmestimate: not enough rows in pseudotransitions"); endif # The number of states is given by pseudotransitions nstate = rows (transprobest); endif # outprobest is empty if pseudoemissions is not specified if (isempty (outprobest)) outprobest = zeros (nstate, noutput); else if (noutput > columns (outprobest)) error ("hmmestimate: not enough columns in pseudoemissions"); endif # Number of outputs is specified by pseudoemissions noutput = columns (outprobest); if (rows (outprobest) != nstate) error ("hmmestimate: pseudoemissions must have the same number of rows as pseudotransitions"); endif endif # Assume that the model started in state 1 cstate = 1; for i = 1:len # Count the number of transitions for each state pair transprobest(cstate, states(i)) ++; cstate = states (i); # Count the number of outputs for each state output pair outprobest(cstate, sequence(i)) ++; endfor # transprobest and outprobest contain counted numbers # Each row in transprobest and outprobest should contain estimated # probabilities # => scale so that the sum is 1 # A zero row remains zero # - for transprobest s = sum (transprobest, 2); s(s == 0) = 1; transprobest = transprobest ./ (s * ones (1, nstate)); # - for outprobest s = sum (outprobest, 2); s(s == 0) = 1; outprobest = outprobest ./ (s * ones (1, noutput)); endfunction %!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.88889, 0.11111; 0.28571, 0.71429]; %! expectedoutprob = [0.16667, 0.33333, 0.50000; 1.00000, 0.00000, 0.00000]; %! assert (transprobest, expectedtransprob, 0.001); %! assert (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.88889, 0.11111; 0.28571, 0.71429]; %! expectedoutprob = [0.16667, 0.33333, 0.50000; 1.00000, 0.00000, 0.00000]; %! assert (transprobest, expectedtransprob, 0.001); %! assert (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.85714, 0.14286; 0.35294, 0.64706]; %! expectedoutprob = [0.178571, 0.357143, 0.464286; 0.823529, 0.117647, 0.058824]; %! assert (transprobest, expectedtransprob, 0.001); %! assert (outprobest, expectedoutprob, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/princomp.m0000644000000000000000000000006213443447555016466 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/princomp.m0000644000175000017500000001242313443447555017177 0ustar00johndjohnd00000000000000## Copyright (C) 2013-2019 Fernando Damian Nieuwveldt ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version 3 ## of the License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{COEFF}]} = princomp(@var{X}) ## @deftypefnx {Function File} {[@var{COEFF},@var{SCORE}]} = princomp(@var{X}) ## @deftypefnx {Function File} {[@var{COEFF},@var{SCORE},@var{latent}]} = princomp(@var{X}) ## @deftypefnx {Function File} {[@var{COEFF},@var{SCORE},@var{latent},@var{tsquare}]} = princomp(@var{X}) ## @deftypefnx {Function File} {[...]} = princomp(@var{X},'econ') ## Performs a principal component analysis on a NxP data matrix X ## ## @itemize @bullet ## @item ## @var{COEFF} : returns the principal component coefficients ## @item ## @var{SCORE} : returns the principal component scores, the representation of X ## in the principal component space ## @item ## @var{LATENT} : returns the principal component variances, i.e., the ## eigenvalues of the covariance matrix X. ## @item ## @var{TSQUARE} : returns Hotelling's T-squared Statistic for each observation in X ## @item ## [...] = princomp(X,'econ') returns only the elements of latent that are not ## necessarily zero, and the corresponding columns of COEFF and SCORE, that is, ## when n <= p, only the first n-1. This can be significantly faster when p is ## much larger than n. In this case the svd will be applied on the transpose of ## the data matrix X ## ## @end itemize ## ## @subheading References ## ## @enumerate ## @item ## Jolliffe, I. T., Principal Component Analysis, 2nd Edition, Springer, 2002 ## ## @end enumerate ## @end deftypefn function [COEFF,SCORE,latent,tsquare] = princomp(X,varargin) if (nargin < 1 || nargin > 2) print_usage (); endif if (nargin == 2 && ! strcmpi (varargin{:}, "econ")) error ("princomp: if a second input argument is present, it must be the string 'econ'"); endif [nobs nvars] = size(X); # Center the columns to mean zero Xcentered = bsxfun(@minus,X,mean(X)); # Check if there are more variables then observations if nvars <= nobs [U,S,COEFF] = svd(Xcentered, "econ"); else # Calculate the svd on the transpose matrix, much faster if (nargin == 2 && strcmpi ( varargin{:} , "econ")) [COEFF,S,V] = svd(Xcentered' , 'econ'); else [COEFF,S,V] = svd(Xcentered'); endif endif if nargout > 1 # Get the Scores SCORE = Xcentered*COEFF; # Get the rank of the SCORE matrix r = rank(SCORE); # Only use the first r columns, pad rest with zeros if economy != 'econ' SCORE = SCORE(:,1:r) ; if !(nargin == 2 && strcmpi ( varargin{:} , "econ")) SCORE = [SCORE, zeros(nobs , nvars-r)]; else COEFF = COEFF(: , 1:r); endif endif if nargout > 2 # This is the same as the eigenvalues of the covariance matrix of X latent = (diag(S'*S)/(size(Xcentered,1)-1))(1:r); if !(nargin == 2 && strcmpi ( varargin{:} , "econ")) latent= [latent;zeros(nvars-r,1)]; endif endif if nargout > 3 # Calculate the Hotelling T-Square statistic for the observations tsquare = sumsq(zscore(SCORE(:,1:r)),2); endif endfunction %!shared COEFF,SCORE,latent,tsquare,m,x,R,V,lambda,i,S,F #NIST Engineering Statistics Handbook example (6.5.5.2) %!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(diag(S(:, 1:2)*S(:, 1:2)'), [0.8662; 0.8420; 0.9876], 1E-4); #contribution of first 2 PCs to each original variable %! B = V(:, i) * diag( 1./ sqrt(diag(lambda)(i))); %! F = zscore(x)*B; %! [COEFF,SCORE,latent,tsquare] = princomp(zscore(x, 1)); %!assert(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(COEFF,m(1:2,:),10*eps); %!assert(SCORE,-m,10*eps); %!assert(latent,[1.5;.5],10*eps); %!assert(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(COEFF,m,10*eps); %!assert(SCORE(:,1),-m(1:2,1),10*eps); %!assert(SCORE(:,2:3),zeros(2),10*eps); %!assert(latent,[1;0;0],10*eps); %!assert(tsquare,[0.5;0.5],10*eps) %!test %! [COEFF,SCORE,latent,tsquare] = princomp(x, "econ"); %!assert(COEFF,m(:, 1),10*eps); %!assert(SCORE,-m(1:2,1),10*eps); %!assert(latent,[1],10*eps); %!assert(tsquare,[0.5;0.5],10*eps) statistics-1.4.1/inst/PaxHeaders.29769/copulacdf.m0000644000000000000000000000006213443447555016577 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/copulacdf.m0000644000175000017500000002174013443447555017312 0ustar00johndjohnd00000000000000## Copyright (C) 2008 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{p} =} copulacdf (@var{family}, @var{x}, @var{theta}) ## @deftypefnx {Function File} {} copulacdf ('t', @var{x}, @var{theta}, @var{nu}) ## Compute the cumulative distribution function of a copula family. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{family} is the copula family name. Currently, @var{family} can ## be @code{'Gaussian'} for the Gaussian family, @code{'t'} for the ## Student's t family, @code{'Clayton'} for the Clayton family, ## @code{'Gumbel'} for the Gumbel-Hougaard family, @code{'Frank'} for ## the Frank family, @code{'AMH'} for the Ali-Mikhail-Haq family, or ## @code{'FGM'} for the Farlie-Gumbel-Morgenstern family. ## ## @item ## @var{x} is the support where each row corresponds to an observation. ## ## @item ## @var{theta} is the parameter of the copula. For the Gaussian and ## Student's t copula, @var{theta} must be a correlation matrix. For ## bivariate copulas @var{theta} can also be a correlation coefficient. ## For the Clayton family, the Gumbel-Hougaard family, the Frank family, ## and the Ali-Mikhail-Haq family, @var{theta} must be a vector with the ## same number of elements as observations in @var{x} or be scalar. For ## the Farlie-Gumbel-Morgenstern family, @var{theta} must be a matrix of ## coefficients for the Farlie-Gumbel-Morgenstern polynomial where each ## row corresponds to one set of coefficients for an observation in ## @var{x}. A single row is expanded. The coefficients are in binary ## order. ## ## @item ## @var{nu} is the degrees of freedom for the Student's t family. ## @var{nu} must be a vector with the same number of elements as ## observations in @var{x} or be scalar. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{p} is the cumulative distribution of the copula at each row of ## @var{x} and corresponding parameter @var{theta}. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = [0.2:0.2:0.6; 0.2:0.2:0.6]; ## theta = [1; 2]; ## p = copulacdf ("Clayton", x, theta) ## @end group ## ## @group ## 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) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Roger B. Nelsen. @cite{An Introduction to Copulas}. Springer, ## New York, second edition, 2006. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: CDF of a copula family function p = copulacdf (family, x, theta, nu) # Check arguments if (nargin != 3 && (nargin != 4 || ! strcmpi (family, "t"))) print_usage (); endif if (! ischar (family)) error ("copulacdf: family must be one of 'Gaussian', 't', 'Clayton', 'Gumbel', 'Frank', 'AMH', and 'FGM'"); endif if (! isempty (x) && ! ismatrix (x)) error ("copulacdf: x must be a numeric matrix"); endif [n, d] = size (x); lower_family = lower (family); # Check family and copula parameters switch (lower_family) case {"gaussian", "t"} # Family with a covariance matrix if (d == 2 && isscalar (theta)) # Expand a scalar to a correlation matrix theta = [1, theta; theta, 1]; endif if (any (size (theta) != [d, d]) || any (diag (theta) != 1) || any (any (theta != theta')) || min (eig (theta)) <= 0) error ("copulacdf: theta must be a correlation matrix"); endif if (nargin == 4) # Student's t family if (! isscalar (nu) && (! isvector (nu) || length (nu) != n)) error ("copulacdf: nu must be a vector with the same number of rows as x or be scalar"); endif nu = nu(:); endif case {"clayton", "gumbel", "frank", "amh"} # Archimedian one parameter family if (! isvector (theta) || (! isscalar (theta) && length (theta) != n)) error ("copulacdf: theta must be a vector with the same number of rows as x or be scalar"); endif theta = theta(:); if (n > 1 && isscalar (theta)) theta = repmat (theta, n, 1); endif case {"fgm"} # Exponential number of parameters if (! ismatrix (theta) || size (theta, 2) != (2 .^ d - d - 1) || (size (theta, 1) != 1 && size (theta, 1) != n)) error ("copulacdf: theta must be a row vector of length 2^d-d-1 or a matrix of size n x (2^d-d-1)"); endif if (n > 1 && size (theta, 1) == 1) theta = repmat (theta, n, 1); endif otherwise error ("copulacdf: unknown copula family '%s'", family); endswitch if (n == 0) # Input is empty p = zeros (0, 1); else # Truncate input to unit hypercube x(x < 0) = 0; x(x > 1) = 1; # Compute the cumulative distribution function according to family switch (lower_family) case {"gaussian"} # The Gaussian family p = mvncdf (norminv (x), zeros (1, d), theta); # No parameter bounds check k = []; case {"t"} # The Student's t family p = mvtcdf (tinv (x, nu), theta, nu); # No parameter bounds check k = []; case {"clayton"} # The Clayton family p = exp (-log (max (sum (x .^ (repmat (-theta, 1, d)), 2) - d + 1, 0)) ./ theta); # Product copula at columns where theta == 0 k = find (theta == 0); if (any (k)) p(k) = prod (x(k, :), 2); endif # Check bounds if (d > 2) k = find (! (theta >= 0) | ! (theta < inf)); else k = find (! (theta >= -1) | ! (theta < inf)); endif case {"gumbel"} # The Gumbel-Hougaard family p = exp (-(sum ((-log (x)) .^ repmat (theta, 1, d), 2)) .^ (1 ./ theta)); # Check bounds k = find (! (theta >= 1) | ! (theta < inf)); case {"frank"} # The Frank family p = -log (1 + (prod (expm1 (repmat (-theta, 1, d) .* x), 2)) ./ (expm1 (-theta) .^ (d - 1))) ./ theta; # Product copula at columns where theta == 0 k = find (theta == 0); if (any (k)) p(k) = prod (x(k, :), 2); endif # Check bounds if (d > 2) k = find (! (theta > 0) | ! (theta < inf)); else k = find (! (theta > -inf) | ! (theta < inf)); endif case {"amh"} # The Ali-Mikhail-Haq family p = (theta - 1) ./ (theta - prod ((1 + repmat (theta, 1, d) .* (x - 1)) ./ x, 2)); # Check bounds if (d > 2) k = find (! (theta >= 0) | ! (theta < 1)); else k = find (! (theta >= -1) | ! (theta < 1)); endif case {"fgm"} # The Farlie-Gumbel-Morgenstern family # All binary combinations bcomb = logical (floor (mod (((0:(2 .^ d - 1))' * 2 .^ ((1 - d):0)), 2))); ecomb = ones (size (bcomb)); ecomb(bcomb) = -1; # Summation over all combinations of order >= 2 bcomb = bcomb(sum (bcomb, 2) >= 2, end:-1:1); # Linear constraints matrix ac = zeros (size (ecomb, 1), size (bcomb, 1)); # Matrix to compute p ap = zeros (size (x, 1), size (bcomb, 1)); for i = 1:size (bcomb, 1) ac(:, i) = -prod (ecomb(:, bcomb(i, :)), 2); ap(:, i) = prod (1 - x(:, bcomb(i, :)), 2); endfor p = prod (x, 2) .* (1 + sum (ap .* theta, 2)); # Check linear constraints k = false (n, 1); for i = 1:n k(i) = any (ac * theta(i, :)' > 1); endfor endswitch # Out of bounds parameters if (any (k)) p(k) = NaN; endif endif endfunction %!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 (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 (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 (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 (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 (p, expected_p, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/tblwrite.m0000644000000000000000000000006213443447555016473 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/tblwrite.m0000644000175000017500000000764013443447555017211 0ustar00johndjohnd00000000000000## Copyright (C) 2008 Bill Denney ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {} tblwrite (@var{data}, @var{varnames}, @var{casenames}, @var{filename}) ## @deftypefnx {Function File} {} tblwrite (@var{data}, @var{varnames}, @var{casenames}, @var{filename}, @var{delimeter}) ## Write tabular data to an ascii file. ## ## @var{data} is written to an ascii data file named @var{filename} with ## an optional @var{delimeter}. The delimeter may be any single ## character or ## @itemize ## @item "space" " " (default) ## @item "tab" "\t" ## @item "comma" "," ## @item "semi" ";" ## @item "bar" "|" ## @end itemize ## ## The @var{data} is written starting at cell (2,2) where the ## @var{varnames} are a char matrix or cell vector written to the first ## row (starting at (1,2)), and the @var{casenames} are a char matrix ## (or cell vector) written to the first column (starting at (2,1)). ## @seealso{tblread, csv2cell, cell2csv} ## @end deftypefn function tblwrite (data, varnames, casenames, f="", d=" ") ## Check arguments if nargin < 4 || nargin > 5 print_usage (); endif varnames = __makecell__ (varnames, "varnames"); casenames = __makecell__ (casenames, "varnames"); if numel (varnames) != columns (data) error ("tblwrite: the number of rows (or cells) in varnames must equal the number of columns in data") endif if numel (varnames) != rows (data) error ("tblwrite: the number of rows (or cells) in casenames must equal the number of rows in data") endif if isempty (f) ## FIXME: open a file dialog box in this case when a file dialog box ## becomes available error ("tblread: filename must be given") endif [d err] = tbl_delim (d); if ! isempty (err) error ("tblwrite: %s", err) endif dat = cell (size (data) + 1); dat(1,2:end) = varnames; dat(2:end,1) = casenames; dat(2:end,2:end) = mat2cell (data, ones (rows (data), 1), ones (columns (data), 1));; cell2csv (f, dat, d); endfunction function x = __makecell__ (x, name) ## force x into a cell matrix if ! iscell (x) if ischar (x) ## convert varnames into a cell x = mat2cell (x, ones (rows (x), 1)); else error ("tblwrite: %s must be either a char or a cell", name) endif endif endfunction ## Tests %!shared d, v, c, tempfilename %! d = [1 2;3 4]; %! v = ["a ";"bc"]; %! c = ["de";"f "]; %! tempfilename = tempname; %!test %! tblwrite (d, v, c, tempfilename); %! [dt vt ct] = tblread (tempfilename, " "); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %! delete (tempfilename); %!test %! tblwrite (d, v, c, tempfilename, " "); %! [dt vt ct] = tblread (tempfilename, " "); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %! delete (tempfilename); %!test %! tblwrite (d, v, c, tempfilename, "space"); %! [dt vt ct] = tblread (tempfilename); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %! delete (tempfilename); %!test %! tblwrite (d, v, c, tempfilename, "tab"); %! [dt vt ct] = tblread (tempfilename, "tab"); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %! delete (tempfilename); %!test %! tblwrite (d, v, c, tempfilename, "\t"); %! [dt vt ct] = tblread (tempfilename, "\t"); %! assert (dt, d); %! assert (vt, v); %! assert (ct, c); %! delete (tempfilename); statistics-1.4.1/inst/PaxHeaders.29769/nanmean.m0000644000000000000000000000006213443447555016254 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nanmean.m0000644000175000017500000000250713443447555016767 0ustar00johndjohnd00000000000000## Copyright (C) 2001 Paul Kienzle ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{v} =} nanmean (@var{X}) ## @deftypefnx{Function File} {@var{v} =} nanmean (@var{X}, @var{dim}) ## Compute the mean value while ignoring NaN values. ## ## @code{nanmean} is identical to the @code{mean} function except that NaN values ## are ignored. If all values are NaN, the mean is returned as NaN. ## ## @seealso{mean, nanmin, nanmax, nansum, nanmedian} ## @end deftypefn function v = nanmean (X, varargin) if nargin < 1 print_usage; else n = sum (!isnan(X), varargin{:}); n(n == 0) = NaN; X(isnan(X)) = 0; v = sum (X, varargin{:}) ./ n; endif endfunction statistics-1.4.1/inst/PaxHeaders.29769/copularnd.m0000644000000000000000000000006213443447555016626 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/copularnd.m0000644000175000017500000001762413443447555017347 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Arno Onken ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{x} =} copularnd (@var{family}, @var{theta}, @var{n}) ## @deftypefnx {Function File} {} copularnd (@var{family}, @var{theta}, @var{n}, @var{d}) ## @deftypefnx {Function File} {} copularnd ('t', @var{theta}, @var{nu}, @var{n}) ## Generate random samples from a copula family. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{family} is the copula family name. Currently, @var{family} can be ## @code{'Gaussian'} for the Gaussian family, @code{'t'} for the Student's t ## family, or @code{'Clayton'} for the Clayton family. ## ## @item ## @var{theta} is the parameter of the copula. For the Gaussian and Student's t ## copula, @var{theta} must be a correlation matrix. For bivariate copulas ## @var{theta} can also be a correlation coefficient. For the Clayton family, ## @var{theta} must be a vector with the same number of elements as samples to ## be generated or be scalar. ## ## @item ## @var{nu} is the degrees of freedom for the Student's t family. @var{nu} must ## be a vector with the same number of elements as samples to be generated or ## be scalar. ## ## @item ## @var{n} is the number of rows of the matrix to be generated. @var{n} must be ## a non-negative integer and corresponds to the number of samples to be ## generated. ## ## @item ## @var{d} is the number of columns of the matrix to be generated. @var{d} must ## be a positive integer and corresponds to the dimension of the copula. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{x} is a matrix of random samples from the copula with @var{n} samples ## of distribution dimension @var{d}. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## theta = 0.5; ## x = copularnd ("Gaussian", theta); ## @end group ## ## @group ## theta = 0.5; ## nu = 2; ## x = copularnd ("t", theta, nu); ## @end group ## ## @group ## theta = 0.5; ## n = 2; ## x = copularnd ("Clayton", theta, n); ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Roger B. Nelsen. @cite{An Introduction to Copulas}. Springer, New York, ## second edition, 2006. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Random samples from a copula family function x = copularnd (family, theta, nu, n) # Check arguments if (nargin < 2) print_usage (); endif if (! ischar (family)) error ("copularnd: family must be one of 'Gaussian', 't', and 'Clayton'"); endif lower_family = lower (family); # Check family and copula parameters switch (lower_family) case {"gaussian"} # Gaussian family if (isscalar (theta)) # Expand a scalar to a correlation matrix theta = [1, theta; theta, 1]; endif if (! ismatrix (theta) || any (diag (theta) != 1) || any (any (theta != theta')) || min (eig (theta)) <= 0) error ("copularnd: theta must be a correlation matrix"); endif if (nargin > 3) d = n; if (! isscalar (d) || d != size (theta, 1)) error ("copularnd: d must correspond to dimension of theta"); endif else d = size (theta, 1); endif if (nargin < 3) n = 1; else n = nu; if (! isscalar (n) || (n < 0) || round (n) != n) error ("copularnd: n must be a non-negative integer"); endif endif case {"t"} # Student's t family if (nargin < 3) print_usage (); endif if (isscalar (theta)) # Expand a scalar to a correlation matrix theta = [1, theta; theta, 1]; endif if (! ismatrix (theta) || any (diag (theta) != 1) || any (any (theta != theta')) || min (eig (theta)) <= 0) error ("copularnd: theta must be a correlation matrix"); endif if (! isscalar (nu) && (! isvector (nu) || length (nu) != n)) error ("copularnd: nu must be a vector with the same number of rows as x or be scalar"); endif nu = nu(:); if (nargin < 4) n = 1; else if (! isscalar (n) || (n < 0) || round (n) != n) error ("copularnd: n must be a non-negative integer"); endif endif case {"clayton"} # Archimedian one parameter family if (nargin < 4) # Default is bivariate d = 2; else d = n; if (! isscalar (d) || (d < 2) || round (d) != d) error ("copularnd: d must be an integer greater than 1"); endif endif if (nargin < 3) # Default is one sample n = 1; else n = nu; if (! isscalar (n) || (n < 0) || round (n) != n) error ("copularnd: n must be a non-negative integer"); endif endif if (! isvector (theta) || (! isscalar (theta) && size (theta, 1) != n)) error ("copularnd: theta must be a column vector with the number of rows equal to n or be scalar"); endif if (n > 1 && isscalar (theta)) theta = repmat (theta, n, 1); endif otherwise error ("copularnd: unknown copula family '%s'", family); endswitch if (n == 0) # Input is empty x = zeros (0, d); else # Draw random samples according to family switch (lower_family) case {"gaussian"} # The Gaussian family x = normcdf (mvnrnd (zeros (1, d), theta, n), 0, 1); # No parameter bounds check k = []; case {"t"} # The Student's t family x = tcdf (mvtrnd (theta, nu, n), nu); # No parameter bounds check k = []; case {"clayton"} # The Clayton family u = rand (n, d); if (d == 2) x = zeros (n, 2); # Conditional distribution method for the bivariate case which also # works for theta < 0 x(:, 1) = u(:, 1); x(:, 2) = (1 + u(:, 1) .^ (-theta) .* (u(:, 2) .^ (-theta ./ (1 + theta)) - 1)) .^ (-1 ./ theta); else # Apply the algorithm by Marshall and Olkin: # Frailty distribution for Clayton copula is gamma y = randg (1 ./ theta, n, 1); x = (1 - log (u) ./ repmat (y, 1, d)) .^ (-1 ./ repmat (theta, 1, d)); endif k = find (theta == 0); if (any (k)) # Produkt copula at columns k x(k, :) = u(k, :); endif # Continue argument check if (d == 2) k = find (! (theta >= -1) | ! (theta < inf)); else k = find (! (theta >= 0) | ! (theta < inf)); endif endswitch # Out of bounds parameters if (any (k)) x(k, :) = NaN; endif endif endfunction %!test %! theta = 0.5; %! x = copularnd ("Gaussian", theta); %! assert (size (x), [1, 2]); %! assert (all ((x >= 0) & (x <= 1))); %!test %! theta = 0.5; %! nu = 2; %! x = copularnd ("t", theta, nu); %! assert (size (x), [1, 2]); %! assert (all ((x >= 0) & (x <= 1))); %!test %! theta = 0.5; %! x = copularnd ("Clayton", theta); %! assert (size (x), [1, 2]); %! assert (all ((x >= 0) & (x <= 1))); %!test %! theta = 0.5; %! n = 2; %! x = copularnd ("Clayton", theta, n); %! assert (size (x), [n, 2]); %! assert (all ((x >= 0) & (x <= 1))); %!test %! theta = [1; 2]; %! n = 2; %! d = 3; %! x = copularnd ("Clayton", theta, n, d); %! assert (size (x), [n, d]); %! assert (all ((x >= 0) & (x <= 1))); statistics-1.4.1/inst/PaxHeaders.29769/normalise_distribution.m0000644000000000000000000000006213443447555021427 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/normalise_distribution.m0000644000175000017500000002142613443447555022143 0ustar00johndjohnd00000000000000## Copyright (C) 2011 Alexander Klein ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn{Function File} {@var{NORMALISED} =} normalise_distribution (@var{DATA}) ## @deftypefnx{Function File} {@var{NORMALISED} =} normalise_distribution (@var{DATA}, @var{DISTRIBUTION}) ## @deftypefnx{Function File} {@var{NORMALISED} =} normalise_distribution (@var{DATA}, @var{DISTRIBUTION}, @var{DIMENSION}) ## ## Transform a set of data so as to be N(0,1) distributed according to an idea ## by van Albada and Robinson. ## This is achieved by first passing it through its own cumulative distribution ## function (CDF) in order to get a uniform distribution, and then mapping ## the uniform to a normal distribution. ## The data must be passed as a vector or matrix in @var{DATA}. ## If the CDF is unknown, then [] can be passed in @var{DISTRIBUTION}, and in ## this case the empirical CDF will be used. ## Otherwise, if the CDFs for all data are known, they can be passed in ## @var{DISTRIBUTION}, ## either in the form of a single function name as a string, ## or a single function handle, ## or a cell array consisting of either all function names as strings, ## or all function handles. ## In the latter case, the number of CDFs passed must match the number ## of rows, or columns respectively, to normalise. ## If the data are passed as a matrix, then the transformation will ## operate either along the first non-singleton dimension, ## or along @var{DIMENSION} if present. ## ## Notes: ## The empirical CDF will map any two sets of data ## having the same size and their ties in the same places after sorting ## to some permutation of the same normalised data: ## @example ## @code{normalise_distribution([1 2 2 3 4])} ## @result{} -1.28 0.00 0.00 0.52 1.28 ## ## @code{normalise_distribution([1 10 100 10 1000])} ## @result{} -1.28 0.00 0.52 0.00 1.28 ## @end example ## ## Original source: ## S.J. van Albada, P.A. Robinson ## "Transformation of arbitrary distributions to the ## normal distribution with application to EEG ## test-retest reliability" ## Journal of Neuroscience Methods, Volume 161, Issue 2, ## 15 April 2007, Pages 205-211 ## ISSN 0165-0270, 10.1016/j.jneumeth.2006.11.004. ## (http://www.sciencedirect.com/science/article/pii/S0165027006005668) ## @end deftypefn function [ normalised ] = normalise_distribution ( data, distribution, dimension ) if ( nargin < 1 || nargin > 3 ) print_usage; elseif ( !ismatrix ( data ) || length ( size ( data ) ) > 2 ) error ( "First argument must be a vector or matrix" ); end if ( nargin >= 2 ) if ( !isempty ( distribution ) ) #Wrap a single handle in a cell array. if ( strcmp ( typeinfo ( distribution ), typeinfo ( @(x)(x) ) ) ) distribution = { distribution }; #Do we have a string argument instead? elseif ( ischar ( distribution ) ) ##Is it a single string? if ( rows ( distribution ) == 1 ) distribution = { str2func( distribution ) }; else error ( ["Second argument cannot contain more than one string" ... " unless in a cell array"] ); end ##Do we have a cell array of distributions instead? elseif ( iscell ( distribution ) ) ##Does it consist of strings only? if ( all ( cellfun ( @ischar, distribution ) ) ) distribution = cellfun ( @str2func, distribution, "UniformOutput", false ); end ##Does it eventually consist of function handles only if ( !all ( cellfun ( @ ( h ) ( strcmp ( typeinfo ( h ), typeinfo ( @(x)(x) ) ) ), distribution ) ) ) error ( ["Second argument must contain either" ... " a single function name or handle or " ... " a cell array of either all function names or handles!"] ); end else error ( "Illegal second argument: ", typeinfo ( distribution ) ); end end else distribution = []; end if ( nargin == 3 ) if ( !isscalar ( dimension ) || ( dimension != 1 && dimension != 2 ) ) error ( "Third argument must be either 1 or 2" ); end else if ( isvector ( data ) && rows ( data ) == 1 ) dimension = 2; else dimension = 1; end end trp = ( dimension == 2 ); if ( trp ) data = data'; end r = rows ( data ); c = columns ( data ); normalised = NA ( r, c ); ##Do we know the distribution of the sample? if ( isempty ( distribution ) ) precomputed_normalisation = []; for k = 1 : columns ( data ) ##Note that this line is in accordance with equation (16) in the ##original text. The author's original program, however, produces ##different values in the presence of ties, namely those you'd ##get replacing "last" by "first". [ uniq, indices ] = unique ( sort ( data ( :, k ) ), "last" ); ##Does the sample have ties? if ( rows ( uniq ) != r ) ##Transform to uniform, then normal distribution. uniform = ( indices - 1/2 ) / r; normal = norminv ( uniform ); else ## Without ties everything is pretty much straightforward as ## stated in the text. if ( isempty ( precomputed_normalisation ) ) precomputed_normalisation = norminv ( 1 / (2*r) : 1/r : 1 - 1 / (2*r) ); end normal = precomputed_normalisation; end #Find the original indices in the unsorted sample. #This somewhat quirky way of doing it is still faster than #using a for-loop. [ ignore, ignore, target_indices ] = unique ( data (:, k ) ); #Put normalised values in the places where they belong. f_remap = @( k ) ( normal ( k ) ); normalised ( :, k ) = arrayfun ( f_remap, target_indices ); end else ##With known distributions, everything boils down to a few lines of code ##The same distribution for all data? if ( all ( size ( distribution ) == 1 ) ) normalised = norminv ( distribution {1,1} ( data ) ); elseif ( length ( vec ( distribution ) ) == c ) for k = 1 : c normalised ( :, k ) = norminv ( distribution { k } ( data ) ( :, k ) ); end else error ( "Number of distributions does not match data size! ") end end if ( trp ) normalised = normalised'; end endfunction %!test %! v = normalise_distribution ( [ 1 2 3 ], [], 1 ); %! assert ( v, [ 0 0 0 ] ) %!test %! v = normalise_distribution ( [ 1 2 3 ], [], 2 ); %! assert ( v, norminv ( [ 1 3 5 ] / 6 ), 3 * eps ) %!test %! v = normalise_distribution ( [ 1 2 3 ]', [], 2 ); %! assert ( v, [ 0 0 0 ]' ) %!test %! v = normalise_distribution ( [ 1 2 3 ]' , [], 1 ); %! assert ( v, norminv ( [ 1 3 5 ]' / 6 ), 3 * eps ) %!test %! v = normalise_distribution ( [ 1 1 2 2 3 3 ], [], 2 ); %! assert ( v, norminv ( [ 3 3 7 7 11 11 ] / 12 ), 3 * eps ) %!test %! v = normalise_distribution ( [ 1 1 2 2 3 3 ]', [], 1 ); %! assert ( v, norminv ( [ 3 3 7 7 11 11 ]' / 12 ), 3 * eps ) %!test %! A = randn ( 10 ); %! N = normalise_distribution ( A, @normcdf ); %! assert ( A, N, 1000 * eps ) %!xtest %! A = exprnd ( 1, 100 ); %! N = normalise_distribution ( A, @ ( x ) ( expcdf ( x, 1 ) ) ); %! assert ( mean ( vec ( N ) ), 0, 0.1 ) %! assert ( std ( vec ( N ) ), 1, 0.1 ) %!xtest %! A = rand (1000,1); %! N = normalise_distribution ( A, "unifcdf" ); %! assert ( mean ( vec ( N ) ), 0, 0.1 ) %! assert ( std ( vec ( N ) ), 1, 0.1 ) %!xtest %! A = [rand(1000,1), randn( 1000, 1)]; %! N = normalise_distribution ( A, { "unifcdf", "normcdf" } ); %! assert ( mean ( N ), [ 0, 0 ], 0.1 ) %! assert ( std ( N ), [ 1, 1 ], 0.1 ) %!xtest %! A = [rand(1000,1), randn( 1000, 1), exprnd( 1, 1000, 1 )]'; %! N = normalise_distribution ( A, { @unifcdf; @normcdf; @( x )( expcdf ( x, 1 ) ) }, 2 ); %! assert ( mean ( N, 2 ), [ 0, 0, 0 ]', 0.1 ) %! assert ( 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 ( mean ( N ), [ 0 0 0 0.38 0.38 0.38 0 0 0 ], 0.1 ); %! assert ( var ( N ), [ 1 1 1 2.59 2.59 2.59 1 1 1 ], 0.1 ); %!test %! fail ("normalise_distribution( zeros ( 3, 4 ), { @unifcdf; @normcdf; @( x )( expcdf ( x, 1 ) ) } )", ... %! "Number of distributions does not match data size!"); statistics-1.4.1/inst/PaxHeaders.29769/raylstat.m0000644000000000000000000000006213443447555016502 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/raylstat.m0000644000175000017500000000477213443447555017223 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} raylstat (@var{sigma}) ## Compute mean and variance of the Rayleigh distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{sigma} is the parameter of the Rayleigh distribution. The elements ## of @var{sigma} must be positive. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the Rayleigh distribution. ## ## @item ## @var{v} is the variance of the Rayleigh distribution. ## @end itemize ## ## @subheading Example ## ## @example ## @group ## sigma = 1:6; ## [m, v] = raylstat (sigma) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the Rayleigh distribution function [m, v] = raylstat (sigma) # Check arguments if (nargin != 1) print_usage (); endif if (! isempty (sigma) && ! ismatrix (sigma)) error ("raylstat: sigma must be a numeric matrix"); endif # Calculate moments m = sigma .* sqrt (pi ./ 2); v = (2 - pi ./ 2) .* sigma .^ 2; # Continue argument check k = find (! (sigma > 0)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!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 (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/gpcdf.m0000644000000000000000000000006213443447555015722 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gpcdf.m0000644000175000017500000001510613443447555016434 0ustar00johndjohnd00000000000000## Copyright (C) 2018 John Donoghue ## Copyright (C) 2016 Dag Lyberg ## Copyright (C) 1997-2015 Kurt Hornik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} gpcdf (@var{x}, @var{shape}, @var{scale}, @var{location}) ## Compute the cumulative distribution function (CDF) at @var{x} of the ## generalized Pareto distribution with parameters @var{location}, @var{scale}, ## and @var{shape}. ## @end deftypefn ## Author: Dag Lyberg ## Description: PDF of the generalized Pareto distribution function cdf = gpcdf (x, shape, scale, location) if (nargin != 4) print_usage (); endif if (! isscalar (location) || ! isscalar (scale) || ! isscalar (shape)) [retval, x, location, scale, shape] = ... common_size (x, location, scale, shape); if (retval > 0) error ("gpcdf: X, LOCATION, SCALE and SHAPE must be of common size or scalars"); endif endif if (iscomplex (x) || iscomplex (location) || iscomplex (scale) ... || iscomplex (shape)) error ("gpcdf: X, LOCATION, SCALE and SHAPE must not be complex"); endif if (isa (x, "single") || isa (location, "single") || isa (scale, "single") ... || isa (shape, "single")) cdf = zeros (size (x), "single"); else cdf = zeros (size (x)); endif k = isnan (x) | ! (-Inf < location) | ! (location < Inf) | ! (scale > 0) ... | ! (-Inf < shape) | ! (shape < Inf); cdf(k) = NaN; k = (x == Inf) & (-Inf < location) & (location < Inf) & (scale > 0) ... & (-Inf < shape) & (shape < Inf); cdf(k) = 1; k = (-Inf < x) & (x < Inf) & (-Inf < location) & (location < Inf) ... & (scale > 0) & (scale < Inf) & (-Inf < shape) & (shape < Inf); if (isscalar (location) && isscalar (scale) && isscalar (shape)) z = (x - location) / scale; j = k & (shape == 0) & (z >= 0); if (any (j)) cdf(j) = 1 - exp (-z(j)); endif j = k & (shape > 0) & (z >= 0); if (any (j)) cdf(j) = 1 - (shape * z(j) + 1).^(-1 / shape); endif if (shape < 0) j = k & (shape < 0) & (0 <= z) & (z <= -1 ./ shape); if (any (j)) cdf(j) = 1 - (shape * z(j) + 1).^(-1 / shape); endif endif else z = (x - location) ./ scale; j = k & (shape == 0) & (z >= 0); if (any (j)) cdf(j) = 1 - exp (-z(j)); endif j = k & (shape > 0) & (z >= 0); if (any (j)) cdf(j) = 1 - (shape(j) .* z(j) + 1).^(-1 ./ shape(j)); endif if (any (shape < 0)) j = k & (shape < 0) & (0 <= z) & (z <= -1 ./ shape); if (any (j)) cdf(j) = 1 - (shape(j) .* z(j) + 1).^(-1 ./ shape(j)); endif endif endif endfunction %!shared x,y1,y2,y3 %! x = [-Inf, -1, 0, 1/2, 1, Inf]; %! y1 = [0, 0, 0, 0.3934693402873666, 0.6321205588285577, 1]; %! y2 = [0, 0, 0, 1/3, 1/2, 1]; %! y3 = [0, 0, 0, 1/2, 1, 1]; %! seps = eps('single')*5; %!assert (gpcdf (x, zeros (1,6), ones (1,6), zeros (1,6)), y1, eps) %!assert (gpcdf (x, 0, 1, zeros (1,6)), y1, eps) %!assert (gpcdf (x, 0, ones (1,6), 0), y1, eps) %!assert (gpcdf (x, zeros (1,6), 1, 0), y1, eps) %!assert (gpcdf (x, 0, 1, 0), y1, eps) %!assert (gpcdf (x, 0, 1, [0, 0, 0, NaN, 0, 0]), [y1(1:3), NaN, y1(5:6)], eps) %!assert (gpcdf (x, 0, [1, 1, 1, NaN, 1, 1], 0), [y1(1:3), NaN, y1(5:6)], eps) %!assert (gpcdf (x, [0, 0, 0, NaN, 0, 0], 1, 0), [y1(1:3), NaN, y1(5:6)], eps) %!assert (gpcdf ([x(1:3), NaN, x(5:6)], 0, 1, 0), [y1(1:3), NaN, y1(5:6)], eps) %!assert (gpcdf (x, ones (1,6), ones (1,6), zeros (1,6)), y2, eps) %!assert (gpcdf (x, 1, 1, zeros (1,6)), y2, eps) %!assert (gpcdf (x, 1, ones (1,6), 0), y2, eps) %!assert (gpcdf (x, ones (1,6), 1, 0), y2, eps) %!assert (gpcdf (x, 1, 1, 0), y2, eps) %!assert (gpcdf (x, 1, 1, [0, 0, 0, NaN, 0, 0]), [y2(1:3), NaN, y2(5:6)], eps) %!assert (gpcdf (x, 1, [1, 1, 1, NaN, 1, 1], 0), [y2(1:3), NaN, y2(5:6)], eps) %!assert (gpcdf (x, [1, 1, 1, NaN, 1, 1], 1, 0), [y2(1:3), NaN, y2(5:6)], eps) %!assert (gpcdf ([x(1:3), NaN, x(5:6)], 1, 1, 0), [y2(1:3), NaN, y2(5:6)], eps) %!assert (gpcdf (x, -ones (1,6), ones (1,6), zeros (1,6)), y3, eps) %!assert (gpcdf (x, -1, 1, zeros (1,6)), y3, eps) %!assert (gpcdf (x, -1, ones (1,6), 0), y3, eps) %!assert (gpcdf (x, -ones (1,6), 1, 0), y3, eps) %!assert (gpcdf (x, -1, 1, 0), y3, eps) %!assert (gpcdf (x, -1, 1, [0, 0, 0, NaN, 0, 0]), [y1(1:3), NaN, y3(5:6)], eps) %!assert (gpcdf (x, -1, [1, 1, 1, NaN, 1, 1], 0), [y1(1:3), NaN, y3(5:6)], eps) %!assert (gpcdf (x, [-1, -1, -1, NaN, -1, -1], 1, 0), [y1(1:3), NaN, y3(5:6)], eps) %!assert (gpcdf ([x(1:3), NaN, x(5:6)], -1, 1, 0), [y1(1:3), NaN, y3(5:6)], eps) ## Test class of input preserved %!assert (gpcdf (single ([x, NaN]), 0, 1, 0), single ([y1, NaN]), eps('single')) %!assert (gpcdf ([x, NaN], 0, 1, single (0)), single ([y1, NaN]), eps('single')) %!assert (gpcdf ([x, NaN], 0, single (1), 0), single ([y1, NaN]), eps('single')) %!assert (gpcdf ([x, NaN], single (0), 1, 0), single ([y1, NaN]), eps('single')) %!assert (gpcdf (single ([x, NaN]), 1, 1, 0), single ([y2, NaN]), eps('single')) %!assert (gpcdf ([x, NaN], 1, 1, single (0)), single ([y2, NaN]), eps('single')) %!assert (gpcdf ([x, NaN], 1, single (1), 0), single ([y2, NaN]), eps('single')) %!assert (gpcdf ([x, NaN], single (1), 1, 0), single ([y2, NaN]), eps('single')) %!assert (gpcdf (single ([x, NaN]), -1, 1, 0), single ([y3, NaN]), eps('single')) %!assert (gpcdf ([x, NaN], -1, 1, single (0)), single ([y3, NaN]), eps('single')) %!assert (gpcdf ([x, NaN], -1, single (1), 0), single ([y3, NaN]), eps('single')) %!assert (gpcdf ([x, NaN], single (-1), 1, 0), single ([y3, NaN]), eps('single')) ## Test input validation %!error gpcdf () %!error gpcdf (1) %!error gpcdf (1,2) %!error gpcdf (1,2,3) %!error gpcdf (1,2,3,4,5) %!error gpcdf (ones (3), ones (2), ones (2), ones (2)) %!error gpcdf (ones (2), ones (2), ones (2), ones (3)) %!error gpcdf (ones (2), ones (2), ones (3), ones (2)) %!error gpcdf (ones (2), ones (3), ones (2), ones (2)) %!error gpcdf (i, 2, 2, 2) %!error gpcdf (2, i, 2, 2) %!error gpcdf (2, 2, i, 2) %!error gpcdf (2, 2, 2, i) statistics-1.4.1/inst/PaxHeaders.29769/raylinv.m0000644000000000000000000000006213443447555016323 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/raylinv.m0000644000175000017500000000636313443447555017042 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{x} =} raylinv (@var{p}, @var{sigma}) ## Compute the quantile of the Rayleigh distribution. The quantile is the ## inverse of the cumulative distribution function. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{p} is the cumulative distribution. The elements of @var{p} must be ## probabilities. ## ## @item ## @var{sigma} is the parameter of the Rayleigh distribution. The elements ## of @var{sigma} must be positive. ## @end itemize ## @var{p} and @var{sigma} must be of common size or one of them must be ## scalar. ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{x} is the quantile of the Rayleigh distribution at each element of ## @var{p} and corresponding parameter @var{sigma}. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## p = 0:0.1:0.5; ## sigma = 1:6; ## x = raylinv (p, sigma) ## @end group ## ## @group ## x = raylinv (p, 0.5) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. pages 104 and 148, McGraw-Hill, New York, second edition, ## 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Quantile of the Rayleigh distribution function x = raylinv (p, sigma) # Check arguments if (nargin != 2) print_usage (); endif if (! isempty (p) && ! ismatrix (p)) error ("raylinv: p must be a numeric matrix"); endif if (! isempty (sigma) && ! ismatrix (sigma)) error ("raylinv: sigma must be a numeric matrix"); endif if (! isscalar (p) || ! isscalar (sigma)) [retval, p, sigma] = common_size (p, sigma); if (retval > 0) error ("raylinv: p and sigma must be of common size or scalar"); endif endif # Calculate quantile x = sqrt (-2 .* log (1 - p) .* sigma .^ 2); k = find (p == 1); if (any (k)) x(k) = Inf; endif # Continue argument check k = find (! (p >= 0) | ! (p <= 1) | ! (sigma > 0)); if (any (k)) x(k) = NaN; endif endfunction %!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 (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 (x, expected_x, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/mvtrnd.m0000644000000000000000000000006213443447555016151 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/mvtrnd.m0000644000175000017500000001032213443447555016656 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Arno Onken , Iñigo Urteaga ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{x} =} mvtrnd (@var{sigma}, @var{nu}) ## @deftypefnx {Function File} {@var{x} =} mvtrnd (@var{sigma}, @var{nu}, @var{n}) ## Generate random samples from the multivariate t-distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{sigma} is the matrix of correlation coefficients. If there are any ## non-unit diagonal elements then @var{sigma} will be normalized, so that the ## resulting covariance of the obtained samples @var{x} follows: ## @code{cov (x) = nu/(nu-2) * sigma ./ (sqrt (diag (sigma) * diag (sigma)))}. ## In order to obtain samples distributed according to a standard multivariate ## t-distribution, @var{sigma} must be equal to the identity matrix. To generate ## multivariate t-distribution samples @var{x} with arbitrary covariance matrix ## @var{sigma}, the following scaling might be used: ## @code{x = mvtrnd (sigma, nu, n) * diag (sqrt (diag (sigma)))}. ## ## @item ## @var{nu} is the degrees of freedom for the multivariate t-distribution. ## @var{nu} must be a vector with the same number of elements as samples to be ## generated or be scalar. ## ## @item ## @var{n} is the number of rows of the matrix to be generated. @var{n} must be ## a non-negative integer and corresponds to the number of samples to be ## generated. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{x} is a matrix of random samples from the multivariate t-distribution ## with @var{n} row samples. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## sigma = [1, 0.5; 0.5, 1]; ## nu = 3; ## n = 10; ## x = mvtrnd (sigma, nu, n); ## @end group ## ## @group ## sigma = [1, 0.5; 0.5, 1]; ## nu = [2; 3]; ## n = 2; ## x = mvtrnd (sigma, nu, 2); ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, 2001. ## ## @item ## Samuel Kotz and Saralees Nadarajah. @cite{Multivariate t Distributions and ## Their Applications}. Cambridge University Press, Cambridge, 2004. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Random samples from the multivariate t-distribution function x = mvtrnd (sigma, nu, n) # Check arguments if (nargin < 2) print_usage (); endif if (! ismatrix (sigma) || any (any (sigma != sigma')) || min (eig (sigma)) <= 0) error ("mvtrnd: sigma must be a positive definite matrix"); endif if (!isvector (nu) || any (nu <= 0)) error ("mvtrnd: nu must be a positive scalar or vector"); endif nu = nu(:); if (nargin > 2) if (! isscalar (n) || n < 0 | round (n) != n) error ("mvtrnd: n must be a non-negative integer") endif if (isscalar (nu)) nu = nu * ones (n, 1); else if (length (nu) != n) error ("mvtrnd: n must match the length of nu") endif endif else n = length (nu); endif # Normalize sigma if (any (diag (sigma) != 1)) sigma = sigma ./ sqrt (diag (sigma) * diag (sigma)'); endif # Dimension d = size (sigma, 1); # Draw samples y = mvnrnd (zeros (1, d), sigma, n); u = repmat (chi2rnd (nu), 1, d); x = y .* sqrt (repmat (nu, 1, d) ./ u); endfunction %!test %! sigma = [1, 0.5; 0.5, 1]; %! nu = 3; %! n = 10; %! x = mvtrnd (sigma, nu, n); %! assert (size (x), [10, 2]); %!test %! sigma = [1, 0.5; 0.5, 1]; %! nu = [2; 3]; %! n = 2; %! x = mvtrnd (sigma, nu, 2); %! assert (size (x), [2, 2]); statistics-1.4.1/inst/PaxHeaders.29769/iwishpdf.m0000644000000000000000000000006213443447555016454 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/iwishpdf.m0000644000175000017500000000545113443447555017170 0ustar00johndjohnd00000000000000## Copyright (C) 2013 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along with Octave; see the file COPYING. If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {} @var{y} = iwishpdf (@var{W}, @var{Tau}, @var{df}, @var{log_y}=false) ## Compute the probability density function of the Wishart distribution ## ## Inputs: A @var{p} x @var{p} matrix @var{W} where to find the PDF and the @var{p} x @var{p} positive definite scale matrix @var{Tau} and scalar degrees of freedom parameter @var{df} characterizing the inverse Wishart distribution. (For the density to be finite, need @var{df} > (@var{p} - 1).) ## If the flag @var{log_y} is set, return the log probability density -- this helps avoid underflow when the numerical value of the density is very small ## ## Output: @var{y} is the probability density of Wishart(@var{Sigma}, @var{df}) at @var{W}. ## ## @seealso{iwishrnd, wishpdf} ## @end deftypefn ## Author: Nir Krakauer ## Description: Compute the probability density function of the inverse Wishart distribution function [y] = iwishpdf(W, Tau, df, log_y=false) if (nargin < 3) print_usage (); endif p = size(Tau, 1); if (df <= (p - 1)) error('df too small, no finite densities exist') endif #calculate the logarithm of G_d(df/2), the multivariate gamma function g = (p * (p-1) / 4) * log(pi); for i = 1:p g = g + log(gamma((df + (1 - i))/2)); #using lngamma_gsl(.) from the gsl package instead of log(gamma(.)) might help avoid underflow/overflow endfor C = chol(W); #use formulas for determinant of positive definite matrix for better efficiency and numerical accuracy logdet_W = 2*sum(log(diag(C))); logdet_Tau = 2*sum(log(diag(chol(Tau)))); y = -(df*p)/2 * log(2) + (df/2)*logdet_Tau - g - ((df + p + 1)/2)*logdet_W - trace(Tau*chol2inv(C))/2; if ~log_y y = exp(y); endif endfunction ##test results cross-checked against diwish function in R MCMCpack library %!assert(iwishpdf(4, 3, 3.1), 0.04226595, 1E-7); %!assert(iwishpdf([2 -0.3;-0.3 4], [1 0.3;0.3 1], 4), 1.60166e-05, 1E-10); %!assert(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); %% Test input validation %!error iwishpdf () %!error iwishpdf (1, 2) %!error iwishpdf (1, 2, 0) %!error wishpdf (1, 2) statistics-1.4.1/inst/PaxHeaders.29769/gamfit.m0000644000000000000000000000006213443447555016106 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gamfit.m0000644000175000017500000000324713443447555016623 0ustar00johndjohnd00000000000000## Author: Martijn van Oosterhout ## This program is granted to the public domain. ## -*- texinfo -*- ## @deftypefn {Function File} {@var{MLE} =} gamfit (@var{data}) ## Calculate gamma distribution parameters. ## ## Find the maximum likelihood estimators (@var{mle}s) of the Gamma distribution ## of @var{data}. @var{MLE} is a two element vector with shape parameter ## @var{A} and scale @var{B}. ## ## @seealso{gampdf, gaminv, gamrnd, gamlike} ## @end deftypefn ## This function works by minimizing the value of gamlike for the vector R. ## Just about any minimization function will work, all it has to do a ## minimize for one variable. Although the gamma distribution has two ## parameters, their product is the mean of the data. so a helper function ## for the search takes one parameter, calculates the other and then returns ## the value of gamlike. ## FIXME is this still true??? ## Note: Octave uses the inverse scale parameter, which is the opposite of ## Matlab. To work for Matlab, value of b needs to be inverted in a few ## places (marked with **) function res = gamfit(R) if (nargin != 1) print_usage; endif avg = mean(R); # This can be just about any search function. I choose this because it # seemed to be the only one that might work in this situaition... a=nmsmax( @gamfit_search, 1, [], [], avg, R ); b=a/avg; # ** res=[a 1/b]; endfunction # Helper function so we only have to minimize for one variable. Also to # inverting the output of gamlike, incase the optimisation function wants to # maximize rather than minimize. function res = gamfit_search( a, avg, R ) b=a/avg; # ** res = -gamlike([a 1/b], R); endfunction statistics-1.4.1/inst/PaxHeaders.29769/binostat.m0000644000000000000000000000006213443447555016462 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/binostat.m0000644000175000017500000000726613443447555017204 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## Copyright (C) 2015 Carnë Draug ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} binostat (@var{n}, @var{p}) ## Compute mean and variance of the binomial distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{n} is the first parameter of the binomial distribution. The elements ## of @var{n} must be natural numbers ## ## @item ## @var{p} is the second parameter of the binomial distribution. The ## elements of @var{p} must be probabilities ## @end itemize ## @var{n} and @var{p} must be of common size or one of them must be scalar ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the binomial distribution ## ## @item ## @var{v} is the variance of the binomial distribution ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## n = 1:6; ## p = 0:0.2:1; ## [m, v] = binostat (n, p) ## @end group ## ## @group ## [m, v] = binostat (n, 0.5) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the binomial distribution function [m, v] = binostat (n, p) if (nargin != 2) print_usage (); elseif (! isscalar (n) && ! isscalar (p) && ! size_equal (n, p)) error ("binostat: N and P must be of common size or scalar"); endif k = find (! (n > 0 & fix (n) == n & p >= 0 & p <= 1)); # Calculate moments m = n .* p; m(k) = NaN; if (nargout > 1) v = m .* (1 - p); v(k) = NaN; endif endfunction %!test %! n = 1:6; %! p = 0:0.2:1; %! [m, v] = binostat (n, p); %! 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 (m, expected_m, 0.001); %! assert (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 (m, expected_m, 0.001); %! assert (v, expected_v, 0.001); %!test %! n = [-Inf -3 5 0.5 3 NaN 100, Inf]; %! [m, v] = binostat (n, 0.5); %! assert (isnan (m), [true true false true false true false false]) %! assert (isnan (v), [true true false true false true false false]) %! assert (m(end), Inf); %! assert (v(end), Inf); %!assert (nthargout (1:2, @binostat, 5, []), {[], []}) %!assert (nthargout (1:2, @binostat, [], 5), {[], []}) %!assert (nthargout (1:2, @binostat, "", 5), {[], []}) %!assert (nthargout (1:2, @binostat, true, 5), {NaN, NaN}) %!assert (nthargout (1:2, @binostat, 5, true), {5, 0}) %!assert (size (binostat (randi (100, 10, 5, 4), rand (10, 5, 4))), [10 5 4]) %!assert (size (binostat (randi (100, 10, 5, 4), 7)), [10 5 4]) statistics-1.4.1/inst/PaxHeaders.29769/nanstd.m0000644000000000000000000000006213443447555016126 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nanstd.m0000644000175000017500000000614213443447555016640 0ustar00johndjohnd00000000000000## Copyright (C) 2001 Paul Kienzle ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{v} =} nanstd (@var{X}) ## @deftypefnx{Function File} {@var{v} =} nanstd (@var{X}, @var{opt}) ## @deftypefnx{Function File} {@var{v} =} nanstd (@var{X}, @var{opt}, @var{dim}) ## Compute the standard deviation while ignoring NaN values. ## ## @code{nanstd} is identical to the @code{std} function except that NaN values are ## ignored. If all values are NaN, the standard deviation is returned as NaN. ## If there is only a single non-NaN value, the deviation is returned as 0. ## ## The argument @var{opt} determines the type of normalization to use. Valid values ## are ## ## @table @asis ## @item 0: ## normalizes with @math{N-1}, provides the square root of best unbiased estimator of ## the variance [default] ## @item 1: ## normalizes with @math{N}, this provides the square root of the second moment around ## the mean ## @end table ## ## The third argument @var{dim} determines the dimension along which the standard ## deviation is calculated. ## ## @seealso{std, nanmin, nanmax, nansum, nanmedian, nanmean} ## @end deftypefn function v = nanstd (X, opt, varargin) if nargin < 1 print_usage; else if nargin < 3 dim = min(find(size(X)>1)); if isempty(dim), dim=1; endif; else dim = varargin{1}; endif if ((nargin < 2) || isempty(opt)) opt = 0; endif ## determine the number of non-missing points in each data set n = sum (!isnan(X), varargin{:}); ## replace missing data with zero and compute the mean X(isnan(X)) = 0; meanX = sum (X, varargin{:}) ./ n; ## subtract the mean from the data and compute the sum squared sz = ones(1,length(size(X))); sz(dim) = size(X,dim); v = sumsq (X - repmat(meanX,sz), varargin{:}); ## because the missing data was set to zero each missing data ## point will contribute (-meanX)^2 to sumsq, so remove these v = v - (meanX .^ 2) .* (size(X,dim) - n); if (opt == 0) ## compute the standard deviation from the corrected sumsq using ## max(n-1,1) in the denominator so that the std for a single point is 0 v = sqrt ( v ./ max(n - 1, 1) ); elseif (opt == 1) ## compute the standard deviation from the corrected sumsq v = sqrt ( v ./ n ); else error ("std: unrecognized normalization type"); endif ## make sure that we return a real number v = real (v); endif endfunction statistics-1.4.1/inst/PaxHeaders.29769/nansum.m0000644000000000000000000000006213443447555016140 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nansum.m0000644000175000017500000000402413443447555016647 0ustar00johndjohnd00000000000000## Copyright (C) 2001 Paul Kienzle ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Built-in Function} {} nansum (@var{x}) ## @deftypefnx {Built-in Function} {} nansum (@var{x}, @var{dim}) ## @deftypefnx {Built-in Function} {} nansum (@dots{}, @qcode{"native"}) ## @deftypefnx {Built-in Function} {} nansum (@dots{}, @qcode{"double"}) ## @deftypefnx {Built-in Function} {} nansum (@dots{}, @qcode{"extra"}) ## Compute the sum while ignoring NaN values. ## ## @code{nansum} is identical to the @code{sum} function except that NaN ## values are treated as 0 and so ignored. If all values are NaN, the sum is ## returned as 0. ## ## See help text of @code{sum} for details on the options. ## ## @seealso{sum, nanmin, nanmax, nanmean, nanmedian} ## @end deftypefn function v = nansum (X, varargin) if (nargin < 1) print_usage (); else X(isnan (X)) = 0; v = sum (X, varargin{:}); endif endfunction %!assert (nansum ([2 4 NaN 7]), 13) %!assert (nansum ([2 4 NaN Inf]), Inf) %!assert (nansum ([1 NaN 3; NaN 5 6; 7 8 NaN]), [8 13 9]) %!assert (nansum ([1 NaN 3; NaN 5 6; 7 8 NaN], 2), [4; 11; 15]) %!assert (nansum (single ([1 NaN 3; NaN 5 6; 7 8 NaN])), single ([8 13 9])) %!assert (nansum (single ([1 NaN 3; NaN 5 6; 7 8 NaN]), "double"), [8 13 9]) %!assert (nansum (uint8 ([2 4 1 7])), 14) %!assert (nansum (uint8 ([2 4 1 7]), "native"), uint8 (14)) %!assert (nansum (uint8 ([2 4 1 7])), 14) statistics-1.4.1/inst/PaxHeaders.29769/nanmin.m0000644000000000000000000000006213443447555016117 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nanmin.m0000644000175000017500000000352013443447555016626 0ustar00johndjohnd00000000000000## Copyright (C) 2001 Paul Kienzle ## Copyright (C) 2003 Alois Schloegl ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{v}, @var{idx}] =} nanmin (@var{X}) ## @deftypefnx{Function File} {[@var{v}, @var{idx}] =} nanmin (@var{X}, @var{Y}) ## Find the minimal element while ignoring NaN values. ## ## @code{nanmin} is identical to the @code{min} function except that NaN values ## are ignored. If all values in a column are NaN, the minimum is ## returned as NaN rather than []. ## ## @seealso{min, nansum, nanmax, nanmean, nanmedian} ## @end deftypefn function [v, idx] = nanmin (X, Y, DIM) if nargin < 1 || nargin > 3 print_usage; elseif nargin == 1 || (nargin == 2 && isempty(Y)) nanvals = isnan(X); X(nanvals) = Inf; [v, idx] = min (X); v(all(nanvals)) = NaN; elseif (nargin == 3 && isempty(Y)) nanvals = isnan(X); X(nanvals) = Inf; [v, idx] = min (X,[],DIM); v(all(nanvals,DIM)) = NaN; else Xnan = isnan(X); Ynan = isnan(Y); X(Xnan) = Inf; Y(Ynan) = Inf; if (nargin == 3) [v, idx] = min(X,Y,DIM); else [v, idx] = min(X,Y); endif v(Xnan & Ynan) = NaN; endif endfunction statistics-1.4.1/inst/PaxHeaders.29769/mnrnd.m0000644000000000000000000000006213443447555015755 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/mnrnd.m0000644000175000017500000001334613443447555016473 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Arno Onken ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{x} =} mnrnd (@var{n}, @var{p}) ## @deftypefnx {Function File} {@var{x} =} mnrnd (@var{n}, @var{p}, @var{s}) ## Generate random samples from the multinomial distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{n} is the first parameter of the multinomial distribution. @var{n} can ## be scalar or a vector containing the number of trials of each multinomial ## sample. The elements of @var{n} must be non-negative integers. ## ## @item ## @var{p} is the second parameter of the multinomial distribution. @var{p} can ## be a vector with the probabilities of the categories or a matrix with each ## row containing the probabilities of a multinomial sample. If @var{p} has ## more than one row and @var{n} is non-scalar, then the number of rows of ## @var{p} must match the number of elements of @var{n}. ## ## @item ## @var{s} is the number of multinomial samples to be generated. @var{s} must ## be a non-negative integer. If @var{s} is specified, then @var{n} must be ## scalar and @var{p} must be a vector. ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{x} is a matrix of random samples from the multinomial distribution with ## corresponding parameters @var{n} and @var{p}. Each row corresponds to one ## multinomial sample. The number of columns, therefore, corresponds to the ## number of columns of @var{p}. If @var{s} is not specified, then the number ## of rows of @var{x} is the maximum of the number of elements of @var{n} and ## the number of rows of @var{p}. If a row of @var{p} does not sum to @code{1}, ## then the corresponding row of @var{x} will contain only @code{NaN} values. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## n = 10; ## p = [0.2, 0.5, 0.3]; ## x = mnrnd (n, p); ## @end group ## ## @group ## n = 10 * ones (3, 1); ## p = [0.2, 0.5, 0.3]; ## x = mnrnd (n, p); ## @end group ## ## @group ## n = (1:2)'; ## p = [0.2, 0.5, 0.3; 0.1, 0.1, 0.8]; ## x = mnrnd (n, p); ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, 2001. ## ## @item ## Merran Evans, Nicholas Hastings and Brian Peacock. @cite{Statistical ## Distributions}. pages 134-136, Wiley, New York, third edition, 2000. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Random samples from the multinomial distribution function x = mnrnd (n, p, s) # Check arguments if (nargin == 3) if (! isscalar (n) || n < 0 || round (n) != n) error ("mnrnd: n must be a non-negative integer"); endif if (! isvector (p) || any (p < 0 | p > 1)) error ("mnrnd: p must be a vector of probabilities"); endif if (! isscalar (s) || s < 0 || round (s) != s) error ("mnrnd: s must be a non-negative integer"); endif elseif (nargin == 2) if (isvector (p) && size (p, 1) > 1) p = p'; endif if (! isvector (n) || any (n < 0 | round (n) != n) || size (n, 2) > 1) error ("mnrnd: n must be a non-negative integer column vector"); endif if (! ismatrix (p) || isempty (p) || any (p < 0 | p > 1)) error ("mnrnd: p must be a non-empty matrix with rows of probabilities"); endif if (! isscalar (n) && size (p, 1) > 1 && length (n) != size (p, 1)) error ("mnrnd: the length of n must match the number of rows of p"); endif else print_usage (); endif # Adjust input sizes if (nargin == 3) n = n * ones (s, 1); p = repmat (p(:)', s, 1); elseif (nargin == 2) if (isscalar (n) && size (p, 1) > 1) n = n * ones (size (p, 1), 1); elseif (size (p, 1) == 1) p = repmat (p, length (n), 1); endif endif sz = size (p); # Upper bounds of categories ub = cumsum (p, 2); # Make sure that the greatest upper bound is 1 gub = ub(:, end); ub(:, end) = 1; # Lower bounds of categories lb = [zeros(sz(1), 1) ub(:, 1:(end-1))]; # Draw multinomial samples x = zeros (sz); for i = 1:sz(1) # Draw uniform random numbers r = repmat (rand (n(i), 1), 1, sz(2)); # Compare the random numbers of r to the cumulated probabilities of p and # count the number of samples for each category x(i, :) = sum (r <= repmat (ub(i, :), n(i), 1) & r > repmat (lb(i, :), n(i), 1), 1); endfor # Set invalid rows to NaN k = (abs (gub - 1) > 1e-6); x(k, :) = NaN; endfunction %!test %! n = 10; %! p = [0.2, 0.5, 0.3]; %! x = mnrnd (n, p); %! assert (size (x), size (p)); %! assert (all (x >= 0)); %! assert (all (round (x) == x)); %! assert (sum (x) == n); %!test %! n = 10 * ones (3, 1); %! p = [0.2, 0.5, 0.3]; %! x = mnrnd (n, p); %! assert (size (x), [length(n), length(p)]); %! assert (all (x >= 0)); %! assert (all (round (x) == x)); %! assert (all (sum (x, 2) == n)); %!test %! n = (1:2)'; %! p = [0.2, 0.5, 0.3; 0.1, 0.1, 0.8]; %! x = mnrnd (n, p); %! assert (size (x), size (p)); %! assert (all (x >= 0)); %! assert (all (round (x) == x)); %! assert (all (sum (x, 2) == n)); statistics-1.4.1/inst/PaxHeaders.29769/poisstat.m0000644000000000000000000000006213443447555016505 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/poisstat.m0000644000175000017500000000452713443447555017224 0ustar00johndjohnd00000000000000## Copyright (C) 2006, 2007 Arno Onken ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{v}] =} poisstat (@var{lambda}) ## Compute mean and variance of the Poisson distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{lambda} is the parameter of the Poisson distribution. The ## elements of @var{lambda} must be positive ## @end itemize ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{m} is the mean of the Poisson distribution ## ## @item ## @var{v} is the variance of the Poisson distribution ## @end itemize ## ## @subheading Example ## ## @example ## @group ## lambda = 1 ./ (1:6); ## [m, v] = poisstat (lambda) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC, ## 2001. ## ## @item ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic ## Processes}. McGraw-Hill, New York, second edition, 1984. ## @end enumerate ## @end deftypefn ## Author: Arno Onken ## Description: Moments of the Poisson distribution function [m, v] = poisstat (lambda) # Check arguments if (nargin != 1) print_usage (); endif if (! isempty (lambda) && ! ismatrix (lambda)) error ("poisstat: lambda must be a numeric matrix"); endif # Set moments m = lambda; v = lambda; # Continue argument check k = find (! (lambda > 0) | ! (lambda < Inf)); if (any (k)) m(k) = NaN; v(k) = NaN; endif endfunction %!test %! lambda = 1 ./ (1:6); %! [m, v] = poisstat (lambda); %! assert (m, lambda); %! assert (v, lambda); statistics-1.4.1/inst/PaxHeaders.29769/gevpdf.m0000644000000000000000000000006213443447555016112 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/gevpdf.m0000644000175000017500000000731413443447555016626 0ustar00johndjohnd00000000000000## Copyright (C) 2012 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} gevpdf (@var{x}, @var{k}, @var{sigma}, @var{mu}) ## Compute the probability density function of the generalized extreme value (GEV) distribution. ## ## @subheading Arguments ## ## @itemize @bullet ## @item ## @var{x} is the support. ## ## @item ## @var{k} is the shape parameter of the GEV distribution. (Also denoted gamma or xi.) ## @item ## @var{sigma} is the scale parameter of the GEV distribution. The elements ## of @var{sigma} must be positive. ## @item ## @var{mu} is the location parameter of the GEV distribution. ## @end itemize ## The inputs must be of common size, or some of them must be scalar. ## ## @subheading Return values ## ## @itemize @bullet ## @item ## @var{y} is the probability density of the GEV distribution at each ## element of @var{x} and corresponding parameter values. ## @end itemize ## ## @subheading Examples ## ## @example ## @group ## x = 0:0.5:2.5; ## sigma = 1:6; ## k = 1; ## mu = 0; ## y = gevpdf (x, k, sigma, mu) ## @end group ## ## @group ## y = gevpdf (x, k, 0.5, mu) ## @end group ## @end example ## ## @subheading References ## ## @enumerate ## @item ## Rolf-Dieter Reiss and Michael Thomas. @cite{Statistical Analysis of Extreme Values with Applications to Insurance, Finance, Hydrology and Other Fields}. Chapter 1, pages 16-17, Springer, 2007. ## ## @end enumerate ## @seealso{gevcdf, gevfit, gevinv, gevlike, gevrnd, gevstat} ## @end deftypefn ## Author: Nir Krakauer ## Description: PDF of the generalized extreme value distribution function y = gevpdf (x, k, sigma, mu) # Check arguments if (nargin != 4) print_usage (); endif if (isempty (x) || isempty (k) || isempty (sigma) || isempty (mu) || ~ismatrix (x) || ~ismatrix (k) || ~ismatrix (sigma) || ~ismatrix (mu)) error ("gevpdf: inputs must be numeric matrices"); endif [retval, x, k, sigma, mu] = common_size (x, k, sigma, mu); if (retval > 0) error ("gevpdf: inputs must be of common size or scalars"); endif z = 1 + k .* (x - mu) ./ sigma; # Calculate pdf y = exp(-(z .^ (-1 ./ k))) .* (z .^ (-1 - 1 ./ k)) ./ sigma; y(z <= 0) = 0; inds = (abs (k) < (eps^0.7)); %use a different formula if k is very close to zero if any(inds) z = (mu(inds) - x(inds)) ./ sigma(inds); y(inds) = exp(z-exp(z)) ./ sigma(inds); endif endfunction %!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 (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 (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 (y, expected_y, 0.001); statistics-1.4.1/inst/PaxHeaders.29769/vartest.m0000644000000000000000000000006213443447555016327 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/vartest.m0000644000175000017500000001067513443447555017047 0ustar00johndjohnd00000000000000## Copyright (C) 2014 Tony Richardson ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} vartest (@var{x}, @var{y}) ## @deftypefnx {Function File} {[@var{h}, @var{pval}, @var{ci}, @var{stats}] =} vartest (@var{x}, @var{y}, @var{Name}, @var{Value}) ## Perform a F-test for equal variances. ## ## If the second argument @var{y} is a vector, a paired-t test of the ## hypothesis @code{mean (@var{x}) = mean (@var{y})} is performed. ## ## The argument @qcode{"alpha"} can be used to specify the significance level ## of the test (the default value is 0.05). The string ## argument @qcode{"tail"}, can be used to select the desired alternative ## hypotheses. If @qcode{"alt"} is @qcode{"both"} (default) the null is ## tested against the two-sided alternative @code{mean (@var{x}) != @var{m}}. ## If @qcode{"alt"} is @qcode{"right"} the one-sided ## alternative @code{mean (@var{x}) > @var{m}} is considered. ## Similarly for @qcode{"left"}, the one-sided alternative @code{mean ## (@var{x}) < @var{m}} is considered. When @qcode{"vartype"} is @qcode{"equal"} ## the variances are assumed to be equal (this is the default). When ## @qcode{"vartype"} is @qcode{"unequal"} the variances are not assumed equal. ## When argument @var{x} is a matrix the @qcode{"dim"} argument can be ## used to selection the dimension over which to perform the test. ## (The default is the first non-singleton dimension.) ## ## If @var{h} is 0 the null hypothesis is accepted, if it is 1 the null ## hypothesis is rejected. The p-value of the test is returned in @var{pval}. ## A 100(1-alpha)% confidence interval is returned in @var{ci}. @var{stats} ## is a structure containing the value of the test statistic (@var{tstat}), ## the degrees of freedom (@var{df}) and the sample standard deviation ## (@var{sd}). ## ## @end deftypefn ## Author: Tony Richardson ## Description: Test for mean of a normal sample with known variance function [h, p, ci, stats] = vartest(x, v, varargin) % Set default arguments alpha = 0.05; tail = 'both'; % Find the first non-singleton dimension of x dim = min(find(size(x)~=1)); if isempty(dim), dim = 1; end i = 1; while ( i <= length(varargin) ) switch lower(varargin{i}) case 'alpha' i = i + 1; alpha = varargin{i}; case 'tail' i = i + 1; tail = varargin{i}; case 'dim' i = i + 1; dim = varargin{i}; otherwise error('Invalid Name argument.',[]); end i = i + 1; end if ~isa(tail, 'char') error('tail argument to vartest must be a string\n',[]); end s_var = var(x, 0, dim); df = size(x, dim) - 1; stats.chisqstat = df*s_var/v; % Based on the "tail" argument determine the P-value, the critical values, % and the confidence interval. switch lower(tail) case 'both' p = 2*min(chi2cdf(stats.chisqstat,df),1-chi2cdf(stats.chisqstat,df)); ci = [df*s_var ./ (chi2inv(1-alpha/2,df)); df*s_var ./ (chi2inv(alpha/2,df))]; case 'left' p = chi2cdf(stats.chisqstat,df); chi2crit = chi2inv(alpha,df); ci = [zeros(size(stats.chisqstat)); df*s_var ./ (chi2inv(alpha,df))]; case 'right' p = 1 - chi2cdf(stats.chisqstat,df); chi2crit = chi2inv(1-alpha,df); ci = [df*s_var ./ (chi2inv(1-alpha,df)); inf*ones(size(stats.chisqstat))]; otherwise error('Invalid fourth (tail) argument to vartest\n',[]); end % Reshape the ci array to match MATLAB shaping if and(isscalar(stats.chisqstat), dim==2) ci = ci(:)'; elseif size(stats.chisqstat,2) ## This program is granted to the public domain. ## -*- texinfo -*- ## @deftypefn {Function File} {@var{X} =} gamlike ([@var{A} @var{B}], @var{R}) ## Calculates the negative log-likelihood function for the Gamma ## distribution over vector @var{R}, with the given parameters @var{A} and @var{B}. ## @seealso{gampdf, gaminv, gamrnd, gamfit} ## @end deftypefn function res = gamlike(P,K) if (nargin != 2) print_usage; endif a=P(1); b=P(2); res = -sum( log( gampdf(K, a, b) ) ); endfunction statistics-1.4.1/inst/PaxHeaders.29769/anovan.m0000644000000000000000000000006213443447555016121 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/anovan.m0000644000175000017500000002737613443447555016647 0ustar00johndjohnd00000000000000## Copyright (C) 2003-2005 Andy Adler ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{pval}, @var{f}, @var{df_b}, @var{df_e}] =} anovan (@var{data}, @var{grps}) ## @deftypefnx {Function File} {[@var{pval}, @var{f}, @var{df_b}, @var{df_e}] =} anovan (@var{data}, @var{grps}, 'param1', @var{value1}) ## Perform a multi-way analysis of variance (ANOVA). The goal is to test ## whether the population means of data taken from @var{k} different ## groups are all equal. ## ## Data is a single vector @var{data} with groups specified by ## a corresponding matrix of group labels @var{grps}, where @var{grps} ## has the same number of rows as @var{data}. For example, if ## @var{data} = [1.1;1.2]; @var{grps}= [1,2,1; 1,5,2]; ## then data point 1.1 was measured under conditions 1,2,1 and ## data point 1.2 was measured under conditions 1,5,2. ## Note that groups do not need to be sequentially numbered. ## ## By default, a 'linear' model is used, computing the N main effects ## with no interactions. this may be modified by param 'model' ## ## p= anovan(data,groups, 'model', modeltype) ## - modeltype = 'linear': compute N main effects ## - modeltype = 'interaction': compute N effects and ## N*(N-1) two-factor interactions ## - modeltype = 'full': compute interactions at all levels ## ## Under the null of constant means, the statistic @var{f} follows an F ## distribution with @var{df_b} and @var{df_e} degrees of freedom. ## ## The p-value (1 minus the CDF of this distribution at @var{f}) is ## returned in @var{pval}. ## ## If no output argument is given, the standard one-way ANOVA table is ## printed. ## ## BUG: DFE is incorrect for modeltypes != full ## @end deftypefn ## Author: Andy Adler ## Based on code by: KH ## $Id$ ## ## TESTING RESULTS: ## 1. ANOVA ACCURACY: www.itl.nist.gov/div898/strd/anova/anova.html ## Passes 'easy' test. Comes close on 'Average'. Fails 'Higher'. ## This could be fixed with higher precision arithmetic ## 2. Matlab anova2 test ## www.mathworks.com/access/helpdesk/help/toolbox/stats/anova2.html ## % From web site: ## 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]; ## % Define groups so reps = 3 ## groups = [ 1 1;1 2;1 3;1 1;1 2;1 3;1 1;1 2;1 3; ## 2 1;2 2;2 3;2 1;2 2;2 3;2 1;2 2;2 3 ]; ## anovan( vec(popcorn'), groups, 'model', 'full') ## % Results same as Matlab output ## 3. Matlab anovan test ## www.mathworks.com/access/helpdesk/help/toolbox/stats/anovan.html ## % From web site ## y = [52.7 57.5 45.9 44.5 53.0 57.0 45.9 44.0]'; ## g1 = [1 2 1 2 1 2 1 2]; ## g2 = {'hi';'hi';'lo';'lo';'hi';'hi';'lo';'lo'}; ## g3 = {'may'; 'may'; 'may'; 'may'; 'june'; 'june'; 'june'; 'june'}; ## anovan( y', [g1',g2',g3']) ## % Fails because we always do interactions function [PVAL, FSTAT, DF_B, DFE] = anovan (data, grps, varargin) if nargin <= 1 usage ("anovan (data, grps)"); end # test supplied parameters modeltype= 'linear'; for idx= 3:2:nargin param= varargin{idx-2}; value= varargin{idx-1}; if strcmp(param, 'model') modeltype= value; # elseif strcmp(param # add other parameters here else error(sprintf('parameter %s is not supported', param)); end end if ~isvector (data) error ("anova: for `anova (data, grps)', data must be a vector"); endif nd = size (grps,1); # number of data points nw = size (grps,2); # number of anova "ways" if (~ isvector (data) || (length(data) ~= nd)) error ("anova: grps must be a matrix of the same number of rows as data"); endif [g,grp_map] = relabel_groups (grps); if strcmp(modeltype, 'linear') max_interact = 1; elseif strcmp(modeltype,'interaction') max_interact = 2; elseif strcmp(modeltype,'full') max_interact = rows(grps); else error(sprintf('modeltype %s is not supported', modeltype)); end ng = length(grp_map); int_tbl = interact_tbl (nw, ng, max_interact ); [gn, gs, gss] = raw_sums(data, g, ng, int_tbl); stats_tbl = int_tbl(2:size(int_tbl,1),:)>0; nstats= size(stats_tbl,1); stats= zeros( nstats+1, 5); # SS, DF, MS, F, p for i= 1:nstats [SS, DF, MS]= factor_sums( gn, gs, gss, stats_tbl(i,:), ng, nw); stats(i,1:3)= [SS, DF, MS]; end # The Mean squared error is the data - avg for each possible measurement # This calculation doesn't work unless there is replication for all grps # SSE= sum( gss(sel) ) - sum( gs(sel).^2 ./ gn(sel) ); SST= gss(1) - gs(1)^2/gn(1); SSE= SST - sum(stats(:,1)); sel = select_pat( ones(1,nw), ng, nw); %incorrect for modeltypes != full DFE= sum( (gn(sel)-1).*(gn(sel)>0) ); MSE= SSE/DFE; stats(nstats+1,1:3)= [SSE, DFE, MSE]; for i= 1:nstats MS= stats(i,3); DF= stats(i,2); F= MS/MSE; pval = 1 - fcdf (F, DF, DFE); stats(i,4:5)= [F, pval]; end if nargout==0; printout( stats, stats_tbl ); else PVAL= stats(1:nstats,5); FSTAT=stats(1:nstats,4); DF_B= stats(1:nstats,2); DF_E= DFE; end endfunction # relabel groups to a mapping from 1 to ng # Input # grps input grouping # Output # g relabelled grouping # grp_map map from output to input grouping function [g,grp_map] = relabel_groups(grps) grp_vec= vec(grps); s= sort (grp_vec); uniq = 1+[0;find(diff(s))]; # mapping from new grps to old groups grp_map = s(uniq); # create new group g ngroups= length(uniq); g= zeros(size(grp_vec)); for i = 1:ngroups g( find( grp_vec== grp_map(i) ) ) = i; end g= reshape(g, size(grps)); endfunction # Create interaction table # # Input: # nw number of "ways" # ng number of ANOVA groups # max_interact maximum number of interactions to consider # default is nw function int_tbl =interact_tbl(nw, ng, max_interact) combin= 2^nw; inter_tbl= zeros( combin, nw); idx= (0:combin-1)'; for i=1:nw; inter_tbl(:,i) = ( rem(idx,2^i) >= 2^(i-1) ); end # find elements with more than max_interact 1's idx = ( sum(inter_tbl',1) > max_interact ); inter_tbl(idx,:) =[]; combin= size(inter_tbl,1); # update value #scale inter_tbl # use ng+1 to map combinations of groups to integers # this would be lots easier with a hash data structure int_tbl = inter_tbl .* (ones(combin,1) * (ng+1).^(0:nw-1) ); endfunction # Calculate sums for each combination # # Input: # g relabelled grouping matrix # ng number of ANOVA groups # max_interact # # Output (virtual (ng+1)x(nw) matrices): # gn number of data sums in each group # gs sum of data in each group # gss sumsqr of data in each group function [gn, gs, gss] = raw_sums(data, g, ng, int_tbl); nw= size(g,2); ndata= size(g,1); gn= gs= gss= zeros((ng+1)^nw, 1); for i=1:ndata # need offset by one for indexing datapt= data(i); idx = 1+ int_tbl*g(i,:)'; gn(idx) +=1; gs(idx) +=datapt; gss(idx) +=datapt^2; end endfunction # Calcualte the various factor sums # Input: # gn number of data sums in each group # gs sum of data in each group # gss sumsqr of data in each group # select binary vector of factor for this "way"? # ng number of ANOVA groups # nw number of ways function [SS,DF]= raw_factor_sums( gn, gs, gss, select, ng, nw); sel= select_pat( select, ng, nw); ss_raw= gs(sel).^2 ./ gn(sel); SS= sum( ss_raw( ~isnan(ss_raw) )); if length(find(select>0))==1 DF= sum(gn(sel)>0)-1; else DF= 1; #this isn't the real DF, but needed to multiply end endfunction function [SS, DF, MS]= factor_sums( gn, gs, gss, select, ng, nw); SS=0; DF=1; ff = find(select); lff= length(ff); # zero terms added, one term subtracted, two added, etc for i= 0:2^lff-1 remove= find( rem( floor( i * 2.^(-lff+1:0) ), 2) ); sel1= select; if ~isempty(remove) sel1( ff( remove ) )=0; end [raw_sum,raw_df]= raw_factor_sums(gn,gs,gss,sel1,ng,nw); add_sub= (-1)^length(remove); SS+= add_sub*raw_sum; DF*= raw_df; end MS= SS/DF; endfunction # Calcualte the various factor sums # Input: # select binary vector of factor for this "way"? # ng number of ANOVA groups # nw number of ways function sel= select_pat( select, ng, nw); # if select(i) is zero, remove nonzeros # if select(i) is zero, remove zero terms for i field=[]; if length(select) ~= nw; error("length of select must be = nw"); end ng1= ng+1; if isempty(field) # expand 0:(ng+1)^nw in base ng+1 field= (0:(ng1)^nw-1)'* ng1.^(-nw+1:0); field= rem( floor( field), ng1); # select zero or non-zero elements field= field>0; end sel= find( all( field == ones(ng1^nw,1)*select(:)', 2) ); endfunction function printout( stats, stats_tbl ); nw= size( stats_tbl,2); [jnk,order]= sort( sum(stats_tbl,2) ); printf('\n%d-way ANOVA Table (Factors A%s):\n\n', nw, ... sprintf(',%c',toascii('A')+(1:nw-1)) ); printf('Source of Variation Sum Sqr df MeanSS Fval p-value\n'); printf('*********************************************************************\n'); printf('Error %10.2f %4d %10.2f\n', stats( size(stats,1),1:3)); for i= order(:)' str= sprintf(' %c x',toascii('A')+find(stats_tbl(i,:)>0)-1 ); str= str(1:length(str)-2); # remove x printf('Factor %15s %10.2f %4d %10.2f %7.3f %7.6f\n', ... str, stats(i,:) ); end printf('\n'); endfunction #{ # Test Data from http://maths.sci.shu.ac.uk/distance/stats/14.shtml data=[7 9 9 8 12 10 ... 9 8 10 11 13 13 ... 9 10 10 12 10 12]'; grp = [1,1; 1,1; 1,2; 1,2; 1,3; 1,3; 2,1; 2,1; 2,2; 2,2; 2,3; 2,3; 3,1; 3,1; 3,2; 3,2; 3,3; 3,3]; data=[7 9 9 8 12 10 9 8 ... 9 8 10 11 13 13 10 11 ... 9 10 10 12 10 12 10 12]'; grp = [1,4; 1,4; 1,5; 1,5; 1,6; 1,6; 1,7; 1,7; 2,4; 2,4; 2,5; 2,5; 2,6; 2,6; 2,7; 2,7; 3,4; 3,4; 3,5; 3,5; 3,6; 3,6; 3,7; 3,7]; # Test Data from http://maths.sci.shu.ac.uk/distance/stats/9.shtml data=[9.5 11.1 11.9 12.8 ... 10.9 10.0 11.0 11.9 ... 11.2 10.4 10.8 13.4]'; grp= [1:4,1:4,1:4]'; # Test Data from http://maths.sci.shu.ac.uk/distance/stats/13.shtml data=[7.56 9.68 11.65 ... 9.98 9.69 10.69 ... 7.23 10.49 11.77 ... 8.22 8.55 10.72 ... 7.59 8.30 12.36]'; grp = [1,1;1,2;1,3; 2,1;2,2;2,3; 3,1;3,2;3,3; 4,1;4,2;4,3; 5,1;5,2;5,3]; # Test Data from www.mathworks.com/ # access/helpdesk/help/toolbox/stats/linear10.shtml data=[23 27 43 41 15 17 3 9 20 63 55 90]; grp= [ 1 1 1 1 2 2 2 2 3 3 3 3; 1 1 2 2 1 1 2 2 1 1 2 2]'; #} statistics-1.4.1/inst/PaxHeaders.29769/nanvar.m0000644000000000000000000000006213443447555016124 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/nanvar.m0000644000175000017500000000400013443447555016625 0ustar00johndjohnd00000000000000# Copyright (C) 2008 Sylvain Pelissier ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {} nanvar (@var{x}) ## @deftypefnx{Function File} {@var{v} =} nanvar (@var{X}, @var{opt}) ## @deftypefnx{Function File} {@var{v} =} nanvar (@var{X}, @var{opt}, @var{dim}) ## Compute the variance while ignoring NaN values. ## ## For vector arguments, return the (real) variance of the values. ## For matrix arguments, return a row vector containing the variance for ## each column. ## ## The argument @var{opt} determines the type of normalization to use. ## Valid values are ## ## @table @asis ## @item 0: ## Normalizes with @math{N-1}, provides the best unbiased estimator of the ## variance [default]. ## @item 1: ## Normalizes with @math{N}, this provides the second moment around the mean. ## @end table ## ## The third argument @var{dim} determines the dimension along which the ## variance is calculated. ## ## @seealso{var, nanmean, nanstd, nanmax, nanmin} ## @end deftypefn function y = nanvar(x,w,dim) if nargin < 1 print_usage (); else if ((nargin < 2) || isempty(w)) w = 0; endif if nargin < 3 dim = min(find(size(x)>1)); if isempty(dim) dim=1; endif endif y = nanstd(x,w,dim).^2; endif endfunction ## Tests %!shared x %! x = [1 2 nan 3 4 5]; %!assert (nanvar (x), var (x(! isnan (x))), 10*eps) statistics-1.4.1/inst/PaxHeaders.29769/cmdscale.m0000644000000000000000000000006213443447555016412 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/cmdscale.m0000644000175000017500000001351013443447555017121 0ustar00johndjohnd00000000000000## Copyright (C) 2014 JD Walsh ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} @var{Y} = cmdscale (@var{D}) ## @deftypefnx{Function File} [@var{Y}, @var{e} ] = cmdscale (@var{D}) ## Classical multidimensional scaling of a matrix. ## ## Takes an @var{n} by @var{n} distance (or difference, similarity, or ## dissimilarity) matrix @var{D}. Returns @var{Y}, a matrix of @var{n} points ## with coordinates in @var{p} dimensional space which approximate those ## distances (or differences, similarities, or dissimilarities). Also returns ## the eigenvalues @var{e} of ## @code{@var{B} = -1/2 * @var{J} * (@var{D}.^2) * @var{J}}, where ## @code{J = eye(@var{n}) - ones(@var{n},@var{n})/@var{n}}. @var{p}, the number ## of columns of @var{Y}, is equal to the number of positive real eigenvalues of ## @var{B}. ## ## @var{D} can be a full or sparse matrix or a vector of length ## @code{@var{n}*(@var{n}-1)/2} containing the upper triangular elements (like ## the output of the @code{pdist} function). It must be symmetric with ## non-negative entries whose values are further restricted by the type of ## matrix being represented: ## ## * If @var{D} is either a distance, dissimilarity, or difference matrix, then ## it must have zero entries along the main diagonal. In this case the points ## @var{Y} equal or approximate the distances given by @var{D}. ## ## * If @var{D} is a similarity matrix, the elements must all be less than or ## equal to one, with ones along the the main diagonal. In this case the points ## @var{Y} equal or approximate the distances given by ## @code{@var{D} = sqrt(ones(@var{n},@var{n})-@var{D})}. ## ## @var{D} is a Euclidean matrix if and only if @var{B} is positive ## semi-definite. When this is the case, then @var{Y} is an exact representation ## of the distances given in @var{D}. If @var{D} is non-Euclidean, @var{Y} only ## approximates the distance given in @var{D}. The approximation used by ## @code{cmdscale} minimizes the statistical loss function known as ## @var{strain}. ## ## The returned @var{Y} is an @var{n} by @var{p} matrix showing possible ## coordinates of the points in @var{p} dimensional space ## (@code{@var{p} < @var{n}}). The columns are correspond to the positive ## eigenvalues of @var{B} in descending order. A translation, rotation, or ## reflection of the coordinates given by @var{Y} will satisfy the same distance ## matrix up to the limits of machine precision. ## ## For any @code{@var{k} <= @var{p}}, if the largest @var{k} positive ## eigenvalues of @var{B} are significantly greater in absolute magnitude than ## its other eigenvalues, the first @var{k} columns of @var{Y} provide a ## @var{k}-dimensional reduction of @var{Y} which approximates the distances ## given by @var{D}. The optional return @var{e} can be used to consider various ## values of @var{k}, or to evaluate the accuracy of specific dimension ## reductions (e.g., @code{@var{k} = 2}). ## ## Reference: Ingwer Borg and Patrick J.F. Groenen (2005), Modern ## Multidimensional Scaling, Second Edition, Springer, ISBN: 978-0-387-25150-9 ## (Print) 978-0-387-28981-6 (Online) ## ## @seealso{pdist} ## @end deftypefn ## Author: JD Walsh ## Created: 2014-10-31 ## Description: Classical multidimensional scaling ## Keywords: multidimensional-scaling mds distance clustering ## TO DO: include missing functions `mdscale' and `procrustes' in @seealso function [Y, e] = cmdscale (D) % Check for matrix input if ((nargin ~= 1) || ... (~any(strcmp ({'matrix' 'scalar' 'range'}, typeinfo(D))))) usage ('cmdscale: input must be vector or matrix; see help'); endif % If vector, convert to matrix; otherwise, check for square symmetric input if (isvector (D)) D = squareform (D); elseif ((~issquare (D)) || (norm (D - D', 1) > 0)) usage ('cmdscale: matrix input must be square symmetric; see help'); endif n = size (D,1); % Check for valid format (see help above); If similarity matrix, convert if (any (any (D < 0))) usage ('cmdscale: entries must be nonnegative; see help'); elseif (trace (D) ~= 0) if ((~all (diag (D) == 1)) || (~all (D <= 1))) usage ('cmdscale: input must be distance vector or matrix; see help'); endif D = sqrt (ones (n,n) - D); endif % Build centering matrix, perform double centering, extract eigenpairs J = eye (n) - ones (n,n) / n; B = -1 / 2 * J * (D .^ 2) * J; [Q, e] = eig (B); e = diag (e); etmp = e; e = sort(e, 'descend'); % Remove complex eigenpairs (only possible due to machine approximation) if (iscomplex (etmp)) for i = 1 : size (etmp,1) cmp(i) = (isreal (etmp(i))); endfor etmp = etmp(cmp); Q = Q(:,cmp); endif % Order eigenpairs [etmp, ord] = sort (etmp, 'descend'); Q = Q(:,ord); % Remove negative eigenpairs cmp = (etmp > 0); etmp = etmp(cmp); Q = Q(:,cmp); % Test for n-dimensional results if (size(etmp,1) == n) etmp = etmp(1:n-1); Q = Q(:, 1:n-1); endif % Build output matrix Y Y = Q * diag (sqrt (etmp)); endfunction %!shared m, n, X, D %! m = randi(100) + 1; n = randi(100) + 1; X = rand(m, n); D = pdist(X); %!assert(norm(pdist(cmdscale(D))), norm(D), sqrt(eps)) %!assert(norm(pdist(cmdscale(squareform(D)))), norm(D), sqrt(eps)) statistics-1.4.1/inst/PaxHeaders.29769/mvnpdf.m0000644000000000000000000000006213443447555016131 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/mvnpdf.m0000644000175000017500000000743513443447555016651 0ustar00johndjohnd00000000000000## Author: Paul Kienzle ## This program is granted to the public domain. ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} mvnpdf (@var{x}) ## @deftypefnx{Function File} {@var{y} =} mvnpdf (@var{x}, @var{mu}) ## @deftypefnx{Function File} {@var{y} =} mvnpdf (@var{x}, @var{mu}, @var{sigma}) ## Compute multivariate normal pdf for @var{x} given mean @var{mu} and covariance matrix ## @var{sigma}. The dimension of @var{x} is @var{d} x @var{p}, @var{mu} is ## @var{1} x @var{p} and @var{sigma} is @var{p} x @var{p}. The normal pdf is ## defined as ## ## @example ## @iftex ## @tex ## $$ 1/y^2 = (2 pi)^p |\Sigma| \exp \{ (x-\mu)^T \Sigma^{-1} (x-\mu) \} $$ ## @end tex ## @end iftex ## @ifnottex ## 1/@var{y}^2 = (2 pi)^@var{p} |@var{Sigma}| exp @{ (@var{x}-@var{mu})' inv(@var{Sigma})@ ## (@var{x}-@var{mu}) @} ## @end ifnottex ## @end example ## ## @strong{References} ## ## NIST Engineering Statistics Handbook 6.5.4.2 ## http://www.itl.nist.gov/div898/handbook/pmc/section5/pmc542.htm ## ## @strong{Algorithm} ## ## Using Cholesky factorization on the positive definite covariance matrix: ## ## @example ## @var{r} = chol (@var{sigma}); ## @end example ## ## where @var{r}'*@var{r} = @var{sigma}. Being upper triangular, the determinant ## of @var{r} is trivially the product of the diagonal, and the determinant of ## @var{sigma} is the square of this: ## ## @example ## @var{det} = prod (diag (@var{r}))^2; ## @end example ## ## The formula asks for the square root of the determinant, so no need to ## square it. ## ## The exponential argument @var{A} = @var{x}' * inv (@var{sigma}) * @var{x} ## ## @example ## @var{A} = @var{x}' * inv (@var{sigma}) * @var{x} ## = @var{x}' * inv (@var{r}' * @var{r}) * @var{x} ## = @var{x}' * inv (@var{r}) * inv(@var{r}') * @var{x} ## @end example ## ## Given that inv (@var{r}') == inv(@var{r})', at least in theory if not numerically, ## ## @example ## @var{A} = (@var{x}' / @var{r}) * (@var{x}'/@var{r})' = sumsq (@var{x}'/@var{r}) ## @end example ## ## The interface takes the parameters to the multivariate normal in columns rather than ## rows, so we are actually dealing with the transpose: ## ## @example ## @var{A} = sumsq (@var{x}/r) ## @end example ## ## and the final result is: ## ## @example ## @var{r} = chol (@var{sigma}) ## @var{y} = (2*pi)^(-@var{p}/2) * exp (-sumsq ((@var{x}-@var{mu})/@var{r}, 2)/2) / prod (diag (@var{r})) ## @end example ## ## @seealso{mvncdf, mvnrnd} ## @end deftypefn function pdf = mvnpdf (x, mu = 0, sigma = 1) ## Check input if (!ismatrix (x)) error ("mvnpdf: first input must be a matrix"); endif if (!isvector (mu) && !isscalar (mu)) error ("mvnpdf: second input must be a real scalar or vector"); endif if (!ismatrix (sigma) || !issquare (sigma)) error ("mvnpdf: third input must be a square matrix"); endif [ps, ps] = size (sigma); [d, p] = size (x); if (p != ps) error ("mvnpdf: dimensions of data and covariance matrix does not match"); endif if (numel (mu) != p && numel (mu) != 1) error ("mvnpdf: dimensions of data does not match dimensions of mean value"); endif mu = mu (:).'; if (all (size (mu) == [1, p])) mu = repmat (mu, [d, 1]); endif if (nargin < 3) pdf = (2*pi)^(-p/2) * exp (-sumsq (x-mu, 2)/2); else r = chol (sigma); pdf = (2*pi)^(-p/2) * exp (-sumsq ((x-mu)/r, 2)/2) / prod (diag (r)); endif endfunction %!demo %! mu = [0, 0]; %! sigma = [1, 0.1; 0.1, 0.5]; %! [X, Y] = meshgrid (linspace (-3, 3, 25)); %! XY = [X(:), Y(:)]; %! Z = mvnpdf (XY, mu, sigma); %! mesh (X, Y, reshape (Z, size (X))); %! colormap jet %!test %! mu = [1,-1]; %! sigma = [.9 .4; .4 .3]; %! x = [ 0.5 -1.2; -0.5 -1.4; 0 -1.5]; %! p = [ 0.41680003660313; 0.10278162359708; 0.27187267524566 ]; %! q = mvnpdf (x, mu, sigma); %! assert (p, q, 10*eps); statistics-1.4.1/inst/PaxHeaders.29769/jackknife.m0000644000000000000000000000006213443447555016564 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/jackknife.m0000644000175000017500000001177113443447555017302 0ustar00johndjohnd00000000000000## Copyright (C) 2011 Alexander Klein ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn{Function File} {@var{jackstat} =} jackknife (@var{E}, @var{x}, @dots{}) ## Compute jackknife estimates of a parameter taking one or more given samples as parameters. ## In particular, @var{E} is the estimator to be jackknifed as a function name, handle, ## or inline function, and @var{x} is the sample for which the estimate is to be taken. ## The @var{i}-th entry of @var{jackstat} will contain the value of the estimator ## on the sample @var{x} with its @var{i}-th row omitted. ## ## @example ## @group ## jackstat(@var{i}) = @var{E}(@var{x}(1 : @var{i} - 1, @var{i} + 1 : length(@var{x}))) ## @end group ## @end example ## ## Depending on the number of samples to be used, the estimator must have the appropriate form: ## If only one sample is used, then the estimator need not be concerned with cell arrays, ## for example jackknifing the standard deviation of a sample can be performed with ## @code{@var{jackstat} = jackknife (@@std, rand (100, 1))}. ## If, however, more than one sample is to be used, the samples must all be of equal size, ## and the estimator must address them as elements of a cell-array, ## in which they are aggregated in their order of appearance: ## ## @example ## @group ## @var{jackstat} = jackknife(@@(x) std(x@{1@})/var(x@{2@}), rand (100, 1), randn (100, 1) ## @end group ## @end example ## ## If all goes well, a theoretical value @var{P} for the parameter is already known, ## @var{n} is the sample size, ## @code{@var{t} = @var{n} * @var{E}(@var{x}) - (@var{n} - 1) * mean(@var{jackstat})}, and ## @code{@var{v} = sumsq(@var{n} * @var{E}(@var{x}) - (@var{n} - 1) * @var{jackstat} - @var{t}) / (@var{n} * (@var{n} - 1))}, then ## @code{(@var{t}-@var{P})/sqrt(@var{v})} should follow a t-distribution with @var{n}-1 degrees of freedom. ## ## Jackknifing is a well known method to reduce bias; further details can be found in: ## @itemize @bullet ## @item Rupert G. Miller: The jackknife-a review; Biometrika (1974) 61(1): 1-15; doi:10.1093/biomet/61.1.1 ## @item Rupert G. Miller: Jackknifing Variances; Ann. Math. Statist. Volume 39, Number 2 (1968), 567-582; doi:10.1214/aoms/1177698418 ## @item M. H. Quenouille: Notes on Bias in Estimation; Biometrika Vol. 43, No. 3/4 (Dec., 1956), pp. 353-360; doi:10.1093/biomet/43.3-4.353 ## @end itemize ## @end deftypefn ## Author: Alexander Klein ## Created: 2011-11-25 function jackstat = jackknife ( anEstimator, varargin ) ## Convert function name to handle if necessary, or throw ## an error. if ( !strcmp ( typeinfo ( anEstimator ), "function handle" ) ) if ( isascii ( anEstimator ) ) anEstimator = str2func ( anEstimator ); else error ( "Estimators must be passed as function names or handles!" ); end end ## Simple jackknifing can be done with a single vector argument, and ## first and foremost with a function that does not care about ## cell-arrays. if ( length ( varargin ) == 1 && isnumeric ( varargin { 1 } ) ) aSample = varargin { 1 }; g = length ( aSample ); jackstat = zeros ( 1, g ); for k = 1 : g jackstat ( k ) = anEstimator ( aSample ( [ 1 : k - 1, k + 1 : g ] ) ); end ## More complicated input requires more work, however. else g = cellfun ( @(x) length ( x ), varargin ); if ( any ( g - g ( 1 ) ) ) error ( "All passed data must be of equal length!" ); end g = g ( 1 ); jackstat = zeros ( 1, g ); for k = 1 : g jackstat ( k ) = anEstimator ( cellfun ( @(x) x( [ 1 : k - 1, k + 1 : g ] ), varargin, "UniformOutput", false ) ); end end endfunction %!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 ( 10 / mean(d) - 9 * mean(jackstat), 0.5240, 1e-5 ); %!demo %! for k = 1:1000 %! x=rand(10,1); %! s(k)=std(x); %! jackstat=jackknife(@std,x); %! j(k)=10*std(x) - 9*mean(jackstat); %! end %! figure();hist([s',j'], 0:sqrt(1/12)/10:2*sqrt(1/12)) %!demo %! 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); %! end %! t=(j-sqrt(1/12))./sqrt(v); %! figure();plot(sort(tcdf(t,49)),"-;Almost linear mapping indicates good fit with t-distribution.;") statistics-1.4.1/inst/PaxHeaders.29769/regress.m0000644000000000000000000000006213443447555016311 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/regress.m0000644000175000017500000001521113443447555017020 0ustar00johndjohnd00000000000000## Copyright (C) 2005, 2006 William Poetra Yoga Hadisoeseno ## Copyright (C) 2011 Nir Krakauer ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{b}, @var{bint}, @var{r}, @var{rint}, @var{stats}] =} regress (@var{y}, @var{X}, [@var{alpha}]) ## Multiple Linear Regression using Least Squares Fit of @var{y} on @var{X} ## with the model @code{y = X * beta + e}. ## ## Here, ## ## @itemize ## @item ## @code{y} is a column vector of observed values ## @item ## @code{X} is a matrix of regressors, with the first column filled with ## the constant value 1 ## @item ## @code{beta} is a column vector of regression parameters ## @item ## @code{e} is a column vector of random errors ## @end itemize ## ## Arguments are ## ## @itemize ## @item ## @var{y} is the @code{y} in the model ## @item ## @var{X} is the @code{X} in the model ## @item ## @var{alpha} is the significance level used to calculate the confidence ## intervals @var{bint} and @var{rint} (see `Return values' below). If not ## specified, ALPHA defaults to 0.05 ## @end itemize ## ## Return values are ## ## @itemize ## @item ## @var{b} is the @code{beta} in the model ## @item ## @var{bint} is the confidence interval for @var{b} ## @item ## @var{r} is a column vector of residuals ## @item ## @var{rint} is the confidence interval for @var{r} ## @item ## @var{stats} is a row vector containing: ## ## @itemize ## @item The R^2 statistic ## @item The F statistic ## @item The p value for the full model ## @item The estimated error variance ## @end itemize ## @end itemize ## ## @var{r} and @var{rint} can be passed to @code{rcoplot} to visualize ## the residual intervals and identify outliers. ## ## NaN values in @var{y} and @var{X} are removed before calculation begins. ## ## @end deftypefn ## References: ## - Matlab 7.0 documentation (pdf) ## - ¡¶´óѧÊýѧʵÑé¡· ½ªÆôÔ´ µÈ (textbook) ## - http://www.netnam.vn/unescocourse/statistics/12_5.htm ## - wsolve.m in octave-forge ## - http://www.stanford.edu/class/ee263/ls_ln_matlab.pdf function [b, bint, r, rint, stats] = regress (y, X, alpha) if (nargin < 2 || nargin > 3) print_usage; endif if (! ismatrix (y)) error ("regress: y must be a numeric matrix"); endif if (! ismatrix (X)) error ("regress: X must be a numeric matrix"); endif if (columns (y) != 1) error ("regress: y must be a column vector"); endif if (rows (y) != rows (X)) error ("regress: y and X must contain the same number of rows"); endif if (nargin < 3) alpha = 0.05; elseif (! isscalar (alpha)) error ("regress: alpha must be a scalar value") endif notnans = ! logical (sum (isnan ([y X]), 2)); y = y(notnans); X = X(notnans,:); [Xq Xr] = qr (X, 0); pinv_X = Xr \ Xq'; b = pinv_X * y; if (nargout > 1) n = rows (X); p = columns (X); dof = n - p; t_alpha_2 = tinv (alpha / 2, dof); r = y - X * b; # added -- Nir SSE = sum (r .^ 2); v = SSE / dof; # c = diag(inv (X' * X)) using (economy) QR decomposition # which means that we only have to use Xr c = diag (inv (Xr' * Xr)); db = t_alpha_2 * sqrt (v * c); bint = [b + db, b - db]; endif if (nargout > 3) dof1 = n - p - 1; h = sum(X.*pinv_X', 2); #added -- Nir (same as diag(X*pinv_X), without doing the matrix multiply) # From Matlab's documentation on Multiple Linear Regression, # sigmaihat2 = norm (r) ^ 2 / dof1 - r .^ 2 / (dof1 * (1 - h)); # dr = -tinv (1 - alpha / 2, dof) * sqrt (sigmaihat2 .* (1 - h)); # Substitute # norm (r) ^ 2 == sum (r .^ 2) == SSE # -tinv (1 - alpha / 2, dof) == tinv (alpha / 2, dof) == t_alpha_2 # We get # sigmaihat2 = (SSE - r .^ 2 / (1 - h)) / dof1; # dr = t_alpha_2 * sqrt (sigmaihat2 .* (1 - h)); # Combine, we get # dr = t_alpha_2 * sqrt ((SSE * (1 - h) - (r .^ 2)) / dof1); dr = t_alpha_2 * sqrt ((SSE * (1 - h) - (r .^ 2)) / dof1); rint = [r + dr, r - dr]; endif if (nargout > 4) R2 = 1 - SSE / sum ((y - mean (y)) .^ 2); # F = (R2 / (p - 1)) / ((1 - R2) / dof); F = dof / (p - 1) / (1 / R2 - 1); pval = 1 - fcdf (F, p - 1, dof); stats = [R2 F pval v]; endif endfunction %!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(b,V(:,1),3e-6); %! assert(stats(1),Rsq,1e-12); %! assert(stats(2),F,3e-8); %! assert(((bint(:,1)-bint(:,2))/2)/tinv(alpha/2,9),V(:,2),-1.e-5); statistics-1.4.1/inst/PaxHeaders.29769/mvnrnd.m0000644000000000000000000000006213443447555016143 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/inst/mvnrnd.m0000644000175000017500000001332713443447555016660 0ustar00johndjohnd00000000000000## Copyright (C) 2003 Iain Murray ## ## This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} @var{s} = mvnrnd (@var{mu}, @var{Sigma}) ## @deftypefnx{Function File} @var{s} = mvnrnd (@var{mu}, @var{Sigma}, @var{n}) ## @deftypefnx{Function File} @var{s} = mvnrnd (@dots{}, @var{tol}) ## Draw @var{n} random @var{d}-dimensional vectors from a multivariate Gaussian distribution with mean @var{mu}(@var{n}x@var{d}) and covariance matrix ## @var{Sigma}(@var{d}x@var{d}). ## ## @var{mu} must be @var{n}-by-@var{d} (or 1-by-@var{d} if @var{n} is given) or a scalar. ## ## If the argument @var{tol} is given the eigenvalues of @var{Sigma} are checked for positivity against -100*tol. The default value of tol is @code{eps*norm (Sigma, "fro")}. ## ## @end deftypefn function s = mvnrnd (mu, Sigma, K, tol=eps*norm (Sigma, "fro")) % Iain Murray 2003 -- I got sick of this simple thing not being in Octave and locking up a stats-toolbox license in Matlab for no good reason. % May 2004 take a third arg, cases. Makes it more compatible with Matlab's. % Paul Kienzle % * Add GPL notice. % * Add docs for argument K % 2012 Juan Pablo Carbajal % * Uses Octave 3.6.2 broadcast. % * Stabilizes chol by perturbing Sigma with a epsilon multiple of the identity. % The effect on the generated samples is to add additional independent noise of variance epsilon. Ref: GPML Rasmussen & Williams. 2006. pp 200-201 % * Improved doc. % * Added tolerance to the positive definite check % * Used chol with option 'upper'. % 2014 Nir Krakauer % * Add tests. % * Allow mu to be scalar, in which case it's assumed that all elements share this mean. %perform some input checking if ~issquare (Sigma) error ('Sigma must be a square covariance matrix.'); end d = size(Sigma, 1); % If mu is column vector and Sigma not a scalar then assume user didn't read help but let them off and flip mu. Don't be more liberal than this or it will encourage errors (eg what should you do if mu is square?). if (size (mu, 2) == 1) && (d != 1) mu = mu'; end if nargin >= 3 n = K; else n = size(mu, 1); %1 if mu is scalar end if (~isscalar (mu)) && any(size (mu) != [1,d]) && any(size (mu) != [n,d]) error ('mu must be nxd, 1xd, or scalar, where Sigma has dimensions dxd.'); end warning ("off", "Octave:broadcast","local"); try U = chol (Sigma + tol*eye (d),"upper"); catch [E , Lambda] = eig (Sigma); if min (diag (Lambda)) < -100*tol error('Sigma must be positive semi-definite. Lowest eigenvalue %g', ... min (diag (Lambda))); else Lambda(Lambda<0) = 0; end warning ("mvnrnd:InvalidInput","Cholesky factorization failed. Using diagonalized matrix.") U = sqrt (Lambda) * E'; end s = randn(n,d)*U + mu; warning ("on", "Octave:broadcast"); endfunction % {{{ END OF CODE --- Guess I should provide an explanation: % % We can draw from axis aligned unit Gaussians with randn(d) % x ~ A*exp(-0.5*x'*x) % We can then rotate this distribution using % y = U'*x % Note that % x = inv(U')*y % Our new variable y is distributed according to: % y ~ B*exp(-0.5*y'*inv(U'*U)*y) % or % y ~ N(0,Sigma) % where % Sigma = U'*U % For a given Sigma we can use the chol function to find the corresponding U, % draw x and find y. We can adjust for a non-zero mean by just adding it on. % % But the Cholsky decomposition function doesn't always work... % Consider Sigma=[1 1;1 1]. Now inv(Sigma) doesn't actually exist, but Matlab's % mvnrnd provides samples with this covariance st x(1)~N(0,1) x(2)=x(1). The % fast way to deal with this would do something similar to chol but be clever % when the rows aren't linearly independent. However, I can't be bothered, so % another way of doing the decomposition is by diagonalising Sigma (which is % slower but works). % if % [E,Lambda]=eig(Sigma) % then % Sigma = E*Lambda*E' % so % U = sqrt(Lambda)*E' % If any Lambdas are negative then Sigma just isn't even positive semi-definite % so we can give up. % % Paul Kienzle adds: % Where it exists, chol(Sigma) is numerically well behaved. chol(hilb(12)) for doubles and for 100 digit floating point differ in the last digit. % Where chol(Sigma) doesn't exist, X*sqrt(Lambda)*E' will be somewhat accurate. For example, the elements of sqrt(Lambda)*E' for hilb(12), hilb(55) and hilb(120) are accurate to around 1e-8 or better. This was tested using the TNT+JAMA for eig and chol templates, and qlib for 100 digit precision. % }}} %!shared m, n, C, rho %! m = 10; n = 3; rho = 0.4; C = rho*ones(n, n) + (1 - rho)*eye(n); %!assert(size(mvnrnd(0, C, m)), [m n]) %!assert(size(mvnrnd(zeros(1, n), C, m)), [m n]) %!assert(size(mvnrnd(zeros(n, 1), C, m)), [m n]) %!assert(size(mvnrnd(zeros(m, n), C, m)), [m n]) %!assert(size(mvnrnd(zeros(m, n), C)), [m n]) %!assert(size(mvnrnd(zeros(1, n), C)), [1 n]) %!assert(size(mvnrnd(zeros(n, 1), C)), [1 n]) %!error(mvnrnd(zeros(m+1, n), C, m)) %!error(mvnrnd(zeros(1, n+1), C, m)) %!error(mvnrnd(zeros(n+1, 1), C, m)) %!error(mvnrnd(zeros(m, n), eye(n+1), m)) %!error(mvnrnd(zeros(m, n), eye(n+1, n), m)) statistics-1.4.1/PaxHeaders.29769/test0000644000000000000000000000013213444214613014370 xustar0030 mtime=1553013131.337844684 30 atime=1553013131.677852968 30 ctime=1553013131.677852968 statistics-1.4.1/test/0000755000175000017500000000000013444214613015156 5ustar00johndjohnd00000000000000statistics-1.4.1/test/PaxHeaders.29769/tblread-space.dat0000644000000000000000000000006213443447555017663 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/test/tblread-space.dat0000755000175000017500000000002413443447555020371 0ustar00johndjohnd00000000000000 a bc de 1 2 f 3 4statistics-1.4.1/test/PaxHeaders.29769/caseread.dat0000644000000000000000000000006213443447555016724 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/test/caseread.dat0000755000175000017500000000001213443447555017427 0ustar00johndjohnd00000000000000a bcd efstatistics-1.4.1/test/PaxHeaders.29769/tblread-tab.dat0000644000000000000000000000006213443447555017336 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/test/tblread-tab.dat0000755000175000017500000000002613443447555020046 0ustar00johndjohnd00000000000000 a bc de 1 2 f 3 4 statistics-1.4.1/PaxHeaders.29769/COPYING0000644000000000000000000000006213443447555014537 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/COPYING0000644000175000017500000001255413443447555015255 0ustar00johndjohnd00000000000000inst/private/tbl_delim.m.m GPLv3+ inst/anderson_darling_cdf.m public domain inst/anderson_darling_test.m public domain inst/anovan.m GPLv3+ inst/bbscdf.m GPLv3+ inst/bbsinv.m GPLv3+ inst/bbspdf.m GPLv3+ inst/bbsrnd.m GPLv3+ inst/betastat.m GPLv3+ inst/binostat.m GPLv3+ inst/binotest.m GPLv3+ inst/boxplot.m GPLv3+ inst/burrcdf.m GPLv3+ inst/burrinv.m GPLv3+ inst/burrpdf.m GPLv3+ inst/burrrnd.m GPLv3+ inst/caseread.m GPLv3+ inst/casewrite.m GPLv3+ inst/cdf.m GPLv3+ inst/chi2stat.m GPLv3+ inst/cl_multinom.m GPLv3+ inst/cmdscale.m GPLv3+ inst/combnk.m GPLv3+ inst/copulacdf.m GPLv3+ inst/copulapdf.m GPLv3+ inst/copularnd.m GPLv3+ inst/crossval.m GPLv3+ inst/dcov.m GPLv3+ inst/dendogram.m GPLv3+ inst/expstat.m GPLv3+ inst/ff2n.m public domain inst/fitgmdist.m GPLv3+ inst/fstat.m GPLv3+ inst/fullfact.m public domain inst/gamfit.m public domain inst/gamlike.m public domain inst/gamstat.m GPLv3+ inst/geomean.m GPLv3+ inst/geostat.m GPLv3+ inst/gevcdf.m GPLv3+ inst/gevfit_lmom.m GPLv3+ inst/gevfit.m GPLv3+ inst/gevinv.m GPLv3+ inst/gevlike.m GPLv3+ inst/gevpdf.m GPLv3+ inst/gevrnd.m GPLv3+ inst/gevstat.m GPLv3+ inst/gmdistribution.m GPLv3+ inst/gpcdf.m GPLv3+ inst/gpinv.m GPLv3+ inst/gppdf.m GPLv3+ inst/gprnd.m GPLv3+ inst/grp2idx.m GPLv3+ inst/harmmean.m GPLv3+ inst/hist3.m GPLv3+ inst/histfit.m GPLv3+ inst/hmmestimate.m GPLv3+ inst/hmmgenerate.m GPLv3+ inst/hmmviterbi.m GPLv3+ inst/iwishpdf.m GPLv3+ inst/iwishrnd.m GPLv3+ inst/hygestat.m GPLv3+ inst/jackknife.m GPLv3+ inst/jsucdf.m GPLv3+ inst/jsupdf.m GPLv3+ inst/kmeans.m GPLv3+ inst/linkage.m GPLv3+ inst/lognstat.m GPLv3+ inst/mad.m GPLv3+ inst/mahal.m GPLv3+ inst/mnpdf.m GPLv3+ inst/mnrnd.m GPLv3+ inst/monotone_smooth.m GPLv3+ inst/mvncdf.m GPLv3+ inst/mvnpdf.m public domain inst/mvnrnd.m GPLv3+ inst/mvtcdf.m GPLv3+ inst/mvtpdf.m GPLv3+ inst/mvtrnd.m GPLv3+ inst/nakacdf.m GPLv3+ inst/nakainv.m GPLv3+ inst/nakapdf.m GPLv3+ inst/nakarnd.m GPLv3+ inst/nanmax.m GPLv3+ inst/nanmean.m GPLv3+ inst/nanmedian.m GPLv3+ inst/nanmin.m GPLv3+ inst/nanstd.m GPLv3+ inst/nansum.m GPLv3+ inst/nanvar.m GPLv3+ inst/nbinstat.m GPLv3+ inst/normalise_distribution.m GPLv3+ inst/normplot.m public domain inst/normstat.m GPLv3+ inst/pcacov.m GPLv3+ inst/pcares.m GPLv3+ inst/pdf.m GPLv3+ inst/pdist.m GPLv3+ inst/pdist2.m GPLv3+ inst/plsregress.m GPLv3+ inst/poisstat.m GPLv3+ inst/princomp.m public domain inst/qrandn.m GPLv3+ inst/random.m GPLv3+ inst/randsample.m GPLv3+ inst/raylcdf.m GPLv3+ inst/raylinv.m GPLv3+ inst/raylpdf.m GPLv3+ inst/raylrnd.m GPLv3+ inst/raylstat.m GPLv3+ inst/regress_gp.m GPLv3+ inst/regress.m GPLv3+ inst/repanova.m.m GPLv3+ inst/runtest.m GPLv3+ inst/signtest.m GPLv3+ inst/squareform.m GPLv3+ inst/stepwisefit.m GPLv3+ inst/tabulate.m GPLv3+ inst/tblread.m GPLv3+ inst/tblwrite.m GPLv3+ inst/tricdf.m GPLv3+ inst/triinv.m GPLv3+ inst/trimmean.m GPLv3+ inst/tripdf.m GPLv3+ inst/trirnd.m GPLv3+ inst/tstat.m GPLv3+ inst/ttest.m GPLv3+ inst/ttest2.m GPLv3+ inst/unidstat.m GPLv3+ inst/unifstat.m GPLv3+ inst/vartest.m GPLv3+ inst/vartest2.m GPLv3+ inst/violin.m GPLv3+ inst/vmpdf.m GPLv3+ inst/vmrnd.m GPLv3+ inst/wblstat.m GPLv3+ inst/wishpdf.m GPLv3+ inst/wishrnd.m GPLv3+ inst/ztest.m GPLv3+ statistics-1.4.1/PaxHeaders.29769/install-conditionally0000644000000000000000000000013013444214613017723 xustar0028 mtime=1553013131.3138441 30 atime=1553013131.677852968 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/0000755000175000017500000000000013444214613020513 5ustar00johndjohnd00000000000000statistics-1.4.1/install-conditionally/PaxHeaders.29769/base0000644000000000000000000000013113444214613020636 xustar0029 mtime=1553013131.26584293 30 atime=1553013131.677852968 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/0000755000175000017500000000000013444214613021425 5ustar00johndjohnd00000000000000statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/statistics.m0000644000000000000000000000006213443447555023302 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/statistics.m0000644000175000017500000000602613443447555024015 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} statistics (@var{x}) ## @deftypefnx {} {} statistics (@var{x}, @var{dim}) ## Return a vector with the minimum, first quartile, median, third quartile, ## maximum, mean, standard deviation, skewness, and kurtosis of the elements of ## the vector @var{x}. ## ## If @var{x} is a matrix, calculate statistics over the first non-singleton ## dimension. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## @seealso{min, max, median, mean, std, skewness, kurtosis} ## @end deftypefn ## Author: KH ## Description: Compute basic statistics function stats = statistics (x, dim) if (nargin != 1 && nargin != 2) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("statistics: X must be a numeric vector or matrix"); endif nd = ndims (x); sz = size (x); if (nargin != 2) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (!(isscalar (dim) && dim == fix (dim)) || !(1 <= dim && dim <= nd)) error ("statistics: DIM must be an integer and a valid dimension"); endif endif if (sz(dim) < 2) error ("statistics: dimension of X is too small (<2)"); endif emp_inv = quantile (x, [0.25; 0.5; 0.75], dim, 7); stats = cat (dim, min (x, [], dim), emp_inv, max (x, [], dim), mean (x, dim), std (x, [], dim), skewness (x, [], dim), kurtosis (x, [], dim)); endfunction %!test %! x = rand (7,5); %! s = statistics (x); %! assert (min (x), s(1,:), eps); %! assert (median (x), s(3,:), eps); %! assert (max (x), s(5,:), eps); %! assert (mean (x), s(6,:), eps); %! assert (std (x), s(7,:), eps); %! assert (skewness (x), s(8,:), eps); %! assert (kurtosis (x), s(9,:), eps); %! x = rand (7,5); %! s = statistics (x, 2); %! assert (min (x, [], 2), s(:,1), eps); %! assert (median (x, 2), s(:,3), eps); %! assert (max (x, [], 2), s(:,5), eps); %! assert (mean (x, 2), s(:,6), eps); %! assert (std (x, [], 2), s(:,7), eps); %! assert (skewness (x, [], 2), s(:,8), eps); %! assert (kurtosis (x, [], 2), s(:,9), eps); ## Test input validation %!error statistics () %!error statistics (1, 2, 3) %!error statistics (['A'; 'B']) %!error statistics (1, ones (2,2)) %!error statistics (1, 1.5) %!error statistics (1, 0) %!error statistics (1, 3) %!error statistics (1) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/skewness.m0000644000000000000000000000006213443447555022752 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/skewness.m0000644000175000017500000001244013443447555023462 0ustar00johndjohnd00000000000000## Copyright (C) 2013-2017 Julien Bect ## Copyright (C) 1996-2016 John W. Eaton ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} skewness (@var{x}) ## @deftypefnx {} {} skewness (@var{x}, @var{flag}) ## @deftypefnx {} {} skewness (@var{x}, @var{flag}, @var{dim}) ## Compute the sample skewness of the elements of @var{x}. ## ## The sample skewness is defined as ## @tex ## $$ ## {\rm skewness} (@var{x}) = {{{1\over N}\, ## \sum_{i=1}^N (x_i - \bar{x})^3} \over \sigma^3}, ## $$ ## where $N$ is the length of @var{x}, $\bar{x}$ its mean and $\sigma$ ## its (uncorrected) standard deviation. ## @end tex ## @ifnottex ## ## @example ## @group ## mean ((@var{x} - mean (@var{x})).^3) ## skewness (@var{X}) = ------------------------. ## std (@var{x}).^3 ## @end group ## @end example ## ## @end ifnottex ## ## @noindent ## The optional argument @var{flag} controls which normalization is used. ## If @var{flag} is equal to 1 (default value, used when @var{flag} is omitted ## or empty), return the sample skewness as defined above. If @var{flag} is ## equal to 0, return the adjusted skewness coefficient instead: ## @tex ## $$ ## {\rm skewness} (@var{x}) = {\sqrt{N (N - 1)} \over N - 2} \times \, ## {{{1 \over N} \sum_{i=1}^N (x_i - \bar{x})^3} \over \sigma^3} ## $$ ## @end tex ## @ifnottex ## ## @example ## @group ## sqrt (N*(N-1)) mean ((@var{x} - mean (@var{x})).^3) ## skewness (@var{X}, 0) = -------------- * ------------------------. ## (N - 2) std (@var{x}).^3 ## @end group ## @end example ## ## where @math{N} is the length of the @var{x} vector. ## ## @end ifnottex ## The adjusted skewness coefficient is obtained by replacing the sample second ## and third central moments by their bias-corrected versions. ## ## If @var{x} is a matrix, or more generally a multi-dimensional array, return ## the skewness along the first non-singleton dimension. If the optional ## @var{dim} argument is given, operate along this dimension. ## ## @seealso{var, kurtosis, moment} ## @end deftypefn ## Author: KH ## Created: 29 July 1994 ## Adapted-By: jwe function y = skewness (x, flag, dim) if (nargin < 1) || (nargin > 3) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("skewness: X must be a numeric vector or matrix"); endif if (nargin < 2 || isempty (flag)) flag = 1; # default: do not use the "bias corrected" version elseif (! isscalar (flag) || (flag != 0 && flag != 1)) error ("skewness: FLAG must be 0 or 1"); endif nd = ndims (x); sz = size (x); if (nargin < 3) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("skewness: DIM must be an integer and a valid dimension"); endif endif n = size (x, dim); sz(dim) = 1; x = center (x, dim); # center also promotes integer, logical to double s = std (x, 1, dim); # Normalize with 1/N y = sum (x .^ 3, dim); idx = (s != 0); y(idx) ./= (n * s(idx) .^ 3); y(! idx) = NaN; ## Apply bias correction to the second and third central sample moment if (flag == 0) if (n > 2) y *= sqrt (n * (n - 1)) / (n - 2); else y(:) = NaN; endif endif endfunction %!assert (skewness ([-1, 0, 1]), 0) %!assert (skewness ([-2, 0, 1]) < 0) %!assert (skewness ([-1, 0, 2]) > 0) %!assert (skewness ([-3, 0, 1]) == -1 * skewness ([-1, 0, 3])) %!assert (skewness (ones (3, 5)), NaN (1, 5)) %!assert (skewness (1, [], 3), NaN) %!test %! x = [0; 0; 0; 1]; %! y = [x, 2*x]; %! assert (skewness (y), 1.154700538379251 * [1 1], 5*eps); %!assert (skewness ([1:5 10; 1:5 10], 0, 2), 1.439590274527954 * [1; 1], eps) %!assert (skewness ([1:5 10; 1:5 10], 1, 2), 1.051328089232020 * [1; 1], 2*eps) %!assert (skewness ([1:5 10; 1:5 10], [], 2), 1.051328089232020 * [1; 1], 2*eps) ## Test behavior on single input %!assert (skewness (single ([1:5 10])), single (1.0513283), eps ("single")) %!assert (skewness (single ([1 2]), 0), single (NaN)) ## Verify no "divide-by-zero" warnings %!test %! warning ("on", "Octave:divide-by-zero", "local"); %! lastwarn (""); # clear last warning %! skewness (1); %! assert (lastwarn (), ""); ## Test input validation %!error skewness () %!error skewness (1, 2, 3) %!error skewness (['A'; 'B']) %!error skewness (1, 2) %!error skewness (1, [1 0]) %!error skewness (1, [], ones (2,2)) %!error skewness (1, [], 1.5) %!error skewness (1, [], 0) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/kendall.m0000644000000000000000000000006213443447555022522 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/kendall.m0000644000175000017500000000721113443447555023232 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} kendall (@var{x}) ## @deftypefnx {} {} kendall (@var{x}, @var{y}) ## @cindex Kendall's Tau ## Compute Kendall's ## @tex ## $\tau$. ## @end tex ## @ifnottex ## @var{tau}. ## @end ifnottex ## ## For two data vectors @var{x}, @var{y} of common length @math{N}, Kendall's ## @tex ## $\tau$ ## @end tex ## @ifnottex ## @var{tau} ## @end ifnottex ## is the correlation of the signs of all rank differences of ## @var{x} and @var{y}; i.e., if both @var{x} and @var{y} have distinct ## entries, then ## ## @tex ## $$ \tau = {1 \over N(N-1)} \sum_{i,j} {\rm sign}(q_i-q_j) \, {\rm sign}(r_i-r_j) $$ ## @end tex ## @ifnottex ## ## @example ## @group ## 1 ## @var{tau} = ------- SUM sign (@var{q}(i) - @var{q}(j)) * sign (@var{r}(i) - @var{r}(j)) ## N (N-1) i,j ## @end group ## @end example ## ## @end ifnottex ## @noindent ## in which the ## @tex ## $q_i$ and $r_i$ ## @end tex ## @ifnottex ## @var{q}(i) and @var{r}(i) ## @end ifnottex ## are the ranks of @var{x} and @var{y}, respectively. ## ## If @var{x} and @var{y} are drawn from independent distributions, ## Kendall's ## @tex ## $\tau$ ## @end tex ## @ifnottex ## @var{tau} ## @end ifnottex ## is asymptotically normal with mean 0 and variance ## @tex ## ${2 (2N+5) \over 9N(N-1)}$. ## @end tex ## @ifnottex ## @code{(2 * (2N+5)) / (9 * N * (N-1))}. ## @end ifnottex ## ## @code{kendall (@var{x})} is equivalent to @code{kendall (@var{x}, ## @var{x})}. ## @seealso{ranks, spearman} ## @end deftypefn ## Author: KH ## Description: Kendall's rank correlation tau function tau = kendall (x, y = []) if (nargin < 1 || nargin > 2) print_usage (); endif if ( ! (isnumeric (x) || islogical (x)) || ! (isnumeric (y) || islogical (y))) error ("kendall: X and Y must be numeric matrices or vectors"); endif if (ndims (x) != 2 || ndims (y) != 2) error ("kendall: X and Y must be 2-D matrices or vectors"); endif if (isrow (x)) x = x.'; endif [n, c] = size (x); if (nargin == 2) if (isrow (y)) y = y.'; endif if (rows (y) != n) error ("kendall: X and Y must have the same number of observations"); else x = [x, y]; endif endif if (isa (x, "single") || isa (y, "single")) cls = "single"; else cls = "double"; endif r = ranks (x); m = sign (kron (r, ones (n, 1, cls)) - kron (ones (n, 1, cls), r)); tau = corr (m); if (nargin == 2) tau = tau(1 : c, (c + 1) : columns (x)); endif endfunction %!test %! x = [1:2:10]; %! y = [100:10:149]; %! assert (kendall (x,y), 1, 5*eps); %! assert (kendall (x,fliplr (y)), -1, 5*eps); %!assert (kendall (logical (1)), 1) %!assert (kendall (single (1)), single (1)) ## Test input validation %!error kendall () %!error kendall (1, 2, 3) %!error kendall (['A'; 'B']) %!error kendall (ones (2,1), ['A'; 'B']) %!error kendall (ones (2,2,2)) %!error kendall (ones (2,2), ones (2,2,2)) %!error kendall (ones (2,2), ones (3,2)) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/cov.m0000644000000000000000000000006213443447555021677 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/cov.m0000644000175000017500000004230613443447555022413 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## Copyright (C) 2017 Nicholas R. Jankowski ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} cov (@var{x}) ## @deftypefnx {} {} cov (@var{x}, @var{opt}) ## @deftypefnx {} {} cov (@var{x}, @var{y}) ## @deftypefnx {} {} cov (@var{x}, @var{y}, @var{opt}) ## @deftypefnx {} {} cov (@var{x}, @var{y}, @var{opt}, @var{NaN-option}) ## Compute the covariance matrix. ## ## If each row of @var{x} and @var{y} is an observation, and each column is ## a variable, then the @w{(@var{i}, @var{j})-th} entry of ## @code{cov (@var{x}, @var{y})} is the covariance between the @var{i}-th ## variable in @var{x} and the @var{j}-th variable in @var{y}. ## @tex ## $$ ## \sigma_{ij} = {1 \over N-1} \sum_{i=1}^N (x_i - \bar{x})(y_i - \bar{y}) ## $$ ## where $\bar{x}$ and $\bar{y}$ are the mean values of @var{x} and @var{y}. ## @end tex ## @ifnottex ## ## @example ## cov (@var{x}) = 1/(N-1) * SUM_i (@var{x}(i) - mean(@var{x})) * (@var{y}(i) - mean(@var{y})) ## @end example ## ## where @math{N} is the length of the @var{x} and @var{y} vectors. ## ## @end ifnottex ## ## If called with one argument, compute @code{cov (@var{x}, @var{x})}, the ## covariance between the columns of @var{x}. ## ## If called with two vector arguments, compute ## @code{cov (@var{x}, @var{y})}, the covariance between two random variables ## @var{x} and @var{y}. The output will be the 2 by 2 covariance matrix. ## ## If called with two matrix arguments, the matrices are treated as vectors and ## covariance is computed as @code{cov (@var{x}(:), @var{y}(:))}. The output ## will be the 2 by 2 covariance matrix. ## ## The optional argument @var{opt} determines the type of normalization to use. ## Valid values are ## ## @table @asis ## @item 0: ## normalize with @math{N-1}, provides the best unbiased estimator of the ## covariance [default] ## ## @item 1: ## normalize with @math{N}, this provides the second moment around the mean ## @end table ## ## The optional argument @var{NaN-option} controls how @code{cov} deals with NaN ## values in the data. The three valid values are ## ## @table @asis ## @item includenan: ## leave NaN values in @var{x} and @var{y}. Output will follow the normal ## rules for handling NaN values in arithemtic operations [default] ## ## @item omitnans: ## rows containing NaN values are trimmed from both @var{x} and @var{y} prior ## to calculating the covariance. (A NaN in one variable will that row from ## both @var{x} and @var{y}.) ## ## @item partialnans: ## rows containing NaN values are ignored from both @var{x} and @var{y} ## independently when for each @var{i}-th and @var{j}-th covariance ## calculation. This may result in a different number of observations, ## @math{N}, being used to calculated each element of the covariance matrix. ## @end table ## ## Compatibility Note: This version of @code{cov} attempts to maintain full ## compatibility with @sc{matlab}'s cov function by treating @var{x} and ## @var{y} as two univariate distributions regardless of shape, resulting in ## a 2x2 output matrix. Previous versions of cov in Octave treated rows ## of @var{x} and @var{y} as multivariate random variables. Code relying on ## Octave's previous definition will need to be changed when running this newer ## version of @code{cov}. ## @seealso{corr} ## @end deftypefn ## Author: KH ## Author: Nicholas Jankowski ## Description: Compute covariances function c = cov (x, varargin) %%input sorting switch nargin case 1 [y, opt, handlenan] = deal ({"no_y", 0, "includenan"}{:}); case 4 [y, opt, handlenan] = deal (varargin{:}); case {2,3} [y, opt, handlenan] = deal ({"no_y", 0, "includenan"}{:}); for vararg_idx = 1 : (nargin-1) v = varargin{vararg_idx}; if ischar (v) if (vararg_idx == 1 && nargin == 3) error ('cov: NaN handling string must be the last input'); else handlenan = v; endif else if (isscalar(v) && (v == 0 || v == 1)) opt = v; elseif (vararg_idx ~= 2) y = v; else print_usage(); endif endif endfor otherwise print_usage(); endswitch ## check sorted X if ~((isnumeric (x) || islogical (x)) && (ndims (x) == 2)) error ("cov: X must be a numeric 2-D matrix or vector"); endif ##vector x needs to be column for calulations, flip before any nantrimming if (isrow (x)) x = x'; endif if ~(strcmp (y, "no_y")) ## check sorted Y assuming one is given if ~((isnumeric (y) || islogical (y)) && (ndims (y) == 2)) error ("cov: Y must be a numeric 2-D matrix or vector"); endif if (numel (x) ~= numel (y)) error ("cov: X and Y must have the same number of elements"); endif endif ## check sorted opt if (opt ~= 0 && opt ~= 1) error ("cov: normalization factor OPT must be either 0 or 1"); endif ## check sorted NaN handling switch, correct for spelling, adjust x and y switch handlenan case {"includenan"} ## okay, do nothing case {"omitrows", "omitrow"} handlenan = "omitrows"; if (strcmp (y, "no_y")) #trim out rows with nans from x x = x(~any (isnan (x), 2), :); else nan_locs = any (isnan ([x(:), y(:)]), 2); x = x(~nan_locs); y = y(~nan_locs); endif case {"partialrows", "partialrow"} handlenan = "partialrows"; if ~(strcmp (y, "no_y")) ##no need to handle anything differently for single input x_nan_locs = any (isnan (x(:)), 2); y_nan_locs = any (isnan (y(:)), 2); both_nan_locs = any (isnan ([x(:), y(:)]), 2); x_xytrim = x(~both_nan_locs); y_xytrim = y(~both_nan_locs); x = x(~x_nan_locs); y = y(~y_nan_locs); endif otherwise error (["cov: unknown NaN handling parameter, '", handlenan, "'"]); endswitch ## opt being single shouldn't affect output if (isa (opt, "single")) opt = double (opt); endif ## end input sorting/checking ## Primary handling difference is whether there are one or two inputs. if (strcmp (y, "no_y")) ## Special case, scalar has zero covariance if (isscalar (x)) if isnan (x) c = NaN; else c = 0; endif if (isa (x, "single")) c = single (c); endif return; elseif (isempty (x)) %not scalar x, check if empty sx = size (x); if all (sx == 0) c = NaN; elseif (sx(1) > 0) c = []; else c = NaN (sx(2)); endif if (isa (x, "single")) c = single (c); endif return; else %not scalar x, not empty, no y, generate covariance matrix if strcmp (handlenan, 'partialrows') ## if 'partialrows', need to calc each element separately with 'omitrows' ## c(i,j) is cov(x(:,i),x(:,j),'omitrows) ## TODO: find more efficient method. maybe can flatten recursion szx = size (x); for rw = 1:szx(1) for cl = 1:szx(2) c(rw,cl) = (cov (x(:,rw), x(:,cl), 'omitrows'))(2); endfor endfor return else ## if some elements are NaN, they propagate through calc as needed n = rows (x); x = center (x, 1); if n == 1 c = x' * x; %% to handle case of omitrows trimming to 1 row else c = x' * x / (n - 1 + opt); %will preserve single type endif return; endif endif else %there is a y if (isscalar (x)) if (isnan (x) || isnan (y)) c = NaN (2, 2); if ~isnan (x) c(1,1) = 0; elseif ~isnan (y) c(2,2) = 0; endif if (isa (x, "single") || isa (y, "single") ) c = single (c); endif return; else %scalar but neither a nan... both should be numbers... if (isa (x, "single") || isa (y, "single") ) c = single ([0 0; 0 0]); else c = [0 0; 0 0]; endif return; endif else % matrix or vector handled the same way, generate 2x2 covariance matrix if (isempty (x) || isempty (y)) if (isa (x, "single") || isa (y, "single") ) c = single (NaN (2, 2)); else c = NaN (2, 2); endif return; endif if (~strcmp (handlenan, 'partialrows')) denom = numel(x) - 1 + opt; x = center (x(:), 1); y = center (y(:), 1); c1 = x' * x; c23 = x' * y; c4 = y' * y; c = [c1, c23; c23, c4] ./ denom; return; else ## 'partialrows': handle each element separatley denom_xy = numel (x_xytrim) - 1 + opt; x_xytrim = center (x_xytrim(:), 1); y_xytrim = center (y_xytrim(:), 1); c23 = (x_xytrim' * y_xytrim) ./ denom_xy; denom_x = numel(x) - 1 + opt; x = center (x(:), 1); c1 = (x' * x) ./ denom_x; denom_y = numel(y) - 1 + opt; y = center (y(:), 1); c4 = (y' * y) ./ denom_y; c = [c1, c23; c23, c4]; return; endif endif endif endfunction %!test %! x = rand (10); %! cx1 = cov (x); %! cx2 = cov (x, x); %! assert (size (cx1) == [10, 10] && size (cx2) == [2, 2]); %! assert (cx2 - cx2(1), zeros (2, 2), eps); %!test %! x = [1:3]'; %! y = [3:-1:1]'; %! assert (cov (x, y), [1 -1; -1 1]); %! assert (cov (x, flipud (y)), ones (2, 2)); %! assert (cov ([x, y]), [1 -1; -1 1]); %!test %! x = single ([1:3]'); %! y = single ([3:-1:1]'); %! assert (cov (x, y), single ([1 -1; -1 1])); %! assert (cov (x, flipud (y)), single (ones (2, 2))); %! assert (cov ([x, y]), single ([1 -1; -1 1])); %!test %! x = [0 2 4]; %! y = [3 2 1]; %! z = [4 -2; -2 1]; %! assert (cov (x, y), z); %! assert (cov (single (x), y), single (z)); %! assert (cov (x, single (y)), single (z)); %! assert (cov (single (x), single (y)), single (z)); %!test %! x = [1:5]; %! c = cov (x); %! assert (c, 2.5); %!test %! x = [1:5]; %! c = cov (x, 0); %! assert (c, 2.5); %! c = cov (x, 1); %! assert (c, 2); %! c = cov (x, single (1)); %! assert (c, double (2)); %!test %! x = [5 0 3 7; 1 -5 7 3; 4 9 8 10]; %! b = [13/3 53/6 -3 17/3; 53/6 151/3 6.5 145/6; -3 6.5 7 1; 17/3 145/6 1 37/3]; %! assert (cov (x), b, 50*eps); %!test %! x = [3 6 4]; %! y = [7 12 -9]; %! assert (cov (x, y), [7, 20.5; 20.5, 361]./3, 50*eps); %!test %! x = [2 0 -9; 3 4 1]; %! y = [5 2 6; -4 4 9]; %! assert (cov (x, y), [66.5, -20.8; -20.8, 58.4]./3, 50*eps); %!test %! x = [1 3 -7; 3 9 2; -5 4 6]; %! assert (cov (x, 1), [104 46 -92; 46 62 47; -92 47 266]./9, 50*eps); %!test %! x = [1 0; 1 0]; %! y = [1 2; 1 1]; %! assert (cov (x, y), [1/3 -1/6; -1/6 0.25], 50*eps); %! assert (cov (x, y(:)), [1/3 -1/6; -1/6 0.25], 50*eps); %! assert (cov (x, y(:)'), [1/3 -1/6; -1/6 0.25], 50*eps); %! assert (cov (x', y(:)), [1/3 1/6; 1/6 0.25], 50*eps); %! assert (cov (x(:), y), [1/3 -1/6; -1/6 0.25], 50*eps); %! assert (cov (x(:)', y), [1/3 -1/6; -1/6 0.25], 50*eps); %!assert (cov (5), 0) %!assert (cov (single (5)), single (0)) %!assert (cov (1, 3), zeros (2, 2)) %!assert (cov (5, 0), 0) %!assert (cov (5, 1), 0) %!assert (cov (5, 2), zeros (2, 2)) %!assert (cov (5, 99), zeros (2, 2)) %!assert (cov (logical(0), logical(0)), double(0)) %!assert (cov (0, logical(0)), double(0)) %!assert (cov (logical(0), 0), double(0)) %!assert (cov (logical([0 1; 1 0]), logical([0 1; 1 0])), double ([1 1;1 1]./3)) ## Test empty and NaN handling (bug #48690) ## TODO: verify compatibily for matlab > 2016b !assert (cov ([]), NaN) %!assert (cov (single ([])), single (NaN)) %!assert (cov ([], []), NaN (2, 2)) %!assert (cov (single ([]), single([])), single (NaN (2, 2))) %!assert (cov ([], single ([])), single (NaN (2, 2))) %!assert (cov (single ([]), []), single (NaN (2, 2))) %!assert (cov (ones(2, 0)), []) %!assert (cov (ones(0, 2)), NaN (2, 2)) %!assert (cov (ones(0, 6)), NaN (6, 6)) %!assert (cov (ones(2, 0), []), NaN (2, 2)) %!assert (cov (NaN), NaN) %!assert (cov (NaN, NaN), NaN (2, 2)) %!assert (cov (5, NaN), [0, NaN; NaN, NaN]) %!assert (cov (NaN, 5), [NaN, NaN; NaN, 0]) %!assert (cov (single (NaN)), single (NaN)) %!assert (cov (NaN (2, 2)), NaN (2, 2)) %!assert (cov (single (NaN (2, 2))), single (NaN (2, 2))) %!assert (cov (NaN(2, 9)), NaN(9, 9)) %!assert (cov (NaN(9, 2)), NaN(2, 2)) %!assert (cov ([NaN, 1, 2, NaN]), NaN) %!assert (cov ([1, NaN, 2, NaN]), NaN) ## Test nan handling parameter, 1 input %!test %! x = [1 3 -7; NaN 9 NaN; -5 4 6]; %! y1 = [NaN NaN NaN;NaN 31/3 NaN;NaN NaN NaN]; %! y2 = [28 NaN -15;NaN NaN NaN;-15 NaN 103/3]; %! y3 = [18 -3 -39; -3 0.5 6.5; -39 6.5 84.5]; %! assert (cov (x), y1, 50*eps); %! assert (cov (x'), y2, 50*eps); %! assert (cov (x, 'includenan'), y1, 50*eps); %! assert (cov (x', 'includenan'), y2, 50*eps); %! assert (cov (x, 'omitrows'), y3, 50*eps); %! assert (cov (x', 'omitrows'), zeros(3, 3), 50*eps); %! y3(2,2) = 31/3; %! assert (cov (x, 'partialrows'), y3, 50*eps); %! y2(isnan (y2)) = 0; %! assert (cov (x', 'partialrows'), y2, 50*eps); ## Test nan handling parameter, 2 inputs %!test %! x = magic (3); %! x(1) = NaN; %! y = magic (3)'; %! assert (cov (x, y), [NaN, NaN; NaN, 7.5]); %! assert (cov (x', y), [NaN, NaN; NaN, 7.5]); %! assert (cov (x, y'), [NaN, NaN; NaN, 7.5]); %! assert (cov (x', y'), [NaN, NaN; NaN, 7.5]); %! assert (cov (x, y, 'omitrows'), [57/8 303/56; 303/56 57/8]); %! assert (cov (x', y, 'omitrows'), [57/8 57/8; 57/8 57/8]); %! assert (cov (x, y', 'omitrows'), [57/8 57/8; 57/8 57/8]); %! assert (cov (x', y', 'omitrows'), [57/8 303/56; 303/56 57/8]); %! assert (cov (x, y, 'partialrows'), [57/8 303/56; 303/56 7.5]); %! assert (cov (x', y, 'partialrows'), [57/8 57/8; 57/8 7.5]); %! assert (cov (x, y', 'partialrows'), [57/8 57/8; 57/8 7.5]); %! assert (cov (x', y', 'partialrows'), [57/8 303/56; 303/56 7.5]); %! assert (cov (y, x), [7.5, NaN; NaN, NaN]); %! assert (cov (y', x), [7.5, NaN; NaN, NaN]); %! assert (cov (y, x'), [7.5, NaN; NaN, NaN]); %! assert (cov (y', x'), [7.5, NaN; NaN, NaN]); %! assert (cov (y, x, 'omitrows'), [57/8 303/56; 303/56 57/8]); %! assert (cov (y', x, 'omitrows'), [57/8 57/8; 57/8 57/8]); %! assert (cov (y, x', 'omitrows'), [57/8 57/8; 57/8 57/8]); %! assert (cov (y', x', 'omitrows'), [57/8 303/56; 303/56 57/8]); %! assert (cov (y, x, 'partialrows'), [7.5 303/56; 303/56 57/8]); %! assert (cov (y', x, 'partialrows'), [7.5 57/8; 57/8 57/8]); %! assert (cov (y, x', 'partialrows'), [7.5 57/8; 57/8 57/8]); %! assert (cov (y', x', 'partialrows'), [7.5 303/56; 303/56 57/8]); ## Test nan handling parameter, 2 inputs, vectors %!test %! x = [1:5]; %! y = [10:-2:2]; %! assert (cov (x, y), [2.5 -5; -5 10]); %! assert (cov ([x NaN], [y 1]), [NaN NaN; NaN, 73/6], 50*eps); %! assert (cov ([x NaN], [y 1], 'omitrows'), [2.5 -5; -5 10],50*eps); %! assert (cov ([x NaN], [y 1], 'partialrows'), [2.5 -5; -5 73/6],50*eps); %! assert (cov ([x 1], [y NaN]), [8/3 NaN; NaN, NaN],50*eps); %! assert (cov ([x 1], [y NaN], 'omitrows'), [2.5 -5; -5 10],50*eps); %! assert (cov ([x 1], [y NaN], 'partialrows'), [8/3 -5; -5 10],50*eps); %! assert (cov ([NaN x], [y NaN], 'omitrows'), [5/3 -10/3; -10/3 20/3],50*eps); %! assert (cov ([NaN x], [y NaN], 'partialrows'), [2.5 -10/3; -10/3 10],50*eps); ## Test nan handling parameter, one matrix trimmed to vector %!test %! x = magic(3); %! y = magic (3) - 2; %! assert (cov (x, y), [7.5 7.5; 7.5 7.5]); %! x(3:4) = NaN; %! assert (cov (x), [NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, 7]); %! assert (cov (x, 'omitrows'), zeros (3, 3)); %! assert (cov (x, 'partialrows'), [12.5 0 -2.5; 0 8 -10; -2.5 -10 7]); %! assert (cov (x, y), [NaN, NaN; NaN, 7.5]); %! assert (cov (x, y, 'omitrows'), [46/7, 46/7; 46/7, 46/7], 50*eps); %! assert (cov (x, y, 'partialrows'), [46/7, 46/7; 46/7, 7.5], 50*eps); %! assert (cov (y, x), [7.5, NaN; NaN, NaN]); %! assert (cov (y, x, 'omitrows'), [46/7, 46/7; 46/7, 46/7], 50*eps); %! assert (cov (y, x, 'partialrows'), [7.5, 46/7; 46/7, 46/7], 50*eps); ## Test input validation %!error cov () %!error cov (1, 2, 3, 4) %!error cov (5,[1 2]) %!error cov ([1; 2], ["A", "B"]) %!error cov (ones (2, 2, 2)) %!error cov (ones (2, 2), ones (2, 2, 2)) %!error cov (ones (2, 2), ones (3, 2)) %!error cov (1, []) %!error cov (ones (1, 0, 2)) %!error cov ([1, 2],ones(1, 0, 2)) %!error cov (1, 2, []) %!error cov (1, 2, 1, []) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/gls.m0000644000000000000000000000006213443447555021675 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/gls.m0000644000175000017500000000756313443447555022417 0ustar00johndjohnd00000000000000## Copyright (C) 1996-2017 John W. Eaton ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {[@var{beta}, @var{v}, @var{r}] =} gls (@var{y}, @var{x}, @var{o}) ## Generalized least squares model. ## ## Perform a generalized least squares estimation for the multivariate model ## @tex ## $y = x b + e$ ## with $\bar{e} = 0$ and cov(vec($e$)) = $(s^2)o$, ## @end tex ## @ifnottex ## @w{@math{y = x*b + e}} with @math{mean (e) = 0} and ## @math{cov (vec (e)) = (s^2) o}, ## @end ifnottex ## where ## @tex ## $y$ is a $t \times p$ matrix, $x$ is a $t \times k$ matrix, $b$ is a $k ## \times p$ matrix, $e$ is a $t \times p$ matrix, and $o$ is a $tp \times ## tp$ matrix. ## @end tex ## @ifnottex ## @math{y} is a @math{t} by @math{p} matrix, @math{x} is a @math{t} by ## @math{k} matrix, @math{b} is a @math{k} by @math{p} matrix, @math{e} ## is a @math{t} by @math{p} matrix, and @math{o} is a @math{t*p} by ## @math{t*p} matrix. ## @end ifnottex ## ## @noindent ## Each row of @var{y} and @var{x} is an observation and each column a ## variable. The return values @var{beta}, @var{v}, and @var{r} are ## defined as follows. ## ## @table @var ## @item beta ## The GLS estimator for @math{b}. ## ## @item v ## The GLS estimator for @math{s^2}. ## ## @item r ## The matrix of GLS residuals, @math{r = y - x*beta}. ## @end table ## @seealso{ols} ## @end deftypefn ## Author: Teresa Twaroch ## Created: May 1993 ## Adapted-By: jwe function [beta, v, r] = gls (y, x, o) if (nargin != 3) print_usage (); endif if (! (isnumeric (x) && isnumeric (y) && isnumeric (o))) error ("gls: X, Y, and O must be numeric matrices or vectors"); endif if (ndims (x) != 2 || ndims (y) != 2 || ndims (o) != 2) error ("gls: X, Y and O must be 2-D matrices or vectors"); endif [rx, cx] = size (x); [ry, cy] = size (y); [ro, co] = size (o); if (rx != ry) error ("gls: number of rows of X and Y must be equal"); endif if (! issquare (o) || ro != ry*cy) error ("gls: matrix O must be square matrix with rows = rows (Y) * cols (Y)"); endif if (isinteger (x)) x = double (x); endif if (isinteger (y)) y = double (y); endif if (isinteger (o)) o = double (o); endif ## Start of algorithm o ^= -1/2; z = kron (eye (cy), x); z = o * z; y1 = o * reshape (y, ry*cy, 1); u = z' * z; r = rank (u); if (r == cx*cy) b = inv (u) * z' * y1; else b = pinv (z) * y1; endif beta = reshape (b, cx, cy); if (isargout (2) || isargout (3)) r = y - x * beta; if (isargout (2)) v = (reshape (r, ry*cy, 1))' * (o^2) * reshape (r, ry*cy, 1) / (rx*cy - r); endif endif endfunction %!test %! x = [1:5]'; %! y = 3*x + 2; %! x = [x, ones(5,1)]; %! o = diag (ones (5,1)); %! assert (gls (y,x,o), [3; 2], 50*eps); ## Test input validation %!error gls () %!error gls (1) %!error gls (1, 2) %!error gls (1, 2, 3, 4) %!error gls ([true, true], [1, 2], ones (2)) %!error gls ([1, 2], [true, true], ones (2)) %!error gls ([1, 2], [1, 2], true (2)) %!error gls (ones (2,2,2), ones (2,2), ones (4,4)) %!error gls (ones (2,2), ones (2,2,2), ones (4,4)) %!error gls (ones (2,2), ones (2,2), ones (4,4,4)) %!error gls (ones (1,2), ones (2,2), ones (2,2)) %!error gls (ones (2,2), ones (2,2), ones (2,2)) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/mode.m0000644000000000000000000000006213443447555022034 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/mode.m0000644000175000017500000003230513443447555022546 0ustar00johndjohnd00000000000000## Copyright (C) 2007-2017 David Bateman ## Copyright (C) 2017 Nicholas R. Jankowski ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} mode (@var{x}) ## @deftypefnx {} {} mode (@var{x}, @var{dim}) ## @deftypefnx {} {[@var{m}, @var{f}, @var{c}] =} mode (@dots{}) ## Compute the most frequently occurring value in a dataset (mode). ## ## @code{mode} determines the frequency of values along the first non-singleton ## dimension and returns the value with the highest frequency. If two, or ## more, values have the same frequency @code{mode} returns the smallest. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## ## The return variable @var{f} is the number of occurrences of the mode in ## the dataset. ## ## The cell array @var{c} contains all of the elements with the maximum ## frequency. ## @seealso{mean, median} ## @end deftypefn function [m, f, c] = mode (x, dim) if (nargin < 1 || nargin > 2) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("mode: X must be a numeric vector or matrix"); endif nd = ndims (x); sz = size (x); if (nargin < 2) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("mode: DIM must be an integer and a valid dimension"); endif endif if (isempty (x)) %% codepath for Matlab compatibility. empty x produces NaN output, but %% m f and c shape depends on size of x. if ((nargin == 1) && (nd == 2) && (sz == [0 0])) f = 0; %seems to always be a double even if x is single if (isa (x, "single")) m = single (NaN); c = {(single (NaN (0, 1)))}; else m = NaN; c = {(NaN (0, 1))}; endif else if (nargin == 2) sz(dim) = 1; else sz (find ((sz ~= 1), 1)) = 1; endif f = zeros (sz); %seems to always be a double even if x is single if (isa (x, "single")) m = single (NaN (sz)); c = cell (sz); c(:) = {(single (NaN (1, 0)))}; else m = NaN (sz); c = cell (sz); c(:) = {(NaN (1, 0))}; endif endif return endif if (dim > nd) ## Special case of mode over non-existent dimension. m = x; f = ones (size (x)); c = num2cell (x); return; endif sz2 = sz; sz2(dim) = 1; sz3 = ones (1, nd); sz3(dim) = sz(dim); if (issparse (x)) t2 = sparse (sz(1), sz(2)); else t2 = zeros (sz); endif if (dim != 1) perm = [dim, 1:dim-1, dim+1:nd]; t2 = permute (t2, perm); endif xs = sort (x, dim); t = cat (dim, true (sz2), diff (xs, 1, dim) != 0); if (dim != 1) t2(permute (t != 0, perm)) = diff ([find(permute (t, perm))(:); prod(sz)+1]); f = max (ipermute (t2, perm), [], dim); xs = permute (xs, perm); else t2(t) = diff ([find(t)(:); prod(sz)+1]); f = max (t2, [], dim); endif c = cell (sz2); if (issparse (x)) m = sparse (sz2(1), sz2(2)); else m = zeros (sz2, class (x)); endif for i = 1 : prod (sz2) c{i} = xs(t2(:, i) == f(i), i); m(i) = c{i}(1); endfor endfunction %!test %! [m, f, c] = mode (toeplitz (1:5)); %! assert (m, [1, 2, 2, 2, 1]); %! assert (f, [1, 2, 2, 2, 1]); %! assert (c, {[1; 2; 3; 4; 5], [2], [2; 3], [2], [1; 2; 3; 4; 5]}); %!test %! [m, f, c] = mode (toeplitz (1:5), 2); %! assert (m, [1; 2; 2; 2; 1]); %! assert (f, [1; 2; 2; 2; 1]); %! assert (c, {[1; 2; 3; 4; 5]; [2]; [2; 3]; [2]; [1; 2; 3; 4; 5]}); %!test %! a = sprandn (32, 32, 0.05); %! sp0 = sparse (0); %! [m, f, c] = mode (a); %! [m2, f2, c2] = mode (full (a)); %! assert (m, sparse (m2)); %! assert (f, sparse (f2)); %! c_exp(1:length (a)) = { sp0 }; %! assert (c , c_exp); %! assert (c2, c_exp); %!assert (mode ([2, 3, 1, 2, 3, 4] ,1), [2, 3, 1, 2, 3, 4]) %!assert (mode ([2, 3, 1, 2, 3, 4], 2), 2) %!assert (mode ([2, 3, 1, 2, 3, 4]), 2) %!assert (mode (single ([2, 3, 1, 2, 3, 4])), single (2)) %!assert (mode (int8 ([2, 3, 1, 2, 3, 4])), int8 (2)) %!assert (mode ([2; 3; 1; 2; 3; 4], 1), 2) %!assert (mode ([2; 3; 1; 2; 3; 4], 2), [2; 3; 1; 2; 3; 4]) %!assert (mode ([2; 3; 1; 2; 3; 4]), 2) %!test %! x = magic (3); %! [m, f, c] = mode (x, 3); %! assert (m, x); %! assert (f, ones (3, 3)); %! assert (c, num2cell (x)); %!shared x %! x(:,:,1) = toeplitz (1:3); %! x(:,:,2) = circshift (toeplitz (1:3), 1); %! x(:,:,3) = circshift (toeplitz (1:3), 2); %!test %! [m, f, c] = mode (x, 1); %! assert (reshape (m, [3, 3]), [1 1 1; 2 2 2; 1 1 1]); %! assert (reshape (f, [3, 3]), [1 1 1; 2 2 2; 1 1 1]); %! c = reshape (c, [3, 3]); %! assert (c{1}, [1; 2; 3]); %! assert (c{2}, 2); %! assert (c{3}, [1; 2; 3]); %!test %! [m, f, c] = mode (x, 2); %! assert (reshape (m, [3, 3]), [1 1 2; 2 1 1; 1 2 1]); %! assert (reshape (f, [3, 3]), [1 1 2; 2 1 1; 1 2 1]); %! c = reshape (c, [3, 3]); %! assert (c{1}, [1; 2; 3]); %! assert (c{2}, 2); %! assert (c{3}, [1; 2; 3]); %!test %! [m, f, c] = mode (x, 3); %! assert (reshape (m, [3, 3]), [1 2 1; 1 2 1; 1 2 1]); %! assert (reshape (f, [3, 3]), [1 2 1; 1 2 1; 1 2 1]); %! c = reshape (c, [3, 3]); %! assert (c{1}, [1; 2; 3]); %! assert (c{2}, [1; 2; 3]); %! assert (c{3}, [1; 2; 3]); ## Test input validation %!error mode () %!error mode (1, 2, 3) %!error mode ({1 2 3}) %!error mode (1, ones (2,2)) %!error mode (1, 1.5) %!error mode (1, 0) ## Tests for empty input Matlab compatibility (bug #48690) %!test %! [m, f, c] = mode ([]); %! assert (m, NaN); %! assert (f, 0); %! assert (c, {(NaN (0, 1))}); %!test %! [m, f, c] = mode (single ([])); %! assert (m, single (NaN)); %! assert (f, double (0)); %! assert (c, {(single (NaN (0, 1)))}); %!test %! [m, f, c] = mode (ones (0, 1)); %! assert (m, NaN); %! assert (f, 0); %! assert (c, {(NaN (1, 0))}); %!test %! [m, f, c] = mode (ones (1, 0)); %! assert (m, NaN); %! assert (f, 0); %! assert (c, {(NaN (1, 0))}); %!test %! [m, f, c] = mode (single (ones (1, 0))); %! assert (m, single (NaN)); %! assert (f, double (0)); %! assert (c, {(single (NaN (1, 0)))}); %!test %! [m, f, c] = mode (ones (2, 0)); %! assert (m, NaN (1, 0)); %! assert (f, zeros (1, 0)); %! assert (c, cell (1, 0)); %!test %! [m, f, c] = mode (ones (0, 2)); %! assert (m, NaN (1, 2)); %! assert (f, zeros (1, 2)); %! assert (c, {(NaN (1, 0)),(NaN (1, 0))}); %!test %! [m, f, c] = mode (single (ones (2, 0))); %! assert (m, single (NaN (1, 0))); %! assert (f, zeros (1, 0)); %! assert (c, cell (1, 0)); %!test %! [m, f, c] = mode (ones (0, 0, 1, 0)); %! assert (m, NaN (1, 0, 1, 0)); %! assert (f, zeros (1, 0, 1, 0)); %! assert (c, cell (1, 0, 1, 0)); %!test %! [m, f, c] = mode (ones (1, 1, 1, 0)); %! assert (m, NaN (1, 1)); %! assert (f, zeros (1, 1)); %! assert (c, {(NaN (1, 0))}); %!assert (mode (ones (0, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (mode (ones (0, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (mode (ones (0, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (mode (ones (0, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (mode (ones (0, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (mode (ones (0, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (mode (ones (0, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (mode (ones (0, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (mode (ones (0, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (mode (ones (0, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (mode (ones (0, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (mode (ones (0, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (mode (ones (0, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (mode (ones (0, 1, 1, 1)), NaN (1, 1, 1, 1)) %!assert (mode (ones (0, 1, 1, 2)), NaN (1, 1, 1, 2)) %!assert (mode (ones (0, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (mode (ones (0, 1, 2, 1)), NaN (1, 1, 2, 1)) %!assert (mode (ones (0, 1, 2, 2)), NaN (1, 1, 2, 2)) %!assert (mode (ones (0, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (mode (ones (0, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (mode (ones (0, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (mode (ones (0, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (mode (ones (0, 2, 1, 1)), NaN (1, 2, 1, 1)) %!assert (mode (ones (0, 2, 1, 2)), NaN (1, 2, 1, 2)) %!assert (mode (ones (0, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (mode (ones (0, 2, 2, 1)), NaN (1, 2, 2, 1)) %!assert (mode (ones (0, 2, 2, 2)), NaN (1, 2, 2, 2)) %!assert (mode (ones (1, 0, 0, 0)), NaN (1, 1, 0, 0)) %!assert (mode (ones (1, 0, 0, 1)), NaN (1, 1, 0, 1)) %!assert (mode (ones (1, 0, 0, 2)), NaN (1, 1, 0, 2)) %!assert (mode (ones (1, 0, 1, 0)), NaN (1, 1, 1, 0)) %!assert (mode (ones (1, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (mode (ones (1, 0, 1, 2)), NaN (1, 1, 1, 2)) %!assert (mode (ones (1, 0, 2, 0)), NaN (1, 1, 2, 0)) %!assert (mode (ones (1, 0, 2, 1)), NaN (1, 1, 2, 1)) %!assert (mode (ones (1, 0, 2, 2)), NaN (1, 1, 2, 2)) %!assert (mode (ones (1, 1, 0, 0)), NaN (1, 1, 1, 0)) %!assert (mode (ones (1, 1, 0, 1)), NaN (1, 1, 1, 1)) %!assert (mode (ones (1, 1, 0, 2)), NaN (1, 1, 1, 2)) %!assert (mode (ones (1, 1, 1, 0)), NaN (1, 1, 1, 1)) %!assert (mode (ones (1, 1, 2, 0)), NaN (1, 1, 1, 0)) %!assert (mode (ones (1, 2, 0, 0)), NaN (1, 1, 0, 0)) %!assert (mode (ones (1, 2, 0, 1)), NaN (1, 1, 0, 1)) %!assert (mode (ones (1, 2, 0, 2)), NaN (1, 1, 0, 2)) %!assert (mode (ones (1, 2, 1, 0)), NaN (1, 1, 1, 0)) %!assert (mode (ones (1, 2, 2, 0)), NaN (1, 1, 2, 0)) %!assert (mode (ones (2, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (mode (ones (2, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (mode (ones (2, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (mode (ones (2, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (mode (ones (2, 0, 1, 1)), NaN (1, 0, 1, 1)) %!assert (mode (ones (2, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (mode (ones (2, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (mode (ones (2, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (mode (ones (2, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (mode (ones (2, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (mode (ones (2, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (mode (ones (2, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (mode (ones (2, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (mode (ones (2, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (mode (ones (2, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (mode (ones (2, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (mode (ones (2, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (mode (ones (2, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (mode (ones (2, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (mode (ones (1, 1, 0, 0, 0)), NaN (1, 1, 1, 0, 0)) %!assert (mode (ones (1, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 1)) %!assert (mode (ones (2, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) %!assert (mode (ones (1, 2, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) ## Tests for empty input with DIM call %!test %! [m, f, c] = mode ([], 1); %! assert (m, NaN (1,0)); %! assert (f, zeros (1,0)); %! assert (c, cell (1,0)); %!test %! [m, f, c] = mode ([], 2); %! assert (m, NaN (0,1)); %! assert (f, zeros (0,1)); %! assert (c, cell (0,1)); %!test %! [m, f, c] = mode ([], 3); %! assert (m, []); %! assert (f, []); %! assert (c, {}); %!test %! [m, f, c] = mode (single([]), 1); %! assert (m, single (NaN (1,0))); %! assert (f, double (zeros (1,0))); %! assert (c, cell (1,0)); %!test %! [m, f, c] = mode (single([]), 2); %! assert (m, single (NaN (0,1))); %! assert (f, double (zeros (0,1))); %! assert (c, cell (0,1)); %!test %! [m, f, c] = mode (single([]), 3); %! assert (m, single([])); %! assert (f, []); %! assert (c, {}); %!test %! [m, f, c] = mode (ones(1,0), 1); %! assert (m, NaN (1,0)); %! assert (f, zeros (1,0)); %! assert (c, cell (1,0)); %!test %! [m, f, c] = mode (ones(1,0), 2); %! assert (m, NaN); %! assert (f, 0); %! assert (c, {(NaN (1,0))}); %!test %! [m, f, c] = mode (ones(1,0), 3); %! assert (m, NaN (1,0)); %! assert (f, zeros (1,0)); %! assert (c, cell (1,0)); %!test %! [m, f, c] = mode (ones(0,1), 1); %! assert (m, NaN); %! assert (f, 0); %! assert (c, {(NaN (1,0))}); %!test %! [m, f, c] = mode (ones(0,1), 2); %! assert (m, NaN (0,1)); %! assert (f, zeros (0,1)); %! assert (c, cell (0,1)); %!test %! [m, f, c] = mode (ones(0,1), 3); %! assert (m, NaN (0,1)); %! assert (f, zeros (0,1)); %! assert (c, cell (0,1)); %!test %! [m, f, c] = mode (ones(0,0,1), 1); %! assert (m, NaN (1,0)); %! assert (f, zeros (1,0)); %! assert (c, cell (1,0)); %!test %! [m, f, c] = mode (ones(0,0,1), 2); %! assert (m, NaN (0,1)); %! assert (f, zeros (0,1)); %! assert (c, cell (0,1)); %!test %! [m, f, c] = mode (ones(0,0,1), 3); %! assert (m, []); %! assert (f, []); %! assert (c, {}); %!test %! [m, f, c] = mode (ones(1,0,1), 1); %! assert (m, NaN (1,0)); %! assert (f, zeros (1,0)); %! assert (c, cell (1,0)); %!test %! [m, f, c] = mode (ones(1,0,1), 2); %! assert (m, NaN); %! assert (f, 0); %! assert (c, {(NaN (1,0))}); %!test %! [m, f, c] = mode (ones(1,0,1), 3); %! assert (m, NaN (1,0)); %! assert (f, zeros (1,0)); %! assert (c, cell (1,0)); statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/corrcoef.m0000644000000000000000000000006213443447555022712 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/corrcoef.m0000644000175000017500000001516313443447555023427 0ustar00johndjohnd00000000000000## Copyright (C) 2016-2017 Guillaume Flandin ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {@var{r} =} corrcoef (@var{x}) ## @deftypefnx {} {@var{r} =} corrcoef (@var{x}, @var{y}) ## @deftypefnx {} {[@var{r}, @var{p}] =} corrcoef (@dots{}) ## @deftypefnx {} {[@var{r}, @var{p}, @var{lci}, @var{hci}] =} corrcoef (@dots{}) ## @deftypefnx {} {[@dots{}] =} corrcoef (@dots{}, @var{param}, @var{value}, @dots{}) ## Compute a matrix of correlation coefficients. ## ## @var{x} is an array where each column contains a variable and each row is ## an observation. ## ## If a second input @var{y} (of the same size as @var{x}) is given then ## calculate the correlation coefficients between @var{x} and @var{y}. ## ## @var{r} is a matrix of Pearson's product moment correlation coefficients for ## each pair of variables. ## ## @var{p} is a matrix of pair-wise p-values testing for the null hypothesis of ## a correlation coefficient of zero. ## ## @var{lci} and @var{hci} are matrices containing, respectively, the lower and ## higher bounds of the 95% confidence interval of each correlation ## coefficient. ## ## @var{param}, @var{value} are pairs of optional parameters and values. ## Valid options are: ## ## @table @asis ## @item @qcode{"alpha"} ## Confidence level used for the definition of the bounds of the confidence ## interval, @var{lci} and @var{hci}. Default is 0.05, i.e., 95% confidence ## interval. ## ## @item @qcode{"rows"} ## Determine processing of NaN values. Acceptable values are @qcode{"all"}, ## @qcode{"complete"}, and @qcode{"pairwise"}. Default is @qcode{"all"}. ## With @qcode{"complete"}, only the rows without NaN values are considered. ## With @qcode{"pairwise"}, the selection of NaN-free rows is made for each ## pair of variables. ## ## @end table ## ## @seealso{corr, cov, cor_test} ## @end deftypefn ## FIXME: It would be good to add a definition of the calculation method ## for a Pearson product moment correlation to the documentation. function [r, p, lci, hci] = corrcoef (x, varargin) if (nargin == 0) print_usage (); endif alpha = 0.05; rows = "all"; if (nargin > 1) ## Check for numeric y argument if (isnumeric (varargin{1})) x = [x(:), varargin{1}(:)]; varargin(1) = []; endif ## Check for Parameter/Value arguments for i = 1:2:numel (varargin) if (! ischar (varargin{i})) error ("corrcoef: parameter %d must be a string", i); endif parameter = varargin{i}; if (numel (varargin) < i+1) error ('corrcoef: parameter "%s" missing value', parameter); endif value = varargin{i+1}; switch (tolower (parameter)) case "alpha" if (isnumeric (value) && isscalar (value) && value >= 0 && value <= 1) alpha = value; else error ('corrcoef: "alpha" must be a number between 0 and 1'); endif case "rows" if (! ischar (value)) error ('corrcoef: "rows" value must be a string'); endif value = tolower (value); switch (value) case {"all", "complete", "pairwise"} rows = value; otherwise error ('corrcoef: "rows" must be "all", "complete", or "pairwise".'); endswitch otherwise error ('corrcoef: Unknown option "%s"', parameter); endswitch endfor endif if (strcmp (rows, "complete")) x(any (isnan (x), 2), :) = []; endif if (isempty (x) || isscalar (x)) r = p = lci = hci = NaN; return; endif ## Flags for calculation pairwise = strcmp (rows, "pairwise"); calc_pval = nargout > 1; if (isrow (x)) x = x(:); endif [m, n] = size (x); r = eye (n); if (calc_pval) p = eye (n); endif if (strcmp (rows, "pairwise")) mpw = m * ones (n); endif for i = 1:n if (! pairwise && any (isnan (x(:,i)))) r(i,i) = NaN; if (nargout > 1) p(i,i) = NaN; endif endif for j = i+1:n xi = x(:,i); xj = x(:,j); if (pairwise) idx = any (isnan ([xi xj]), 2); xi(idx) = xj(idx) = []; mpw(i,j) = mpw(j,i) = m - nnz (idx); endif r(i,j) = r(j,i) = corr (xi, xj); if (calc_pval) T = cor_test (xi, xj, "!=", "pearson"); p(i,j) = p(j,i) = T.pval; endif endfor endfor if (nargout > 2) if (pairwise) m = mpw; endif CI = sqrt (2) * erfinv (1-alpha) ./ sqrt (m-3); lci = tanh (atanh (r) - CI); hci = tanh (atanh (r) + CI); endif endfunction %!test %! x = rand (5); %! r = corrcoef (x); %! assert (size (r) == [5, 5]); %!test %! x = [1 2 3]; %! r = corrcoef (x); %! assert (size (r) == [1, 1]); %!test %! x = []; %! r = corrcoef (x); %! assert (isnan (r)); %!test %! x = [NaN]; %! r = corrcoef (x); %! assert (isnan (r)); %!test %! x = [1]; %! r = corrcoef (x); %! assert (isnan (r)); %!test %! x = [NaN NaN]; %! r = corrcoef (x); %! assert (size(r) == [1, 1] && isnan (r)); %!test %! x = rand (5); %! [r, p] = corrcoef (x); %! assert (size (r) == [5, 5] && size (p) == [5 5]); %!test %! x = rand (5,1); %! y = rand (5,1); %! R1 = corrcoef (x, y); %! R2 = corrcoef ([x, y]); %! assert (R1, R2); %!test %! x = [1;2;3]; %! y = [1;2;3]; %! r = corrcoef (x, y); %! assert (r, ones (2,2)); %!test %! x = [1;2;3]; %! y = [3;2;1]; %! r = corrcoef (x, y); %! assert (r, [1, -1; -1, 1]); %!test %! x = [1;2;3]; %! y = [1;1;1]; %! r = corrcoef (x, y); %! assert (r, [1, NaN; NaN, 1]); %!test %!error corrcoef () %!error corrcoef (1, 2, 3) %!error corrcoef (1, 2, "alpha") %!error <"alpha" must be a number> corrcoef (1,2, "alpha", "1") %!error <"alpha" must be a number> corrcoef (1,2, "alpha", ones (2,2)) %!error <"alpha" must be a number between 0 and 1> corrcoef (1,2, "alpha", -1) %!error <"alpha" must be a number between 0 and 1> corrcoef (1,2, "alpha", 2) %!error <"rows" must be "all"...> corrcoef (1,2, "rows", "foobar") %!error corrcoef (1,2, "foobar", 1) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/quantile.m0000644000000000000000000000006213443447555022732 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/quantile.m0000644000175000017500000003472413443447555023453 0ustar00johndjohnd00000000000000## Copyright (C) 2008-2017 Ben Abbott and Jaroslav Hajek ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {@var{q} =} quantile (@var{x}) ## @deftypefnx {} {@var{q} =} quantile (@var{x}, @var{p}) ## @deftypefnx {} {@var{q} =} quantile (@var{x}, @var{p}, @var{dim}) ## @deftypefnx {} {@var{q} =} quantile (@var{x}, @var{p}, @var{dim}, @var{method}) ## For a sample, @var{x}, calculate the quantiles, @var{q}, corresponding to ## the cumulative probability values in @var{p}. All non-numeric values (NaNs) ## of @var{x} are ignored. ## ## If @var{x} is a matrix, compute the quantiles for each column and ## return them in a matrix, such that the i-th row of @var{q} contains ## the @var{p}(i)th quantiles of each column of @var{x}. ## ## If @var{p} is unspecified, return the quantiles for ## @code{[0.00 0.25 0.50 0.75 1.00]}. ## The optional argument @var{dim} determines the dimension along which ## the quantiles are calculated. If @var{dim} is omitted it defaults to ## the first non-singleton dimension. ## ## The methods available to calculate sample quantiles are the nine methods ## used by R (@url{http://www.r-project.org/}). The default value is ## @w{@var{method} = 5}. ## ## Discontinuous sample quantile methods 1, 2, and 3 ## ## @enumerate 1 ## @item Method 1: Inverse of empirical distribution function. ## ## @item Method 2: Similar to method 1 but with averaging at discontinuities. ## ## @item Method 3: SAS definition: nearest even order statistic. ## @end enumerate ## ## Continuous sample quantile methods 4 through 9, where ## @tex ## $p(k)$ ## @end tex ## @ifnottex ## @var{p}(k) ## @end ifnottex ## is the linear ## interpolation function respecting each method's representative cdf. ## ## @enumerate 4 ## @item Method 4: ## @tex ## $p(k) = k / N$. ## @end tex ## @ifnottex ## @var{p}(k) = k / N. ## @end ifnottex ## That is, linear interpolation of the empirical cdf, where @math{N} is the ## length of @var{P}. ## ## @item Method 5: ## @tex ## $p(k) = (k - 0.5) / N$. ## @end tex ## @ifnottex ## @var{p}(k) = (k - 0.5) / N. ## @end ifnottex ## That is, a piecewise linear function where the knots are the values midway ## through the steps of the empirical cdf. ## ## @item Method 6: ## @tex ## $p(k) = k / (N + 1)$. ## @end tex ## @ifnottex ## @var{p}(k) = k / (N + 1). ## @end ifnottex ## ## @item Method 7: ## @tex ## $p(k) = (k - 1) / (N - 1)$. ## @end tex ## @ifnottex ## @var{p}(k) = (k - 1) / (N - 1). ## @end ifnottex ## ## @item Method 8: ## @tex ## $p(k) = (k - 1/3) / (N + 1/3)$. ## @end tex ## @ifnottex ## @var{p}(k) = (k - 1/3) / (N + 1/3). ## @end ifnottex ## The resulting quantile estimates are approximately median-unbiased ## regardless of the distribution of @var{x}. ## ## @item Method 9: ## @tex ## $p(k) = (k - 3/8) / (N + 1/4)$. ## @end tex ## @ifnottex ## @var{p}(k) = (k - 3/8) / (N + 1/4). ## @end ifnottex ## The resulting quantile estimates are approximately unbiased for the ## expected order statistics if @var{x} is normally distributed. ## @end enumerate ## ## @nospell{Hyndman and Fan} (1996) recommend method 8. Maxima, S, and R ## (versions prior to 2.0.0) use 7 as their default. Minitab and SPSS ## use method 6. @sc{matlab} uses method 5. ## ## References: ## ## @itemize @bullet ## @item @nospell{Becker, R. A., Chambers, J. M. and Wilks, A. R.} (1988) ## The New S Language. @nospell{Wadsworth & Brooks/Cole}. ## ## @item @nospell{Hyndman, R. J. and Fan, Y.} (1996) Sample quantiles in ## statistical packages, American Statistician, 50, 361--365. ## ## @item R: A Language and Environment for Statistical Computing; ## @url{http://cran.r-project.org/doc/manuals/fullrefman.pdf}. ## @end itemize ## ## Examples: ## @c Set example in small font to prevent overfull line ## ## @smallexample ## @group ## x = randi (1000, [10, 1]); # Create empirical data in range 1-1000 ## q = quantile (x, [0, 1]); # Return minimum, maximum of distribution ## q = quantile (x, [0.25 0.5 0.75]); # Return quartiles of distribution ## @end group ## @end smallexample ## @seealso{prctile} ## @end deftypefn ## Author: Ben Abbott ## Description: Matlab style quantile function of a discrete/continuous ## distribution. function q = quantile (x, p = [], dim, method = 5) if (nargin < 1 || nargin > 4) print_usage (); endif if (! (isnumeric (x) || islogical (x)) || isempty (x)) error ("quantile: X must be a non-empty numeric vector or matrix"); endif if (isempty (p)) p = [0.00 0.25, 0.50, 0.75, 1.00]; endif if (! (isnumeric (p) && isvector (p))) error ("quantile: P must be a numeric vector"); endif if (nargin < 3) ## Find the first non-singleton dimension. (dim = find (size (x) > 1, 1)) || (dim = 1); else if (!(isscalar (dim) && dim == fix (dim)) || !(1 <= dim && dim <= ndims (x))) error ("quantile: DIM must be an integer and a valid dimension"); endif endif ## Set the permutation vector. perm = 1:ndims (x); perm(1) = dim; perm(dim) = 1; ## Permute dim to the 1st index. x = permute (x, perm); ## Save the size of the permuted x N-d array. sx = size (x); ## Reshape to a 2-d array. x = reshape (x, [sx(1), prod(sx(2:end))]); ## Calculate the quantiles. q = __quantile__ (x, p, method); ## Return the shape to the original N-d array. q = reshape (q, [numel(p), sx(2:end)]); ## Permute the 1st index back to dim. q = ipermute (q, perm); endfunction %!test %! p = 0.50; %! q = quantile (1:4, p); %! qa = 2.5; %! assert (q, qa); %! q = quantile (1:4, p, 1); %! qa = [1, 2, 3, 4]; %! assert (q, qa); %! q = quantile (1:4, p, 2); %! qa = 2.5; %! assert (q, qa); %!test %! p = [0.50 0.75]; %! q = quantile (1:4, p); %! qa = [2.5 3.5]; %! assert (q, qa); %! q = quantile (1:4, p, 1); %! qa = [1, 2, 3, 4; 1, 2, 3, 4]; %! assert (q, qa); %! q = quantile (1:4, p, 2); %! qa = [2.5 3.5]; %! assert (q, qa); %!test %! p = 0.5; %! x = sort (rand (11)); %! q = quantile (x, p); %! assert (q, x(6,:)); %! x = x.'; %! q = quantile (x, p, 2); %! assert (q, x(:,6)); %!test %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; %! x = [1; 2; 3; 4]; %! a = [1.0000 1.0000 2.0000 3.0000 4.0000 %! 1.0000 1.5000 2.5000 3.5000 4.0000 %! 1.0000 1.0000 2.0000 3.0000 4.0000 %! 1.0000 1.0000 2.0000 3.0000 4.0000 %! 1.0000 1.5000 2.5000 3.5000 4.0000 %! 1.0000 1.2500 2.5000 3.7500 4.0000 %! 1.0000 1.7500 2.5000 3.2500 4.0000 %! 1.0000 1.4167 2.5000 3.5833 4.0000 %! 1.0000 1.4375 2.5000 3.5625 4.0000]; %! for m = 1:9 %! q = quantile (x, p, 1, m).'; %! assert (q, a(m,:), 0.0001); %! endfor %!test %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; %! x = [1; 2; 3; 4; 5]; %! a = [1.0000 2.0000 3.0000 4.0000 5.0000 %! 1.0000 2.0000 3.0000 4.0000 5.0000 %! 1.0000 1.0000 2.0000 4.0000 5.0000 %! 1.0000 1.2500 2.5000 3.7500 5.0000 %! 1.0000 1.7500 3.0000 4.2500 5.0000 %! 1.0000 1.5000 3.0000 4.5000 5.0000 %! 1.0000 2.0000 3.0000 4.0000 5.0000 %! 1.0000 1.6667 3.0000 4.3333 5.0000 %! 1.0000 1.6875 3.0000 4.3125 5.0000]; %! for m = 1:9 %! q = quantile (x, p, 1, m).'; %! assert (q, a(m,:), 0.0001); %! endfor %!test %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; %! x = [1; 2; 5; 9]; %! a = [1.0000 1.0000 2.0000 5.0000 9.0000 %! 1.0000 1.5000 3.5000 7.0000 9.0000 %! 1.0000 1.0000 2.0000 5.0000 9.0000 %! 1.0000 1.0000 2.0000 5.0000 9.0000 %! 1.0000 1.5000 3.5000 7.0000 9.0000 %! 1.0000 1.2500 3.5000 8.0000 9.0000 %! 1.0000 1.7500 3.5000 6.0000 9.0000 %! 1.0000 1.4167 3.5000 7.3333 9.0000 %! 1.0000 1.4375 3.5000 7.2500 9.0000]; %! for m = 1:9 %! q = quantile (x, p, 1, m).'; %! assert (q, a(m,:), 0.0001); %! endfor %!test %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; %! x = [1; 2; 5; 9; 11]; %! a = [1.0000 2.0000 5.0000 9.0000 11.0000 %! 1.0000 2.0000 5.0000 9.0000 11.0000 %! 1.0000 1.0000 2.0000 9.0000 11.0000 %! 1.0000 1.2500 3.5000 8.0000 11.0000 %! 1.0000 1.7500 5.0000 9.5000 11.0000 %! 1.0000 1.5000 5.0000 10.0000 11.0000 %! 1.0000 2.0000 5.0000 9.0000 11.0000 %! 1.0000 1.6667 5.0000 9.6667 11.0000 %! 1.0000 1.6875 5.0000 9.6250 11.0000]; %! for m = 1:9 %! q = quantile (x, p, 1, m).'; %! assert (q, a(m,:), 0.0001); %! endfor %!test %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; %! x = [16; 11; 15; 12; 15; 8; 11; 12; 6; 10]; %! a = [6.0000 10.0000 11.0000 15.0000 16.0000 %! 6.0000 10.0000 11.5000 15.0000 16.0000 %! 6.0000 8.0000 11.0000 15.0000 16.0000 %! 6.0000 9.0000 11.0000 13.5000 16.0000 %! 6.0000 10.0000 11.5000 15.0000 16.0000 %! 6.0000 9.5000 11.5000 15.0000 16.0000 %! 6.0000 10.2500 11.5000 14.2500 16.0000 %! 6.0000 9.8333 11.5000 15.0000 16.0000 %! 6.0000 9.8750 11.5000 15.0000 16.0000]; %! for m = 1:9 %! q = quantile (x, p, 1, m).'; %! assert (q, a(m,:), 0.0001); %! endfor %!test %! p = [0.00, 0.25, 0.50, 0.75, 1.00]; %! x = [-0.58851; 0.40048; 0.49527; -2.551500; -0.52057; ... %! -0.17841; 0.057322; -0.62523; 0.042906; 0.12337]; %! a = [-2.551474 -0.588505 -0.178409 0.123366 0.495271 %! -2.551474 -0.588505 -0.067751 0.123366 0.495271 %! -2.551474 -0.625231 -0.178409 0.123366 0.495271 %! -2.551474 -0.606868 -0.178409 0.090344 0.495271 %! -2.551474 -0.588505 -0.067751 0.123366 0.495271 %! -2.551474 -0.597687 -0.067751 0.192645 0.495271 %! -2.551474 -0.571522 -0.067751 0.106855 0.495271 %! -2.551474 -0.591566 -0.067751 0.146459 0.495271 %! -2.551474 -0.590801 -0.067751 0.140686 0.495271]; %! for m = 1:9 %! q = quantile (x, p, 1, m).'; %! assert (q, a(m,:), 0.0001); %! endfor %!test %! p = 0.5; %! x = [0.112600, 0.114800, 0.052100, 0.236400, 0.139300 %! 0.171800, 0.727300, 0.204100, 0.453100, 0.158500 %! 0.279500, 0.797800, 0.329600, 0.556700, 0.730700 %! 0.428800, 0.875300, 0.647700, 0.628700, 0.816500 %! 0.933100, 0.931200, 0.963500, 0.779600, 0.846100]; %! tol = 0.00001; %! x(5,5) = NaN; %! assert (quantile (x, p, 1), [0.27950, 0.79780, 0.32960, 0.55670, 0.44460], tol); %! x(1,1) = NaN; %! assert (quantile (x, p, 1), [0.35415, 0.79780, 0.32960, 0.55670, 0.44460], tol); %! x(3,3) = NaN; %! assert (quantile (x, p, 1), [0.35415, 0.79780, 0.42590, 0.55670, 0.44460], tol); %!test %! sx = [2, 3, 4]; %! x = rand (sx); %! dim = 2; %! p = 0.5; %! yobs = quantile (x, p, dim); %! yexp = median (x, dim); %! assert (yobs, yexp); %!assert <*45455> (quantile ([1 3 2], 0.5, 1), [1 3 2]) ## Test input validation %!error quantile () %!error quantile (1, 2, 3, 4, 5) %!error quantile (['A'; 'B'], 10) %!error quantile (1:10, [true, false]) %!error quantile (1:10, ones (2,2)) %!error quantile (1, 1, 1.5) %!error quantile (1, 1, 0) %!error quantile (1, 1, 3) %!error quantile ((1:5)', 0.5, 1, 0) %!error quantile ((1:5)', 0.5, 1, 10) ## For the cumulative probability values in @var{p}, compute the ## quantiles, @var{q} (the inverse of the cdf), for the sample, @var{x}. ## ## The optional input, @var{method}, refers to nine methods available in R ## (http://www.r-project.org/). The default is @var{method} = 7. ## @seealso{prctile, quantile, statistics} ## Author: Ben Abbott ## Vectorized version: Jaroslav Hajek ## Description: Quantile function of empirical samples function inv = __quantile__ (x, p, method = 5) if (nargin < 2 || nargin > 3) print_usage (); endif if (isinteger (x) || islogical (x)) x = double (x); endif ## set shape of quantiles to column vector. p = p(:); ## Save length and set shape of samples. x = sort (x, 1); m = sum (! isnan (x)); [xr, xc] = size (x); ## Initialize output values. inv = Inf (class (x)) * (-(p < 0) + (p > 1)); inv = repmat (inv, 1, xc); ## Do the work. if (any (k = find ((p >= 0) & (p <= 1)))) n = length (k); p = p(k); ## Special case of 1 row. if (xr == 1) inv(k,:) = repmat (x, n, 1); return; endif ## The column-distribution indices. pcd = kron (ones (n, 1), xr*(0:xc-1)); mm = kron (ones (n, 1), m); switch (method) case {1, 2, 3} switch (method) case 1 p = max (ceil (kron (p, m)), 1); inv(k,:) = x(p + pcd); case 2 p = kron (p, m); p_lr = max (ceil (p), 1); p_rl = min (floor (p + 1), mm); inv(k,:) = (x(p_lr + pcd) + x(p_rl + pcd))/2; case 3 ## Used by SAS, method PCTLDEF=2. ## http://support.sas.com/onlinedoc/913/getDoc/en/statug.hlp/stdize_sect14.htm t = max (kron (p, m), 1); t = roundb (t); inv(k,:) = x(t + pcd); endswitch otherwise switch (method) case 4 p = kron (p, m); case 5 ## Used by Matlab. p = kron (p, m) + 0.5; case 6 ## Used by Minitab and SPSS. p = kron (p, m+1); case 7 ## Used by S and R. p = kron (p, m-1) + 1; case 8 ## Median unbiased. p = kron (p, m+1/3) + 1/3; case 9 ## Approximately unbiased respecting order statistics. p = kron (p, m+0.25) + 0.375; otherwise error ("quantile: Unknown METHOD, '%d'", method); endswitch ## Duplicate single values. imm1 = (mm(1,:) == 1); x(2,imm1) = x(1,imm1); ## Interval indices. pi = max (min (floor (p), mm-1), 1); pr = max (min (p - pi, 1), 0); pi += pcd; inv(k,:) = (1-pr) .* x(pi) + pr .* x(pi+1); endswitch endif endfunction statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/histc.m0000644000000000000000000000006213443447555022222 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/histc.m0000644000175000017500000001212613443447555022733 0ustar00johndjohnd00000000000000## Copyright (C) 2009-2017 Søren Hauberg ## Copyright (C) 2009 VZLU Prague ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {@var{n} =} histc (@var{x}, @var{edges}) ## @deftypefnx {} {@var{n} =} histc (@var{x}, @var{edges}, @var{dim}) ## @deftypefnx {} {[@var{n}, @var{idx}] =} histc (@dots{}) ## Compute histogram counts. ## ## When @var{x} is a vector, the function counts the number of elements of ## @var{x} that fall in the histogram bins defined by @var{edges}. This ## must be a vector of monotonically increasing values that define the edges ## of the histogram bins. ## @tex ## $n(k)$ ## @end tex ## @ifnottex ## @code{@var{n}(k)} ## @end ifnottex ## contains the number of elements in @var{x} for which ## @tex ## $@var{edges}(k) <= @var{x} < @var{edges}(k+1)$. ## @end tex ## @ifnottex ## @code{@var{edges}(k) <= @var{x} < @var{edges}(k+1)}. ## @end ifnottex ## The final element of @var{n} contains the number of elements of @var{x} ## exactly equal to the last element of @var{edges}. ## ## When @var{x} is an @math{N}-dimensional array, the computation is carried ## out along dimension @var{dim}. If not specified @var{dim} defaults to the ## first non-singleton dimension. ## ## When a second output argument is requested an index matrix is also returned. ## The @var{idx} matrix has the same size as @var{x}. Each element of ## @var{idx} contains the index of the histogram bin in which the ## corresponding element of @var{x} was counted. ## @seealso{hist} ## @end deftypefn function [n, idx] = histc (x, edges, dim) if (nargin < 2 || nargin > 3) print_usage (); endif if (! isreal (x)) error ("histc: X argument must be real-valued, not complex"); endif num_edges = numel (edges); if (num_edges == 0) warning ("histc: empty EDGES specified\n"); n = idx = []; return; endif if (! isreal (edges)) error ("histc: EDGES must be real-valued, not complex"); else ## Make sure 'edges' is sorted edges = edges(:); if (! issorted (edges) || edges(1) > edges(end)) warning ("histc: edge values not sorted on input"); edges = sort (edges); endif endif nd = ndims (x); sz = size (x); if (nargin < 3) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (!(isscalar (dim) && dim == fix (dim)) || !(1 <= dim && dim <= nd)) error ("histc: DIM must be an integer and a valid dimension"); endif endif nsz = sz; nsz(dim) = num_edges; ## the splitting point is 3 bins if (num_edges <= 3) ## This is the O(M*N) algorithm. ## Allocate the histogram n = zeros (nsz); ## Allocate 'idx' if (nargout > 1) idx = zeros (sz); endif ## Prepare indices idx1 = cell (1, dim-1); for k = 1:length (idx1) idx1{k} = 1:sz(k); endfor idx2 = cell (length (sz) - dim); for k = 1:length (idx2) idx2{k} = 1:sz(k+dim); endfor ## Compute the histograms for k = 1:num_edges-1 b = (edges(k) <= x & x < edges(k+1)); n(idx1{:}, k, idx2{:}) = sum (b, dim); if (nargout > 1) idx(b) = k; endif endfor b = (x == edges(end)); n(idx1{:}, num_edges, idx2{:}) = sum (b, dim); if (nargout > 1) idx(b) = num_edges; endif else ## This is the O(M*log(N) + N) algorithm. ## Look-up indices. idx = lookup (edges, x); ## Zero invalid ones (including NaNs). x < edges(1) are already zero. idx(! (x <= edges(end))) = 0; iidx = idx; ## In case of matrix input, we adjust the indices. if (! isvector (x)) nl = prod (sz(1:dim-1)); nn = sz(dim); nu = prod (sz(dim+1:end)); if (nl != 1) iidx = (iidx-1) * nl; iidx += reshape (kron (ones (1, nn*nu), 1:nl), sz); endif if (nu != 1) ne =length (edges); iidx += reshape (kron (nl*ne*(0:nu-1), ones (1, nl*nn)), sz); endif endif ## Select valid elements. iidx = iidx(idx != 0); ## Call accumarray to sum the indexed elements. n = accumarray (iidx(:), 1, nsz); endif endfunction %!test %! x = linspace (0, 10, 1001); %! n = histc (x, 0:10); %! assert (n, [repmat(100, 1, 10), 1]); %!test %! x = repmat (linspace (0, 10, 1001), [2, 1, 3]); %! n = histc (x, 0:10, 2); %! assert (n, repmat ([repmat(100, 1, 10), 1], [2, 1, 3])); %!error histc () %!error histc (1) %!error histc (1, 2, 3, 4) %!error histc ([1:10 1+i], 2) %!warning histc (1:10, []); %!error histc (1, 1, 3) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/zscore.m0000644000000000000000000000006213443447555022415 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/zscore.m0000644000175000017500000000614413443447555023131 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {@var{z} =} zscore (@var{x}) ## @deftypefnx {} {@var{z} =} zscore (@var{x}, @var{opt}) ## @deftypefnx {} {@var{z} =} zscore (@var{x}, @var{opt}, @var{dim}) ## @deftypefnx {} {[@var{z}, @var{mu}, @var{sigma}] =} zscore (@dots{}) ## Compute the Z score of @var{x} ## ## If @var{x} is a vector, subtract its mean and divide by its standard ## deviation. If the standard deviation is zero, divide by 1 instead. ## ## The optional parameter @var{opt} determines the normalization to use when ## computing the standard deviation and has the same definition as the ## corresponding parameter for @code{std}. ## ## If @var{x} is a matrix, calculate along the first non-singleton dimension. ## If the third optional argument @var{dim} is given, operate along this ## dimension. ## ## The optional outputs @var{mu} and @var{sigma} contain the mean and standard ## deviation. ## ## @seealso{mean, std, center} ## @end deftypefn ## Author: KH ## Description: Subtract mean and divide by standard deviation function [z, mu, sigma] = zscore (x, opt, dim) if (nargin < 1 || nargin > 3 ) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("zscore: X must be a numeric vector or matrix"); endif if (nargin < 2) opt = 0; else if (opt != 0 && opt != 1 || ! isscalar (opt)) error ("zscore: OPT must be empty, 0, or 1"); endif endif nd = ndims (x); sz = size (x); if (nargin < 3) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (!(isscalar (dim) && dim == fix (dim)) || !(1 <= dim && dim <= nd)) error ("zscore: DIM must be an integer and a valid dimension"); endif endif n = sz(dim); if (n == 0) z = x; else if (isinteger (x)) x = double (x); endif mu = mean (x, dim); sigma = std (x, opt, dim); s = sigma; s(s==0) = 1; z = (x - mu) ./ s; endif endfunction %!assert (zscore ([1,2,3]), [-1,0,1]) %!assert (zscore (single ([1,2,3])), single ([-1,0,1])) %!assert (zscore (int8 ([1,2,3])), [-1,0,1]) %!assert (zscore (ones (3,2,2,2)), zeros (3,2,2,2)) %!assert (zscore ([2,0,-2;0,2,0;-2,-2,2]), [1,0,-1;0,1,0;-1,-1,1]) ## Test input validation %!error zscore () %!error zscore (1, 2, 3) %!error zscore (['A'; 'B']) %!error zscore (1, ones (2,2)) %!error zscore (1, 1.5) %!error zscore (1, 1, 0) %!error zscore (1, 3) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/prctile.m0000644000000000000000000000006213443447555022552 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/prctile.m0000644000175000017500000001252713443447555023270 0ustar00johndjohnd00000000000000## Copyright (C) 2008-2017 Ben Abbott ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {@var{q} =} prctile (@var{x}) ## @deftypefnx {} {@var{q} =} prctile (@var{x}, @var{p}) ## @deftypefnx {} {@var{q} =} prctile (@var{x}, @var{p}, @var{dim}) ## For a sample @var{x}, compute the quantiles, @var{q}, corresponding ## to the cumulative probability values, @var{p}, in percent. ## ## If @var{x} is a matrix, compute the percentiles for each column and return ## them in a matrix, such that the i-th row of @var{q} contains the ## @var{p}(i)th percentiles of each column of @var{x}. ## ## If @var{p} is unspecified, return the quantiles for @code{[0 25 50 75 100]}. ## ## The optional argument @var{dim} determines the dimension along which the ## percentiles are calculated. If @var{dim} is omitted it defaults to the ## first non-singleton dimension. ## ## Programming Note: All non-numeric values (NaNs) of @var{x} are ignored. ## @seealso{quantile} ## @end deftypefn ## Author: Ben Abbott ## Description: Matlab style prctile function. function q = prctile (x, p = [], dim) if (nargin < 1 || nargin > 3) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("prctile: X must be a numeric vector or matrix"); endif if (isempty (p)) p = [0, 25, 50, 75, 100]; endif if (! (isnumeric (p) && isvector (p))) error ("prctile: P must be a numeric vector"); endif nd = ndims (x); sz = size (x); if (nargin < 3) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (!(isscalar (dim) && dim == fix (dim)) || !(1 <= dim && dim <= nd)) error ("prctile: DIM must be an integer and a valid dimension"); endif endif ## Convert from percent to decimal. p /= 100; q = quantile (x, p, dim); endfunction %!test %! pct = 50; %! q = prctile (1:4, pct); %! qa = 2.5; %! assert (q, qa); %! q = prctile (1:4, pct, 1); %! qa = [1, 2, 3, 4]; %! assert (q, qa); %! q = prctile (1:4, pct, 2); %! qa = 2.5; %! assert (q, qa); %!test %! pct = [50 75]; %! q = prctile (1:4, pct); %! qa = [2.5 3.5]; %! assert (q, qa); %! q = prctile (1:4, pct, 1); %! qa = [1, 2, 3, 4; 1, 2, 3, 4]; %! assert (q, qa); %! q = prctile (1:4, pct, 2); %! qa = [2.5 3.5]; %! assert (q, qa); %!test %! pct = 50; %! x = [0.1126, 0.1148, 0.0521, 0.2364, 0.1393 %! 0.1718, 0.7273, 0.2041, 0.4531, 0.1585 %! 0.2795, 0.7978, 0.3296, 0.5567, 0.7307 %! 0.4288, 0.8753, 0.6477, 0.6287, 0.8165 %! 0.9331, 0.9312, 0.9635, 0.7796, 0.8461]; %! tol = 0.0001; %! q = prctile (x, pct, 1); %! qa = [0.2795, 0.7978, 0.3296, 0.5567, 0.7307]; %! assert (q, qa, tol); %! q = prctile (x, pct, 2); %! qa = [0.1148; 0.2041; 0.5567; 0.6477; 0.9312]; %! assert (q, qa, tol); %!test %! pct = 50; %! tol = 0.0001; %! x = [0.1126, 0.1148, 0.0521, 0.2364, 0.1393 %! 0.1718, 0.7273, 0.2041, 0.4531, 0.1585 %! 0.2795, 0.7978, 0.3296, 0.5567, 0.7307 %! 0.4288, 0.8753, 0.6477, 0.6287, 0.8165 %! 0.9331, 0.9312, 0.9635, 0.7796, 0.8461]; %! x(5,5) = Inf; %! q = prctile (x, pct, 1); %! qa = [0.2795, 0.7978, 0.3296, 0.5567, 0.7307]; %! assert (q, qa, tol); %! x(5,5) = -Inf; %! q = prctile (x, pct, 1); %! qa = [0.2795, 0.7978, 0.3296, 0.5567, 0.1585]; %! assert (q, qa, tol); %! x(1,1) = Inf; %! q = prctile (x, pct, 1); %! qa = [0.4288, 0.7978, 0.3296, 0.5567, 0.1585]; %! assert (q, qa, tol); %!test %! pct = 50; %! tol = 0.0001; %! x = [0.1126, 0.1148, 0.0521, 0.2364, 0.1393 %! 0.1718, 0.7273, 0.2041, 0.4531, 0.1585 %! 0.2795, 0.7978, 0.3296, 0.5567, 0.7307 %! 0.4288, 0.8753, 0.6477, 0.6287, 0.8165 %! 0.9331, 0.9312, 0.9635, 0.7796, 0.8461]; %! x(3,3) = Inf; %! q = prctile (x, pct, 1); %! qa = [0.2795, 0.7978, 0.6477, 0.5567, 0.7307]; %! assert (q, qa, tol); %! q = prctile (x, pct, 2); %! qa = [0.1148; 0.2041; 0.7307; 0.6477; 0.9312]; %! assert (q, qa, tol); %!test %! pct = 50; %! tol = 0.0001; %! x = [0.1126, 0.1148, 0.0521, 0.2364, 0.1393 %! 0.1718, 0.7273, 0.2041, 0.4531, 0.1585 %! 0.2795, 0.7978, 0.3296, 0.5567, 0.7307 %! 0.4288, 0.8753, 0.6477, 0.6287, 0.8165 %! 0.9331, 0.9312, 0.9635, 0.7796, 0.8461]; %! x(5,5) = NaN; %! q = prctile (x, pct, 2); %! qa = [0.1148; 0.2041; 0.5567; 0.6477; 0.9322]; %! assert (q, qa, tol); %! x(1,1) = NaN; %! q = prctile (x, pct, 2); %! qa = [0.1270; 0.2041; 0.5567; 0.6477; 0.9322]; %! assert (q, qa, tol); %! x(3,3) = NaN; %! q = prctile (x, pct, 2); %! qa = [0.1270; 0.2041; 0.6437; 0.6477; 0.9322]; %! assert (q, qa, tol); ## Test input validation %!error prctile () %!error prctile (1, 2, 3, 4) %!error prctile (['A'; 'B'], 10) %!error prctile (1:10, [true, false]) %!error prctile (1:10, ones (2,2)) %!error prctile (1, 1, 1.5) %!error prctile (1, 1, 0) %!error prctile (1, 1, 3) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/runlength.m0000644000000000000000000000006213443447555023116 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/runlength.m0000644000175000017500000000371413443447555023632 0ustar00johndjohnd00000000000000## Copyright (C) 2005-2017 Paul Kienzle ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {count =} runlength (@var{x}) ## @deftypefnx {} {[count, value] =} runlength (@var{x}) ## Find the lengths of all sequences of common values. ## ## @var{count} is a vector with the lengths of each repeated value. ## ## The optional output @var{value} contains the value that was repeated in ## the sequence. ## ## @example ## @group ## runlength ([2, 2, 0, 4, 4, 4, 0, 1, 1, 1, 1]) ## @result{} [2, 1, 3, 1, 4] ## @end group ## @end example ## @seealso{run_count} ## @end deftypefn function [count, value] = runlength (x) if (nargin != 1) print_usage (); endif if (! (isnumeric (x) || islogical (x)) || ! isvector (x)) error ("runlength: X must be a numeric vector"); endif if (iscolumn (x)) x = x.'; endif idx = [find(x(1:end-1) != x(2:end)), length(x)]; count = diff ([0 idx]); if (nargout == 2) value = x(idx); endif endfunction %!assert (runlength ([2 2 0 4 4 4 0 1 1 1 1]), [2 1 3 1 4]) %!assert (runlength ([2 2 0 4 4 4 0 1 1 1 1]'), [2 1 3 1 4]) %!test %! [c, v] = runlength ([2 2 0 4 4 4 0 1 1 1 1]); %! assert (c, [2 1 3 1 4]); %! assert (v, [2 0 4 0 1]); ## Test input validation %!error runlength () %!error runlength (1, 2) %!error runlength (['A'; 'B']) %!error runlength (ones (2,2)) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/range.m0000644000000000000000000000006213443447555022204 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/range.m0000644000175000017500000000361113443447555022714 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## Copyright (C) 2009 Jaroslav Hajek ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} range (@var{x}) ## @deftypefnx {} {} range (@var{x}, @var{dim}) ## Return the range, i.e., the difference between the maximum and the minimum ## of the input data. ## ## If @var{x} is a vector, the range is calculated over the elements of ## @var{x}. If @var{x} is a matrix, the range is calculated over each column ## of @var{x}. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## ## The range is a quickly computed measure of the dispersion of a data set, but ## is less accurate than @code{iqr} if there are outlying data points. ## @seealso{iqr, std} ## @end deftypefn ## Author: KH ## Description: Compute range function y = range (x, dim) if (nargin < 1 || nargin > 2) print_usage (); endif if (nargin == 1) y = max (x) - min (x); else y = max (x, [], dim) - min (x, [], dim); endif endfunction %!assert (range (1:10), 9) %!assert (range (single (1:10)), single (9)) %!assert (range (magic (3)), [5, 8, 5]) %!assert (range (magic (3), 2), [7; 4; 7]) %!assert (range (2), 0) ## Test input validation %!error range () %!error range (1, 2, 3) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/std.m0000644000000000000000000000006213443447555021702 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/std.m0000644000175000017500000002117613443447555022420 0ustar00johndjohnd00000000000000## Copyright (C) 1996-2017 John W. Eaton ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} std (@var{x}) ## @deftypefnx {} {} std (@var{x}, @var{opt}) ## @deftypefnx {} {} std (@var{x}, @var{opt}, @var{dim}) ## Compute the standard deviation of the elements of the vector @var{x}. ## ## The standard deviation is defined as ## @tex ## $$ ## {\rm std} (x) = \sigma = \sqrt{{\sum_{i=1}^N (x_i - \bar{x})^2 \over N - 1}} ## $$ ## where $\bar{x}$ is the mean value of @var{x} and $N$ is the number of elements of @var{x}. ## @end tex ## @ifnottex ## ## @example ## @group ## std (@var{x}) = sqrt ( 1/(N-1) SUM_i (@var{x}(i) - mean(@var{x}))^2 ) ## @end group ## @end example ## ## @noindent ## where @math{N} is the number of elements of the @var{x} vector. ## @end ifnottex ## ## If @var{x} is a matrix, compute the standard deviation for each column and ## return them in a row vector. ## ## The argument @var{opt} determines the type of normalization to use. ## Valid values are ## ## @table @asis ## @item 0: ## normalize with @math{N-1}, provides the square root of the best unbiased ## estimator of the variance [default] ## ## @item 1: ## normalize with @math{N}, this provides the square root of the second ## moment around the mean ## @end table ## ## If the optional argument @var{dim} is given, operate along this dimension. ## @seealso{var, range, iqr, mean, median} ## @end deftypefn ## Author: jwe function retval = std (x, opt = 0, dim) if (nargin < 1 || nargin > 3) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("std: X must be a numeric vector or matrix"); endif if (isempty (opt)) opt = 0; elseif (! isscalar (opt) || (opt != 0 && opt != 1)) error ("std: normalization OPT must be 0 or 1"); endif nd = ndims (x); sz = size (x); if (nargin < 3) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("std: DIM must be an integer and a valid dimension"); endif endif n = size (x, dim); if (isempty (x)) %% codepath for Matlab compatibility. empty x produces NaN output, but %% for ndim > 2, output depends on size of x. if ((nargin < 3) && (nd == 2) && (max (sz) < 2)) retval = NaN; else if (nargin == 3) sz(dim) = 1; else sz (find ((sz ~= 1), 1)) = 1; endif retval = NaN (sz); endif if (isa (x, "single")) retval = single (retval); endif elseif (n == 1) if (isa (x, "single")) retval = zeros (sz, "single"); else retval = zeros (sz); endif else retval = sqrt (sumsq (center (x, dim), dim) / (n - 1 + opt)); endif endfunction %!test %! x = ones (10, 2); %! y = [1, 3]; %! assert (std (x), [0, 0]); %! assert (std (y), sqrt (2), sqrt (eps)); %! assert (std (x, 0, 2), zeros (10, 1)); %!assert (std (ones (3, 1, 2), 0, 2), zeros (3, 1, 2)) %!assert (std ([1 2], 0), sqrt (2)/2, 5*eps) %!assert (std ([1 2], 1), 0.5, 5*eps) %!assert (std (1), 0) %!assert (std (single (1)), single (0)) %!assert (std ([1 2 3], [], 3), [0 0 0]) ##tests for empty input Matlab compatibility (bug #48690) %!assert (std ([]), NaN) %!assert (std (single ([])), single (NaN)) %!assert (std (ones (0, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (std (ones (0, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (std (ones (0, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (std (ones (0, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (std (ones (0, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (std (ones (0, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (std (ones (0, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (std (ones (0, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (std (ones (0, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (std (ones (0, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (std (ones (0, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (std (ones (0, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (std (ones (0, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (std (ones (0, 1, 1, 1)), NaN (1, 1, 1, 1)) %!assert (std (ones (0, 1, 1, 2)), NaN (1, 1, 1, 2)) %!assert (std (ones (0, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (std (ones (0, 1, 2, 1)), NaN (1, 1, 2, 1)) %!assert (std (ones (0, 1, 2, 2)), NaN (1, 1, 2, 2)) %!assert (std (ones (0, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (std (ones (0, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (std (ones (0, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (std (ones (0, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (std (ones (0, 2, 1, 1)), NaN (1, 2, 1, 1)) %!assert (std (ones (0, 2, 1, 2)), NaN (1, 2, 1, 2)) %!assert (std (ones (0, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (std (ones (0, 2, 2, 1)), NaN (1, 2, 2, 1)) %!assert (std (ones (0, 2, 2, 2)), NaN (1, 2, 2, 2)) %!assert (std (ones (1, 0, 0, 0)), NaN (1, 1, 0, 0)) %!assert (std (ones (1, 0, 0, 1)), NaN (1, 1, 0, 1)) %!assert (std (ones (1, 0, 0, 2)), NaN (1, 1, 0, 2)) %!assert (std (ones (1, 0, 1, 0)), NaN (1, 1, 1, 0)) %!assert (std (ones (1, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (std (ones (1, 0, 1, 2)), NaN (1, 1, 1, 2)) %!assert (std (ones (1, 0, 2, 0)), NaN (1, 1, 2, 0)) %!assert (std (ones (1, 0, 2, 1)), NaN (1, 1, 2, 1)) %!assert (std (ones (1, 0, 2, 2)), NaN (1, 1, 2, 2)) %!assert (std (ones (1, 1, 0, 0)), NaN (1, 1, 1, 0)) %!assert (std (ones (1, 1, 0, 1)), NaN (1, 1, 1, 1)) %!assert (std (ones (1, 1, 0, 2)), NaN (1, 1, 1, 2)) %!assert (std (ones (1, 1, 1, 0)), NaN (1, 1, 1, 1)) %!assert (std (ones (1, 1, 2, 0)), NaN (1, 1, 1, 0)) %!assert (std (ones (1, 2, 0, 0)), NaN (1, 1, 0, 0)) %!assert (std (ones (1, 2, 0, 1)), NaN (1, 1, 0, 1)) %!assert (std (ones (1, 2, 0, 2)), NaN (1, 1, 0, 2)) %!assert (std (ones (1, 2, 1, 0)), NaN (1, 1, 1, 0)) %!assert (std (ones (1, 2, 2, 0)), NaN (1, 1, 2, 0)) %!assert (std (ones (2, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (std (ones (2, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (std (ones (2, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (std (ones (2, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (std (ones (2, 0, 1, 1)), NaN (1, 0, 1, 1)) %!assert (std (ones (2, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (std (ones (2, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (std (ones (2, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (std (ones (2, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (std (ones (2, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (std (ones (2, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (std (ones (2, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (std (ones (2, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (std (ones (2, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (std (ones (2, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (std (ones (2, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (std (ones (2, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (std (ones (2, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (std (ones (2, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (std (ones (1, 1, 0, 0, 0)), NaN (1, 1, 1, 0, 0)) %!assert (std (ones (1, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 1)) %!assert (std (ones (2, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) %!assert (std (ones (1, 2, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) %!assert (std (ones (1, 3, 0, 2)), NaN (1, 1, 0, 2)) %!assert (std (single (ones (1, 3, 0, 2))), single (NaN (1, 1, 0, 2))) %!assert (std ([], 0, 1), NaN (1, 0)) %!assert (std ([], 0, 2), NaN (0, 1)) %!assert (std ([], 0, 3), []) %!assert (std (ones (1, 0), 0, 1), NaN (1, 0)) %!assert (std (ones (1, 0), 0, 2), NaN) %!assert (std (ones (1, 0), 0, 3), NaN (1, 0)) %!assert (std (ones (0, 1), 0, 1), NaN) %!assert (std (ones (0, 1), 0, 2), NaN (0, 1)) %!assert (std (ones (0, 1), 0, 3), NaN (0, 1)) %!assert (std ([], 1, 1), NaN (1, 0)) %!assert (std ([], 1, 2), NaN (0, 1)) %!assert (std ([], 1, 3), []) %!assert (std (ones (1, 0), 1, 1), NaN (1, 0)) %!assert (std (ones (1, 0), 1, 2), NaN) %!assert (std (ones (1, 0), 1, 3), NaN (1, 0)) %!assert (std (ones (0, 1), 1, 1), NaN) %!assert (std (ones (0, 1), 1, 2), NaN (0, 1)) %!assert (std (ones (0, 1), 1, 3), NaN (0, 1)) ## Test input validation %!error std () %!error std (1, 2, 3, 4) %!error std (['A'; 'B']) %!error std (1, 2) %!error std (1, [], ones (2, 2)) %!error std (1, [], 1.5) %!error std (1, [], 0) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/iqr.m0000644000000000000000000000006213443447555021703 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/iqr.m0000644000175000017500000000535313443447555022420 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} iqr (@var{x}) ## @deftypefnx {} {} iqr (@var{x}, @var{dim}) ## Return the interquartile range, i.e., the difference between the upper ## and lower quartile of the input data. ## ## If @var{x} is a matrix, do the above for first non-singleton dimension of ## @var{x}. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## ## As a measure of dispersion, the interquartile range is less affected by ## outliers than either @code{range} or @code{std}. ## @seealso{range, std} ## @end deftypefn ## Author KH ## Description: Interquartile range function y = iqr (x, dim) if (nargin != 1 && nargin != 2) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("iqr: X must be a numeric vector or matrix"); endif nd = ndims (x); sz = size (x); nel = numel (x); if (nargin != 2) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (!(isscalar (dim) && dim == fix (dim)) || !(1 <= dim && dim <= nd)) error ("iqr: DIM must be an integer and a valid dimension"); endif endif ## This code is a bit heavy, but is needed until empirical_inv ## can take a matrix, rather than just a vector argument. n = sz(dim); sz(dim) = 1; if (isa (x, "single")) y = zeros (sz, "single"); else y = zeros (sz); endif stride = prod (sz(1:dim-1)); for i = 1 : nel / n; offset = i; offset2 = 0; while (offset > stride) offset -= stride; offset2 += 1; endwhile offset += offset2 * stride * n; rng = [0 : n-1] * stride + offset; y(i) = diff (empirical_inv ([1/4, 3/4], x(rng))); endfor endfunction %!assert (iqr (1:101), 50) %!assert (iqr (single (1:101)), single (50)) ## FIXME: iqr throws horrible error when running across a dimension that is 1. %!test %! x = [1:100]'; %! assert (iqr (x, 1), 50); %! assert (iqr (x', 2), 50); %!error iqr () %!error iqr (1, 2, 3) %!error iqr (1) %!error iqr (['A'; 'B']) %!error iqr (1:10, 3) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/moment.m0000644000000000000000000000006213443447555022407 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/moment.m0000644000175000017500000001244413443447555023123 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} moment (@var{x}, @var{p}) ## @deftypefnx {} {} moment (@var{x}, @var{p}, @var{type}) ## @deftypefnx {} {} moment (@var{x}, @var{p}, @var{dim}) ## @deftypefnx {} {} moment (@var{x}, @var{p}, @var{type}, @var{dim}) ## @deftypefnx {} {} moment (@var{x}, @var{p}, @var{dim}, @var{type}) ## Compute the @var{p}-th central moment of the vector @var{x}: ## ## @tex ## $$ ## {\sum_{i=1}^N (x_i - \bar{x})^p \over N} ## $$ ## where $\bar{x}$ is the mean value of @var{x} and $N$ is the number of elements of @var{x}. ## ## ## @end tex ## @ifnottex ## ## @example ## @group ## 1/N SUM_i (@var{x}(i) - mean(@var{x}))^@var{p} ## @end group ## @end example ## ## where @math{N} is the length of the @var{x} vector. ## ## @end ifnottex ## ## If @var{x} is a matrix, return the row vector containing the @var{p}-th ## central moment of each column. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## ## The optional string @var{type} specifies the type of moment to be computed. ## Valid options are: ## ## @table @asis ## @item @qcode{"c"} ## Central Moment (default). ## ## @item @qcode{"a"} ## @itemx @qcode{"ac"} ## Absolute Central Moment. The moment about the mean ignoring sign ## defined as ## @tex ## $$ ## {\sum_{i=1}^N {\left| x_i - \bar{x} \right|}^p \over N} ## $$ ## @end tex ## @ifnottex ## ## @example ## @group ## 1/N SUM_i (abs (@var{x}(i) - mean(@var{x})))^@var{p} ## @end group ## @end example ## ## @end ifnottex ## ## @item @qcode{"r"} ## Raw Moment. The moment about zero defined as ## ## @tex ## $$ ## {\rm moment} (x) = { \sum_{i=1}^N {x_i}^p \over N } ## $$ ## @end tex ## @ifnottex ## ## @example ## @group ## moment (@var{x}) = 1/N SUM_i @var{x}(i)^@var{p} ## @end group ## @end example ## ## @end ifnottex ## ## @item @nospell{@qcode{"ar"}} ## Absolute Raw Moment. The moment about zero ignoring sign defined as ## @tex ## $$ ## {\sum_{i=1}^N {\left| x_i \right|}^p \over N} ## $$ ## @end tex ## @ifnottex ## ## @example ## @group ## 1/N SUM_i ( abs (@var{x}(i)) )^@var{p} ## @end group ## @end example ## ## @end ifnottex ## @end table ## ## If both @var{type} and @var{dim} are given they may appear in any order. ## @seealso{var, skewness, kurtosis} ## @end deftypefn ## Can easily be made to work for continuous distributions (using quad) ## as well, but how does the general case work? ## Author: KH ## Description: Compute moments function m = moment (x, p, opt1, opt2) if (nargin < 2 || nargin > 4) print_usage (); endif if (! (isnumeric (x) || islogical (x)) || isempty (x)) error ("moment: X must be a non-empty numeric matrix or vector"); endif if (! (isnumeric (p) && isscalar (p))) error ("moment: P must be a numeric scalar"); endif need_dim = false; if (nargin == 2) type = ""; need_dim = true; elseif (nargin == 3) if (ischar (opt1)) type = opt1; need_dim = true; else dim = opt1; type = ""; endif elseif (nargin == 4) if (ischar (opt1)) type = opt1; dim = opt2; elseif (ischar (opt2)) type = opt2; dim = opt1; else error ("moment: TYPE must be a string"); endif endif nd = ndims (x); sz = size (x); if (need_dim) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("moment: DIM must be an integer and a valid dimension"); endif endif n = size (x, dim); if (! any (type == "r")) x = center (x, dim); endif if (any (type == "a")) x = abs (x); endif m = sum (x .^ p, dim) / n; endfunction %!shared x %! x = rand (10); %!assert (moment (x,1), mean (center (x)), eps) %!assert (moment (x,2), meansq (center (x)), eps) %!assert (moment (x,1,2), mean (center (x, 2), 2), eps) %!assert (moment (x,1,"a"), mean (abs (center (x))), eps) %!assert (moment (x,1,"r"), mean (x), eps) %!assert (moment (x,1,"ar"), mean (abs (x)), eps) %!assert (moment (single ([1 2 3]), 1, "r"), single (2)) %!assert (moment (1, 2, 4), 0) ## Test input validation %!error moment () %!error moment (1) %!error moment (1, 2, 3, 4, 5) %!error moment (['A'; 'B'], 2) %!error moment (ones (2,0,3), 2) %!error

moment (1, true) %!error

moment (1, ones (2,2)) %!error moment (1, 2, 3, 4) %!error moment (1, 2, ones (2,2)) %!error moment (1, 2, 1.5) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/lscov.m0000644000000000000000000000006213443447555022236 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/lscov.m0000644000175000017500000001543613443447555022756 0ustar00johndjohnd00000000000000## Copyright (C) 2014-2017 Nir Krakauer ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {@var{x} =} lscov (@var{A}, @var{b}) ## @deftypefnx {} {@var{x} =} lscov (@var{A}, @var{b}, @var{V}) ## @deftypefnx {} {@var{x} =} lscov (@var{A}, @var{b}, @var{V}, @var{alg}) ## @deftypefnx {} {[@var{x}, @var{stdx}, @var{mse}, @var{S}] =} lscov (@dots{}) ## ## Compute a generalized linear least squares fit. ## ## Estimate @var{x} under the model @var{b} = @var{A}@var{x} + @var{w}, ## where the noise @var{w} is assumed to follow a normal distribution ## with covariance matrix @math{{\sigma^2} V}. ## ## If the size of the coefficient matrix @var{A} is n-by-p, the ## size of the vector/array of constant terms @var{b} must be n-by-k. ## ## The optional input argument @var{V} may be a n-by-1 vector of positive ## weights (inverse variances), or a n-by-n symmetric positive semidefinite ## matrix representing the covariance of @var{b}. If @var{V} is not ## supplied, the ordinary least squares solution is returned. ## ## The @var{alg} input argument, a guidance on solution method to use, is ## currently ignored. ## ## Besides the least-squares estimate matrix @var{x} (p-by-k), the function ## also returns @var{stdx} (p-by-k), the error standard deviation of ## estimated @var{x}; @var{mse} (k-by-1), the estimated data error covariance ## scale factors (@math{\sigma^2}); and @var{S} (p-by-p, or p-by-p-by-k if k ## > 1), the error covariance of @var{x}. ## ## Reference: @nospell{Golub and Van Loan} (1996), ## @cite{Matrix Computations (3rd Ed.)}, Johns Hopkins, Section 5.6.3 ## ## @seealso{ols, gls, lsqnonneg} ## @end deftypefn ## Author: Nir Krakauer function [x, stdx, mse, S] = lscov (A, b, V = [], alg) if (nargin < 2 || (rows (A) != rows (b))) print_usage (); endif n = rows (A); p = columns (A); k = columns (b); if (! isempty (V)) if (rows (V) != n || ! any (columns (V) == [1 n])) error ("lscov: V should be a square matrix or a vector with the same number of rows as A"); endif if (isvector (V)) ## n-by-1 vector of inverse variances v = diag (sqrt (V)); A = v * A; b = v * b; else ## n-by-n covariance matrix try ## ordinarily V will be positive definite B = chol (V)'; catch ## if V is only positive semidefinite, use its ## eigendecomposition to find a factor B such that V = B*B' [B, lambda] = eig (V); image_dims = (diag (lambda) > 0); B = B(:, image_dims) * sqrt (lambda(image_dims, image_dims)); end_try_catch A = B \ A; b = B \ b; endif endif pinv_A = pinv (A); #pseudoinverse x = pinv_A * b; if (isargout (3)) dof = n - p; #degrees of freedom remaining after fit SSE = sumsq (b - A * x); mse = SSE / dof; endif s = pinv_A * pinv_A'; stdx = sqrt (diag (s) * mse); if (isargout (4)) if (k == 1) S = mse * s; else S = NaN (p, p, k); for i = 1:k S(:, :, i) = mse(i) * s; endfor endif endif endfunction %!test <49040> %! ## 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 ]; %! rsd = 304.854073561965; %! y = Z(:,1); X = [ones(rows(Z),1), Z(:,2:end)]; %! alpha = 0.05; %! [b, stdb, mse] = lscov (X, y); %! assert(b, V(:,1), 3e-6); %! assert(stdb, V(:,2), -1.e-5); %! assert(sqrt (mse), rsd, -1E-6); %!test %! ## Adapted from example in Matlab documentation %! x1 = [.2 .5 .6 .8 1.0 1.1]'; %! x2 = [.1 .3 .4 .9 1.1 1.4]'; %! X = [ones(size(x1)) x1 x2]; %! y = [.17 .26 .28 .23 .27 .34]'; %! [b, se_b, mse, S] = lscov(X, y); %! assert(b, [0.1203 0.3284 -0.1312]', 1E-4); %! assert(se_b, [0.0643 0.2267 0.1488]', 1E-4); %! assert(mse, 0.0015, 1E-4); %! assert(S, [0.0041 -0.0130 0.0075; -0.0130 0.0514 -0.0328; 0.0075 -0.0328 0.0221], 1E-4); %! w = [1 1 1 1 1 .1]'; %! [bw, sew_b, msew] = lscov (X, y, w); %! assert(bw, [0.1046 0.4614 -0.2621]', 1E-4); %! assert(sew_b, [0.0309 0.1152 0.0814]', 1E-4); %! assert(msew, 3.4741e-004, -1E-4); %! V = .2*ones(length(x1)) + .8*diag(ones(size(x1))); %! [bg, sew_b, mseg] = lscov (X, y, V); %! assert(bg, [0.1203 0.3284 -0.1312]', 1E-4); %! assert(sew_b, [0.0672 0.2267 0.1488]', 1E-4); %! assert(mseg, 0.0019, 1E-4); %! y2 = [y 2*y]; %! [b2, se_b2, mse2, S2] = lscov (X, y2); %! assert(b2, [b 2*b], 2*eps); %! assert(se_b2, [se_b 2*se_b], eps); %! assert(mse2, [mse 4*mse], eps); %! assert(S2(:, :, 1), S, eps); %! assert(S2(:, :, 2), 4*S, eps); %!test %! ## Artificial example with positive semidefinite weight matrix %! x = (0:0.2:2)'; %! y = round(100*sin(x) + 200*cos(x)); %! X = [ones(size(x)) sin(x) cos(x)]; %! V = eye(numel(x)); %! V(end, end-1) = V(end-1, end) = 1; %! [b, seb, mseb, S] = lscov (X, y, V); %! assert(b, [0 100 200]', 0.2); statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/run_count.m0000644000000000000000000000006213443447555023124 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/run_count.m0000644000175000017500000000616513443447555023643 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Friedrich Leisch ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} run_count (@var{x}, @var{n}) ## @deftypefnx {} {} run_count (@var{x}, @var{n}, @var{dim}) ## Count the upward runs along the first non-singleton dimension of @var{x} ## of length 1, 2, @dots{}, @var{n}-1 and greater than or equal to @var{n}. ## ## If the optional argument @var{dim} is given then operate along this ## dimension. ## @seealso{runlength} ## @end deftypefn ## Author: FL ## Description: Count upward runs function retval = run_count (x, n, dim) if (nargin != 2 && nargin != 3) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("run_count: X must be a numeric vector or matrix"); endif if (!(isscalar (n) && n == fix (n) && n > 0)) error ("run_count: N must be a positive integer"); endif nd = ndims (x); sz = size (x); if (nargin != 3) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (!(isscalar (dim) && dim == fix (dim)) || !(1 <= dim && dim <= nd)) error ("run_count: DIM must be an integer and a valid dimension"); endif endif ## Algorithm works on rows. Permute array if necessary, ipermute back at end if (dim != 1) perm = [1 : nd]; perm(1) = dim; perm(dim) = 1; x = permute (x, perm); endif sz = size (x); idx = cell (); for i = 1 : nd idx{i} = 1 : sz(i); endfor c = sz(1); tmp = zeros ([c + 1, sz(2 : end)]); infvec = Inf ([1, sz(2 : end)]); ind = find (diff ([infvec; x; -infvec]) < 0); tmp(ind(2:end) - 1) = diff (ind); tmp = tmp(idx{:}); sz(1) = n; retval = zeros (sz); for k = 1 : (n-1) idx{1} = k; retval(idx{:}) = sum (tmp == k); endfor idx{1} = n; retval(idx{:}) = sum (tmp >= n); if (dim != 1) retval = ipermute (retval, perm); endif endfunction %!assert (run_count (magic (3), 4), [1,0,1;1,0,1;0,1,0;0,0,0]) %!assert (run_count (magic (3), 4, 2), [1,0,1;1,0,1;0,1,0;0,0,0]') %!assert (run_count (5:-1:1, 5), [5, 0, 0, 0, 0]) %!assert (run_count (ones (3), 4), [0,0,0;0,0,0;1,1,1;0,0,0]) ## Test input validation %!error run_count () %!error run_count (1) %!error run_count (1, 2, 3, 4) %!error run_count ({1, 2}, 3) %!error run_count (['A'; 'A'; 'B'], 3) %!error run_count (1:5, ones (2,2)) %!error run_count (1:5, 1.5) %!error run_count (1:5, -2) %!error run_count (1:5, 3, ones (2,2)) %!error run_count (1:5, 3, 1.5) %!error run_count (1:5, 3, 0) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/var.m0000644000000000000000000000006213443447555021700 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/var.m0000644000175000017500000002130213443447555022405 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} var (@var{x}) ## @deftypefnx {} {} var (@var{x}, @var{opt}) ## @deftypefnx {} {} var (@var{x}, @var{opt}, @var{dim}) ## Compute the variance of the elements of the vector @var{x}. ## ## The variance is defined as ## @tex ## $$ ## {\rm var} (x) = \sigma^2 = {\sum_{i=1}^N (x_i - \bar{x})^2 \over N - 1} ## $$ ## where $\bar{x}$ is the mean value of @var{x} and $N$ is the number of ## elements of @var{x}. ## @end tex ## @ifnottex ## ## @example ## @group ## var (@var{x}) = 1/(N-1) SUM_i (@var{x}(i) - mean(@var{x}))^2 ## @end group ## @end example ## ## where @math{N} is the length of the @var{x} vector. ## ## @end ifnottex ## If @var{x} is a matrix, compute the variance for each column and return ## them in a row vector. ## ## The argument @var{opt} determines the type of normalization to use. ## Valid values are ## ## @table @asis ## @item 0: ## normalize with @math{N-1}, provides the best unbiased estimator of the ## variance [default] ## ## @item 1: ## normalizes with @math{N}, this provides the second moment around the mean ## @end table ## ## If @math{N} is equal to 1 the value of @var{opt} is ignored and ## normalization by @math{N} is used. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## @seealso{cov, std, skewness, kurtosis, moment} ## @end deftypefn ## Author: KH ## Description: Compute variance function retval = var (x, opt = 0, dim) if (nargin < 1 || nargin > 3) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("var: X must be a numeric vector or matrix"); endif if (isempty (opt)) opt = 0; elseif (opt != 0 && opt != 1) error ("var: normalization OPT must be 0 or 1"); endif nd = ndims (x); sz = size (x); if (nargin < 3) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("var: DIM must be an integer and a valid dimension"); endif endif n = size (x, dim); if (isempty (x)) %% codepath for Matlab compatibility. empty x produces NaN output, but %% for ndim > 2, output depends on size of x. if ((nargin < 3) && (nd == 2) && (max (sz) < 2)) retval = NaN; else if (nargin == 3) sz(dim) = 1; else sz (find ((sz ~= 1), 1)) = 1; endif retval = NaN (sz); endif if (isa (x, "single")) retval = single (retval); endif elseif (n == 1) if (isa (x, "single")) retval = zeros (sz, "single"); else retval = zeros (sz); endif elseif (numel (x) > 0) retval = sumsq (center (x, dim), dim) / (n - 1 + opt); else error ("var: X must not be empty"); endif endfunction %!assert (var (13), 0) %!assert (var (single (13)), single (0)) %!assert (var ([1, 2, 3]), 1) %!assert (var ([1, 2, 3], 1), 2/3, eps) %!assert (var ([1, 2, 3], [], 1), [0, 0, 0]) %!assert (var ([1, 2, 3], [], 3), [0, 0, 0]) ##tests for empty input Matlab compatibility (bug #48690) %!assert (var ([]), NaN) %!assert (var (single ([])), single (NaN)) %!assert (var (ones (0, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (var (ones (0, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (var (ones (0, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (var (ones (0, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (var (ones (0, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (var (ones (0, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (var (ones (0, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (var (ones (0, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (var (ones (0, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (var (ones (0, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (var (ones (0, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (var (ones (0, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (var (ones (0, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (var (ones (0, 1, 1, 1)), NaN (1, 1, 1, 1)) %!assert (var (ones (0, 1, 1, 2)), NaN (1, 1, 1, 2)) %!assert (var (ones (0, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (var (ones (0, 1, 2, 1)), NaN (1, 1, 2, 1)) %!assert (var (ones (0, 1, 2, 2)), NaN (1, 1, 2, 2)) %!assert (var (ones (0, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (var (ones (0, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (var (ones (0, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (var (ones (0, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (var (ones (0, 2, 1, 1)), NaN (1, 2, 1, 1)) %!assert (var (ones (0, 2, 1, 2)), NaN (1, 2, 1, 2)) %!assert (var (ones (0, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (var (ones (0, 2, 2, 1)), NaN (1, 2, 2, 1)) %!assert (var (ones (0, 2, 2, 2)), NaN (1, 2, 2, 2)) %!assert (var (ones (1, 0, 0, 0)), NaN (1, 1, 0, 0)) %!assert (var (ones (1, 0, 0, 1)), NaN (1, 1, 0, 1)) %!assert (var (ones (1, 0, 0, 2)), NaN (1, 1, 0, 2)) %!assert (var (ones (1, 0, 1, 0)), NaN (1, 1, 1, 0)) %!assert (var (ones (1, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (var (ones (1, 0, 1, 2)), NaN (1, 1, 1, 2)) %!assert (var (ones (1, 0, 2, 0)), NaN (1, 1, 2, 0)) %!assert (var (ones (1, 0, 2, 1)), NaN (1, 1, 2, 1)) %!assert (var (ones (1, 0, 2, 2)), NaN (1, 1, 2, 2)) %!assert (var (ones (1, 1, 0, 0)), NaN (1, 1, 1, 0)) %!assert (var (ones (1, 1, 0, 1)), NaN (1, 1, 1, 1)) %!assert (var (ones (1, 1, 0, 2)), NaN (1, 1, 1, 2)) %!assert (var (ones (1, 1, 1, 0)), NaN (1, 1, 1, 1)) %!assert (var (ones (1, 1, 2, 0)), NaN (1, 1, 1, 0)) %!assert (var (ones (1, 2, 0, 0)), NaN (1, 1, 0, 0)) %!assert (var (ones (1, 2, 0, 1)), NaN (1, 1, 0, 1)) %!assert (var (ones (1, 2, 0, 2)), NaN (1, 1, 0, 2)) %!assert (var (ones (1, 2, 1, 0)), NaN (1, 1, 1, 0)) %!assert (var (ones (1, 2, 2, 0)), NaN (1, 1, 2, 0)) %!assert (var (ones (2, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (var (ones (2, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (var (ones (2, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (var (ones (2, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (var (ones (2, 0, 1, 1)), NaN (1, 0, 1, 1)) %!assert (var (ones (2, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (var (ones (2, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (var (ones (2, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (var (ones (2, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (var (ones (2, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (var (ones (2, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (var (ones (2, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (var (ones (2, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (var (ones (2, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (var (ones (2, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (var (ones (2, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (var (ones (2, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (var (ones (2, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (var (ones (2, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (var (ones (1, 1, 0, 0, 0)), NaN (1, 1, 1, 0, 0)) %!assert (var (ones (1, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 1)) %!assert (var (ones (2, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) %!assert (var (ones (1, 2, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) %!assert (var (ones (1, 3, 0, 2)), NaN (1, 1, 0, 2)) %!assert (var (single (ones (1, 3, 0, 2))), single (NaN (1, 1, 0, 2))) %!assert (var ([], 0, 1), NaN (1, 0)) %!assert (var ([], 0, 2), NaN (0, 1)) %!assert (var ([], 0, 3), []) %!assert (var (ones (1, 0), 0, 1), NaN (1, 0)) %!assert (var (ones (1, 0), 0, 2), NaN) %!assert (var (ones (1, 0), 0, 3), NaN (1, 0)) %!assert (var (ones (0, 1), 0, 1), NaN) %!assert (var (ones (0, 1), 0, 2), NaN (0, 1)) %!assert (var (ones (0, 1), 0, 3), NaN (0, 1)) %!assert (var ([], 1, 1), NaN (1, 0)) %!assert (var ([], 1, 2), NaN (0, 1)) %!assert (var ([], 1, 3), []) %!assert (var (ones (1, 0), 1, 1), NaN (1, 0)) %!assert (var (ones (1, 0), 1, 2), NaN) %!assert (var (ones (1, 0), 1, 3), NaN (1, 0)) %!assert (var (ones (0, 1), 1, 1), NaN) %!assert (var (ones (0, 1), 1, 2), NaN (0, 1)) %!assert (var (ones (0, 1), 1, 3), NaN (0, 1)) ## Test input validation %!error var () %!error var (1, 2, 3, 4) %!error var (['A'; 'B']) %!error var (1, -1) %!error skewness (1, 2) %!error skewness (1, [1 0]) %!error var (1, [], ones (2, 2)) %!error var (1, [], 1.5) %!error var (1, [], 0) %!error var ([], 1) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/meansq.m0000644000000000000000000000006213443447555022374 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/meansq.m0000644000175000017500000000513213443447555023104 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## Copyright (C) 2009 Jaroslav Hajek ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} meansq (@var{x}) ## @deftypefnx {} {} meansq (@var{x}, @var{dim}) ## Compute the mean square of the elements of the vector @var{x}. ## ## The mean square is defined as ## @tex ## $$ ## {\rm meansq} (x) = {\sum_{i=1}^N {x_i}^2 \over N} ## $$ ## where $N$ is the number of elements of @var{x}. ## ## @end tex ## @ifnottex ## ## @example ## @group ## meansq (@var{x}) = 1/N SUM_i @var{x}(i)^2 ## @end group ## @end example ## ## where @math{N} is the length of the @var{x} vector. ## ## @end ifnottex ## If @var{x} is a matrix, return a row vector containing the mean square ## of each column. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## @seealso{var, std, moment} ## @end deftypefn ## Author: KH ## Description: Compute mean square function y = meansq (x, dim) if (nargin != 1 && nargin != 2) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("mean: X must be a numeric vector or matrix"); endif nd = ndims (x); sz = size (x); if (nargin < 2) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("mean: DIM must be an integer and a valid dimension"); endif endif y = sumsq (x, dim) / size (x, dim); endfunction %!assert (meansq (1:5), 11) %!assert (meansq (single (1:5)), single (11)) %!assert (meansq (magic (4)), [94.5, 92.5, 92.5, 94.5]) %!assert (meansq (magic (4), 2), [109.5; 77.5; 77.5; 109.5]) %!assert (meansq ([1 2], 3), [1 4]) ## Test input validation %!error meansq () %!error meansq (1, 2, 3) %!error meansq (['A'; 'B']) %!error meansq (1, ones (2,2)) %!error meansq (1, 1.5) %!error meansq (1, 0) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/ppplot.m0000644000000000000000000000006213443447555022426 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/ppplot.m0000644000175000017500000000503613443447555023141 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {[@var{p}, @var{y}] =} ppplot (@var{x}, @var{dist}, @var{params}) ## Perform a PP-plot (probability plot). ## ## If F is the CDF of the distribution @var{dist} with parameters ## @var{params} and @var{x} a sample vector of length @var{n}, the PP-plot ## graphs ordinate @var{y}(@var{i}) = F (@var{i}-th largest element of ## @var{x}) versus abscissa @var{p}(@var{i}) = (@var{i} - 0.5)/@var{n}. If ## the sample comes from F, the pairs will approximately follow a straight ## line. ## ## The default for @var{dist} is the standard normal distribution. ## ## The optional argument @var{params} contains a list of parameters of ## @var{dist}. ## ## For example, for a probability plot of the uniform distribution on [2,4] ## and @var{x}, use ## ## @example ## ppplot (x, "uniform", 2, 4) ## @end example ## ## @noindent ## @var{dist} can be any string for which a function @var{dist_cdf} that ## calculates the CDF of distribution @var{dist} exists. ## ## If no output is requested then the data are plotted immediately. ## @seealso{qqplot} ## @end deftypefn ## Author: KH ## Description: Perform a PP-plot (probability plot) function [p, y] = ppplot (x, dist, varargin) if (nargin < 1) print_usage (); endif if (! isvector (x)) error ("ppplot: X must be a vector"); endif s = sort (x); n = length (x); p = ((1 : n)' - 0.5) / n; if (nargin == 1) F = @stdnormal_cdf; elseif (! ischar (dist)) error ("ppplot: DIST must be a string"); else F = str2func ([dist "cdf"]); endif if (nargin <= 2) y = feval (F, s); else y = feval (F, s, varargin{:}); endif if (nargout == 0) plot (p, y); axis ([0, 1, 0, 1]); endif endfunction ## Test input validation %!error ppplot () %!error ppplot (ones (2,2)) %!error ppplot (1, 2) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/kurtosis.m0000644000000000000000000000006213443447555022773 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/kurtosis.m0000644000175000017500000001227213443447555023506 0ustar00johndjohnd00000000000000## Copyright (C) 2013-2017 Julien Bect ## Copyright (C) 1996-2016 John W. Eaton ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} kurtosis (@var{x}) ## @deftypefnx {} {} kurtosis (@var{x}, @var{flag}) ## @deftypefnx {} {} kurtosis (@var{x}, @var{flag}, @var{dim}) ## Compute the sample kurtosis of the elements of @var{x}. ## ## The sample kurtosis is defined as ## @tex ## $$ ## \kappa_1 = {{{1\over N}\, ## \sum_{i=1}^N (x_i - \bar{x})^4} \over \sigma^4}, ## $$ ## where $N$ is the length of @var{x}, $\bar{x}$ its mean, and $\sigma$ ## its (uncorrected) standard deviation. ## @end tex ## @ifnottex ## ## @example ## @group ## mean ((@var{x} - mean (@var{x})).^4) ## k1 = ------------------------ ## std (@var{x}).^4 ## @end group ## @end example ## ## @end ifnottex ## ## @noindent ## The optional argument @var{flag} controls which normalization is used. ## If @var{flag} is equal to 1 (default value, used when @var{flag} is omitted ## or empty), return the sample kurtosis as defined above. If @var{flag} is ## equal to 0, return the @w{"bias-corrected"} kurtosis coefficient instead: ## @tex ## $$ ## \kappa_0 = 3 + {\scriptstyle N - 1 \over \scriptstyle (N - 2)(N - 3)} \, ## \left( (N + 1)\, \kappa_1 - 3 (N - 1) \right) ## $$ ## @end tex ## @ifnottex ## ## @example ## @group ## N - 1 ## k0 = 3 + -------------- * ((N + 1) * k1 - 3 * (N - 1)) ## (N - 2)(N - 3) ## @end group ## @end example ## ## where @math{N} is the length of the @var{x} vector. ## ## @end ifnottex ## The bias-corrected kurtosis coefficient is obtained by replacing the sample ## second and fourth central moments by their unbiased versions. It is an ## unbiased estimate of the population kurtosis for normal populations. ## ## If @var{x} is a matrix, or more generally a multi-dimensional array, return ## the kurtosis along the first non-singleton dimension. If the optional ## @var{dim} argument is given, operate along this dimension. ## ## @seealso{var, skewness, moment} ## @end deftypefn ## Author: KH ## Created: 29 July 1994 ## Adapted-By: jwe function y = kurtosis (x, flag, dim) if (nargin < 1) || (nargin > 3) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("kurtosis: X must be a numeric vector or matrix"); endif if (nargin < 2 || isempty (flag)) flag = 1; # default: do not use the "bias corrected" version else if (! isscalar (flag) || (flag != 0 && flag != 1)) error ("kurtosis: FLAG must be 0 or 1"); endif endif nd = ndims (x); sz = size (x); if (nargin < 3) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("kurtosis: DIM must be an integer and a valid dimension"); endif endif n = size (x, dim); sz(dim) = 1; x = center (x, dim); # center also promotes integer, logical to double v = var (x, 1, dim); # normalize with 1/N y = sum (x .^ 4, dim); idx = (v != 0); y(idx) = y(idx) ./ (n * v(idx) .^ 2); y(! idx) = NaN; ## Apply bias correction to the second and fourth central sample moment if (flag == 0) if (n > 3) C = (n - 1) / ((n - 2) * (n - 3)); y = 3 + C * ((n + 1) * y - 3 * (n - 1)); else y(:) = NaN; endif endif endfunction %!test %! x = [-1; 0; 0; 0; 1]; %! y = [x, 2*x]; %! assert (kurtosis (y), [2.5, 2.5], sqrt (eps)); %!assert (kurtosis ([-3, 0, 1]) == kurtosis ([-1, 0, 3])) %!assert (kurtosis (ones (3, 5)), NaN (1, 5)) %!assert (kurtosis (1, [], 3), NaN) %!assert (kurtosis ([1:5 10; 1:5 10], 0, 2), 5.4377317925288901 * [1; 1], 8 * eps) %!assert (kurtosis ([1:5 10; 1:5 10], 1, 2), 2.9786509002956195 * [1; 1], 8 * eps) %!assert (kurtosis ([1:5 10; 1:5 10], [], 2), 2.9786509002956195 * [1; 1], 8 * eps) ## Test behavior on single input %!assert (kurtosis (single ([1:5 10])), single (2.9786513), eps ("single")) %!assert (kurtosis (single ([1 2]), 0), single (NaN)) ## Verify no "divide-by-zero" warnings %!test %! warning ("on", "Octave:divide-by-zero", "local"); %! lastwarn (""); # clear last warning %! kurtosis (1); %! assert (lastwarn (), ""); ## Test input validation %!error kurtosis () %!error kurtosis (1, 2, 3) %!error kurtosis (['A'; 'B']) %!error kurtosis (1, 2) %!error kurtosis (1, [1 0]) %!error kurtosis (1, [], ones (2,2)) %!error kurtosis (1, [], 1.5) %!error kurtosis (1, [], 0) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/median.m0000644000000000000000000000006213443447555022345 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/median.m0000644000175000017500000002146713443447555023066 0ustar00johndjohnd00000000000000## Copyright (C) 1996-2017 John W. Eaton ## Copyright (C) 2009-2010 VZLU Prague ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} median (@var{x}) ## @deftypefnx {} {} median (@var{x}, @var{dim}) ## Compute the median value of the elements of the vector @var{x}. ## ## When the elements of @var{x} are sorted, say @code{@var{s} = sort (@var{x})}, ## the median is defined as ## @tex ## $$ ## {\rm median} (x) = ## \cases{s(\lceil N/2\rceil), & $N$ odd;\cr ## (s(N/2)+s(N/2+1))/2, & $N$ even.} ## $$ ## where $N$ is the number of elements of @var{x}. ## ## @end tex ## @ifnottex ## ## @example ## @group ## | @var{s}(ceil(N/2)) N odd ## median (@var{x}) = | ## | (@var{s}(N/2) + @var{s}(N/2+1))/2 N even ## @end group ## @end example ## ## @end ifnottex ## If @var{x} is of a discrete type such as integer or logical, then ## the case of even @math{N} rounds up (or toward @code{true}). ## ## If @var{x} is a matrix, compute the median value for each column and ## return them in a row vector. ## ## If the optional @var{dim} argument is given, operate along this dimension. ## @seealso{mean, mode} ## @end deftypefn ## Author: jwe function retval = median (x, dim) if (nargin != 1 && nargin != 2) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("median: X must be a numeric vector or matrix"); endif nd = ndims (x); sz = size (x); if (nargin < 2) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("median: DIM must be an integer and a valid dimension"); endif endif n = size (x, dim); k = floor ((n+1) / 2); if (isempty (x)) %% codepath for Matlab compatibility. empty x produces NaN output, but %% for ndim > 2, output depends on size of x. if ((nd == 2) && (max (sz) < 2) && (nargin ~= 2)) retval = NaN; else if (nargin == 2) sz(dim) = 1; else sz (find ((sz ~= 1), 1)) = 1; endif retval = NaN (sz); endif if (isa (x, "single")) retval = single (retval); endif elseif (mod (n, 2) == 1) retval = nth_element (x, k, dim); else retval = sum (nth_element (x, k:k+1, dim), dim, "native") / 2; if (islogical (x)) retval = logical (retval); endif endif ## Inject NaNs where needed, to be consistent with Matlab. if (isfloat (x)) retval(any (isnan (x), dim)) = NaN; endif endfunction %!test %! x = [1, 2, 3, 4, 5, 6]; %! x2 = x'; %! y = [1, 2, 3, 4, 5, 6, 7]; %! y2 = y'; %! %! assert (median (x) == median (x2) && median (x) == 3.5); %! assert (median (y) == median (y2) && median (y) == 4); %! assert (median ([x2, 2*x2]), [3.5, 7]); %! assert (median ([y2, 3*y2]), [4, 12]); %!assert (median (single ([1, 2, 3])), single (2)) %!assert (median ([1, 2, NaN; 4, 5, 6; NaN, 8, 9]), [NaN, 5, NaN]) %!assert (median ([1, 2], 3), [1, 2]) ## Test multidimensional arrays %!shared a, b, x, y %! rand ("seed", 2); %! a = rand (2, 3, 4, 5); %! b = rand (3, 4, 6, 5); %! x = sort (a, 4); %! y = sort (b, 3); %!assert <35679> (median (a, 4), x(:, :, :, 3)) %!assert <35679> (median (b, 3), (y(:, :, 3, :) + y(:, :, 4, :))/2) ##tests for empty input Matlab compatibility (bug #48690) %!assert (median ([]), NaN) %!assert (median (single ([])), single (NaN)) %!assert (median (ones (0, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (median (ones (0, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (median (ones (0, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (median (ones (0, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (median (ones (0, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (median (ones (0, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (median (ones (0, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (median (ones (0, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (median (ones (0, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (median (ones (0, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (median (ones (0, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (median (ones (0, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (median (ones (0, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (median (ones (0, 1, 1, 1)), NaN (1, 1, 1, 1)) %!assert (median (ones (0, 1, 1, 2)), NaN (1, 1, 1, 2)) %!assert (median (ones (0, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (median (ones (0, 1, 2, 1)), NaN (1, 1, 2, 1)) %!assert (median (ones (0, 1, 2, 2)), NaN (1, 1, 2, 2)) %!assert (median (ones (0, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (median (ones (0, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (median (ones (0, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (median (ones (0, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (median (ones (0, 2, 1, 1)), NaN (1, 2, 1, 1)) %!assert (median (ones (0, 2, 1, 2)), NaN (1, 2, 1, 2)) %!assert (median (ones (0, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (median (ones (0, 2, 2, 1)), NaN (1, 2, 2, 1)) %!assert (median (ones (0, 2, 2, 2)), NaN (1, 2, 2, 2)) %!assert (median (ones (1, 0, 0, 0)), NaN (1, 1, 0, 0)) %!assert (median (ones (1, 0, 0, 1)), NaN (1, 1, 0, 1)) %!assert (median (ones (1, 0, 0, 2)), NaN (1, 1, 0, 2)) %!assert (median (ones (1, 0, 1, 0)), NaN (1, 1, 1, 0)) %!assert (median (ones (1, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (median (ones (1, 0, 1, 2)), NaN (1, 1, 1, 2)) %!assert (median (ones (1, 0, 2, 0)), NaN (1, 1, 2, 0)) %!assert (median (ones (1, 0, 2, 1)), NaN (1, 1, 2, 1)) %!assert (median (ones (1, 0, 2, 2)), NaN (1, 1, 2, 2)) %!assert (median (ones (1, 1, 0, 0)), NaN (1, 1, 1, 0)) %!assert (median (ones (1, 1, 0, 1)), NaN (1, 1, 1, 1)) %!assert (median (ones (1, 1, 0, 2)), NaN (1, 1, 1, 2)) %!assert (median (ones (1, 1, 1, 0)), NaN (1, 1, 1, 1)) %!assert (median (ones (1, 1, 2, 0)), NaN (1, 1, 1, 0)) %!assert (median (ones (1, 2, 0, 0)), NaN (1, 1, 0, 0)) %!assert (median (ones (1, 2, 0, 1)), NaN (1, 1, 0, 1)) %!assert (median (ones (1, 2, 0, 2)), NaN (1, 1, 0, 2)) %!assert (median (ones (1, 2, 1, 0)), NaN (1, 1, 1, 0)) %!assert (median (ones (1, 2, 2, 0)), NaN (1, 1, 2, 0)) %!assert (median (ones (2, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (median (ones (2, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (median (ones (2, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (median (ones (2, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (median (ones (2, 0, 1, 1)), NaN (1, 0, 1, 1)) %!assert (median (ones (2, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (median (ones (2, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (median (ones (2, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (median (ones (2, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (median (ones (2, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (median (ones (2, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (median (ones (2, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (median (ones (2, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (median (ones (2, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (median (ones (2, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (median (ones (2, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (median (ones (2, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (median (ones (2, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (median (ones (2, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (median (ones (1, 1, 0, 0, 0)), NaN (1, 1, 1, 0, 0)) %!assert (median (ones (1, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 1)) %!assert (median (ones (2, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) %!assert (median (ones (1, 2, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) %!assert (median (ones (1, 3, 0, 2)), NaN (1, 1, 0, 2)) %!assert (median (single (ones (1, 3, 0, 2))), single (NaN (1, 1, 0, 2))) %!assert (median ([], 1), NaN (1, 0)) %!assert (median ([], 2), NaN (0, 1)) %!assert (median ([], 3), []) %!assert (median (ones (1, 0), 1), NaN (1, 0)) %!assert (median (ones (1, 0), 2), NaN) %!assert (median (ones (1, 0), 3), NaN (1, 0)) %!assert (median (ones (0, 1), 1), NaN) %!assert (median (ones (0, 1), 2), NaN (0, 1)) %!assert (median (ones (0, 1), 3), NaN (0, 1)) ## Test non-floating point types %!assert (median ([true, false]), true) %!assert (median (uint8 ([1, 3])), uint8 (2)) %!assert (median (int8 ([1, 3, 4])), int8 (3)) %!assert (median (single ([1, 3, 4])), single (3)) %!assert (median (single ([1, 3, NaN])), single (NaN)) ## Test input validation %!error median () %!error median (1, 2, 3) %!error median ({1:5}) %!error median (1, ones (2, 2)) %!error median (1, 1.5) %!error median (1, 0) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/logit.m0000644000000000000000000000006213443447555022226 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/logit.m0000644000175000017500000000272613443447555022744 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} logit (@var{p}) ## Compute the logit for each value of @var{p} ## ## The logit is defined as ## @tex ## $$ ## {\rm logit}(p) = \log\Big({p \over 1-p}\Big) ## $$ ## @end tex ## @ifnottex ## ## @example ## logit (@var{p}) = log (@var{p} / (1-@var{p})) ## @end example ## ## @end ifnottex ## @seealso{probit, logistic_cdf} ## @end deftypefn ## Author: KH ## Description: Logit transformation function y = logit (p) if (nargin != 1) print_usage (); endif y = logistic_inv (p); endfunction %!test %! p = [0.01:0.01:0.99]; %! assert (logit (p), log (p ./ (1-p)), 25*eps); %!assert (logit ([-1, 0, 0.5, 1, 2]), [NaN, -Inf, 0, +Inf, NaN]) ## Test input validation %!error logit () %!error logit (1, 2) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/qqplot.m0000644000000000000000000000006213443447555022430 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/qqplot.m0000644000175000017500000000737413443447555023152 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {[@var{q}, @var{s}] =} qqplot (@var{x}) ## @deftypefnx {} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{y}) ## @deftypefnx {} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{dist}) ## @deftypefnx {} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{y}, @var{params}) ## @deftypefnx {} {} qqplot (@dots{}) ## Perform a QQ-plot (quantile plot). ## ## If F is the CDF of the distribution @var{dist} with parameters ## @var{params} and G its inverse, and @var{x} a sample vector of length ## @var{n}, the QQ-plot graphs ordinate @var{s}(@var{i}) = @var{i}-th ## largest element of x versus abscissa @var{q}(@var{i}f) = G((@var{i} - ## 0.5)/@var{n}). ## ## If the sample comes from F, except for a transformation of location ## and scale, the pairs will approximately follow a straight line. ## ## If the second argument is a vector @var{y} the empirical CDF of @var{y} ## is used as @var{dist}. ## ## The default for @var{dist} is the standard normal distribution. The ## optional argument @var{params} contains a list of parameters of ## @var{dist}. For example, for a quantile plot of the uniform ## distribution on [2,4] and @var{x}, use ## ## @example ## qqplot (x, "unif", 2, 4) ## @end example ## ## @noindent ## @var{dist} can be any string for which a function @var{distinv} or ## @var{dist_inv} exists that calculates the inverse CDF of distribution ## @var{dist}. ## ## If no output arguments are given, the data are plotted directly. ## @seealso{ppplot} ## @end deftypefn ## Author: KH ## Description: Perform a QQ-plot (quantile plot) function [qout, sout] = qqplot (x, dist, varargin) if (nargin < 1) print_usage (); endif if (! (isnumeric (x) && isvector (x))) error ("qqplot: X must be a numeric vector"); endif if (nargin == 1) f = @stdnormal_inv; else if (isnumeric (dist)) f = @(y) empirical_inv (y, dist); elseif (ischar (dist) && (exist (invname = [dist "inv"]) || exist (invname = [dist "_inv"]))) f = str2func (invname); else error ("qqplot: no inverse CDF found for distribution DIST"); endif endif; s = sort (x); n = length (x); t = ((1 : n)' - .5) / n; if (nargin <= 2) q = f (t); q_label = func2str (f); else q = f (t, varargin{:}); if (nargin == 3) q_label = sprintf ("%s with parameter %g", func2str (f), varargin{1}); else q_label = sprintf ("%s with parameters %g", func2str (f), varargin{1}); param_str = sprintf (", %g", varargin{2:end}); q_label = [q_label param_str]; endif endif if (nargout == 0) plot (q, s, "-x"); q_label = strrep (q_label, '_inv', '\_inv'); if (q_label(1) == '@') q_label = q_label(6:end); # Strip "@(y) " from anon. function endif xlabel (q_label); ylabel ("sample points"); else qout = q; sout = s; endif endfunction ## Test input validation %!error qqplot () %!error qqplot ({1}) %!error qqplot (ones (2,2)) %!error qqplot (1, "foobar") statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/corr.m0000644000000000000000000000006213443447555022055 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/corr.m0000644000175000017500000000601213443447555022563 0ustar00johndjohnd00000000000000## Copyright (C) 1996-2017 John W. Eaton ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} corr (@var{x}) ## @deftypefnx {} {} corr (@var{x}, @var{y}) ## Compute matrix of correlation coefficients. ## ## If each row of @var{x} and @var{y} is an observation and each column is ## a variable, then the @w{(@var{i}, @var{j})-th} entry of ## @code{corr (@var{x}, @var{y})} is the correlation between the ## @var{i}-th variable in @var{x} and the @var{j}-th variable in @var{y}. ## @tex ## $$ ## {\rm corr}(x,y) = {{\rm cov}(x,y) \over {\rm std}(x) \, {\rm std}(y)} ## $$ ## @end tex ## @ifnottex ## ## @example ## corr (@var{x},@var{y}) = cov (@var{x},@var{y}) / (std (@var{x}) * std (@var{y})) ## @end example ## ## @end ifnottex ## If called with one argument, compute @code{corr (@var{x}, @var{x})}, ## the correlation between the columns of @var{x}. ## @seealso{cov} ## @end deftypefn ## Author: Kurt Hornik ## Created: March 1993 ## Adapted-By: jwe function retval = corr (x, y = []) if (nargin < 1 || nargin > 2) print_usage (); endif ## Input validation is done by cov.m. Don't repeat tests here ## Special case, scalar is always 100% correlated with itself if (isscalar (x)) if (isa (x, "single")) retval = single (1); else retval = 1; endif return; endif ## No check for division by zero error, which happens only when ## there is a constant vector and should be rare. if (nargin == 2) c = cov (x, y); s = std (x)' * std (y); retval = c ./ s; else c = cov (x); s = sqrt (diag (c)); retval = c ./ (s * s'); endif endfunction %!test %! x = rand (10); %! cc1 = corr (x); %! cc2 = corr (x, x); %! assert (size (cc1) == [10, 10] && size (cc2) == [10, 10]); %! assert (cc1, cc2, sqrt (eps)); %!test %! x = [1:3]'; %! y = [3:-1:1]'; %! assert (corr (x, y), -1, 5*eps); %! assert (corr (x, flipud (y)), 1, 5*eps); %! assert (corr ([x, y]), [1 -1; -1 1], 5*eps); %!test %! x = single ([1:3]'); %! y = single ([3:-1:1]'); %! assert (corr (x, y), single (-1), 5*eps); %! assert (corr (x, flipud (y)), single (1), 5*eps); %! assert (corr ([x, y]), single ([1 -1; -1 1]), 5*eps); %!assert (corr (5), 1) %!assert (corr (single (5)), single (1)) ## Test input validation %!error corr () %!error corr (1, 2, 3) %!error corr ([1; 2], ["A", "B"]) %!error corr (ones (2,2,2)) %!error corr (ones (2,2), ones (2,2,2)) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/cloglog.m0000644000000000000000000000006213443447555022536 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/cloglog.m0000644000175000017500000000263613443447555023254 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} cloglog (@var{x}) ## Return the complementary log-log function of @var{x}. ## ## The complementary log-log function is defined as ## @tex ## $$ ## {\rm cloglog}(x) = - \log (- \log (x)) ## $$ ## @end tex ## @ifnottex ## ## @example ## cloglog (x) = - log (- log (@var{x})) ## @end example ## ## @end ifnottex ## @end deftypefn ## Author: KH ## Description: Complementary log-log function function y = cloglog (x) if (nargin != 1) print_usage (); endif y = - log (- log (x)); endfunction %!assert (cloglog (0), -Inf) %!assert (cloglog (1), Inf) %!assert (cloglog (1/e), 0) ## Test input validation %!error cloglog () %!error cloglog (1, 2) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/mad.m0000644000000000000000000000006213443447555021651 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/mad.m0000644000175000017500000000656513443447555022374 0ustar00johndjohnd00000000000000## Copyright (C) 2017-2018 Rik Wehbring ## ## This file is part of Octave. ## ## Octave is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} mad (@var{x}) ## @deftypefnx {} {} mad (@var{x}, @var{opt}) ## @deftypefnx {} {} mad (@var{x}, @var{opt}, @var{dim}) ## Compute the mean or median absolute deviation of the elements of @var{x}. ## ## The mean absolute deviation is defined as ## ## @example ## @var{mad} = mean (abs (@var{x} - mean (@var{x}))) ## @end example ## ## The median absolute deviation is defined as ## ## @example ## @var{mad} = median (abs (@var{x} - median (@var{x}))) ## @end example ## ## If @var{x} is a matrix, compute @code{mad} for each column and return ## results in a row vector. For a multi-dimensional array, the calculation is ## done over the first non-singleton dimension. ## ## The optional argument @var{opt} determines whether mean or median absolute ## deviation is calculated. The default is 0 which corresponds to mean ## absolute deviation; A value of 1 corresponds to median absolute deviation. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## ## As a measure of dispersion, @code{mad} is less affected by outliers than ## @code{std}. ## @seealso{bounds, range, iqr, std, mean, median} ## @end deftypefn function retval = mad (x, opt = 0, dim) if (nargin < 1 || nargin > 3) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("mad: X must be a numeric vector or matrix"); endif if (isempty (opt)) opt = 0; elseif (! isscalar (opt) || (opt != 0 && opt != 1)) error ("mad: OPT must be 0 or 1"); endif sz = size (x); if (nargin < 3) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("mad: DIM must be an integer and a valid dimension"); endif endif if (opt == 0) fcn = @mean; else fcn = @median; endif retval = fcn (abs (x - fcn (x, dim)), dim); endfunction %!assert (mad ([0 0 1 2 100]), 31.76) %!assert (mad (single ([0 0 1 2 100])), single (31.76)) %!assert (mad ([0 0 1 2 100]'), 31.76) %!assert (mad ([0 0 1 2 100], 1), 1) %!assert (mad (single ([0 0 1 2 100]), 1), single (1)) %!assert (mad ([0 0 1 2 100]', 1), 1) %!assert (mad (magic (4)), [4, 4, 4, 4]) %!assert (mad (magic (4), [], 2), [6; 2; 2; 6]) %!assert (mad (magic (4), 1), [2.5, 3.5, 3.5, 2.5]) %!assert (mad (magic (4), 1, 2), [5.5; 1.5; 1.5; 5.5]) ## Test input validation %!error mad () %!error mad (1, 2, 3, 4) %!error mad (['A'; 'B']) %!error mad (1, 2) %!error mad (1, [], ones (2,2)) %!error mad (1, [], 1.5) %!error mad (1, [], 0) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/center.m0000644000000000000000000000006213443447555022370 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/center.m0000644000175000017500000000615413443447555023105 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## Copyright (C) 2009 VZLU Prague ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} center (@var{x}) ## @deftypefnx {} {} center (@var{x}, @var{dim}) ## Center data by subtracting its mean. ## ## If @var{x} is a vector, subtract its mean. ## ## If @var{x} is a matrix, do the above for each column. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## ## Programming Note: @code{center} has obvious application for normalizing ## statistical data. It is also useful for improving the precision of general ## numerical calculations. Whenever there is a large value that is common ## to a batch of data, the mean can be subtracted off, the calculation ## performed, and then the mean added back to obtain the final answer. ## @seealso{zscore} ## @end deftypefn ## Author: KH ## Description: Center by subtracting means function retval = center (x, dim) if (nargin != 1 && nargin != 2) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("center: X must be a numeric vector or matrix"); endif if (isinteger (x)) x = double (x); endif nd = ndims (x); sz = size (x); if (nargin != 2) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("center: DIM must be an integer and a valid dimension"); endif endif n = size (x, dim); if (n == 0) retval = x; else ## FIXME: Use bsxfun, rather than broadcasting, until broadcasting ## supports diagonal and sparse matrices (Bugs #41441, #35787). retval = bsxfun (@minus, x, mean (x, dim)); ## retval = x - mean (x, dim); # automatic broadcasting endif endfunction %!assert (center ([1,2,3]), [-1,0,1]) %!assert (center (single ([1,2,3])), single ([-1,0,1])) %!assert (center (int8 ([1,2,3])), [-1,0,1]) %!assert (center (logical ([1, 0, 0, 1])), [0.5, -0.5, -0.5, 0.5]) %!assert (center (ones (3,2,0,2)), zeros (3,2,0,2)) %!assert (center (ones (3,2,0,2, "single")), zeros (3,2,0,2, "single")) %!assert (center (magic (3)), [3,-4,1;-2,0,2;-1,4,-3]) %!assert (center ([1 2 3; 6 5 4], 2), [-1 0 1; 1 0 -1]) %!assert (center (1, 3), 0) ## Test input validation %!error center () %!error center (1, 2, 3) %!error center (1, ones (2,2)) %!error center (1, 1.5) %!error center (1, 0) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/ols.m0000644000000000000000000000006213443447555021705 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/ols.m0000644000175000017500000001035513443447555022420 0ustar00johndjohnd00000000000000## Copyright (C) 1996-2017 John W. Eaton ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {[@var{beta}, @var{sigma}, @var{r}] =} ols (@var{y}, @var{x}) ## Ordinary least squares estimation. ## ## OLS applies to the multivariate model ## @tex ## $y = x b + e$ ## with ## $\bar{e} = 0$, and cov(vec($e$)) = kron ($s, I$) ## @end tex ## @ifnottex ## @w{@math{y = x*b + e}} with ## @math{mean (e) = 0} and @math{cov (vec (e)) = kron (s, I)}. ## @end ifnottex ## where ## @tex ## $y$ is a $t \times p$ matrix, $x$ is a $t \times k$ matrix, ## $b$ is a $k \times p$ matrix, and $e$ is a $t \times p$ matrix. ## @end tex ## @ifnottex ## @math{y} is a @math{t} by @math{p} matrix, @math{x} is a @math{t} by @math{k} ## matrix, @math{b} is a @math{k} by @math{p} matrix, and @math{e} is a ## @math{t} by @math{p} matrix. ## @end ifnottex ## ## Each row of @var{y} and @var{x} is an observation and each column a ## variable. ## ## The return values @var{beta}, @var{sigma}, and @var{r} are defined as ## follows. ## ## @table @var ## @item beta ## The OLS estimator for @math{b}. ## @tex ## $beta$ is calculated directly via $(x^Tx)^{-1} x^T y$ if the matrix $x^Tx$ is ## of full rank. ## @end tex ## @ifnottex ## @var{beta} is calculated directly via @code{inv (x'*x) * x' * y} if the ## matrix @code{x'*x} is of full rank. ## @end ifnottex ## Otherwise, @code{@var{beta} = pinv (@var{x}) * @var{y}} where ## @code{pinv (@var{x})} denotes the pseudoinverse of @var{x}. ## ## @item sigma ## The OLS estimator for the matrix @var{s}, ## ## @example ## @group ## @var{sigma} = (@var{y}-@var{x}*@var{beta})' ## * (@var{y}-@var{x}*@var{beta}) ## / (@var{t}-rank(@var{x})) ## @end group ## @end example ## ## @item r ## The matrix of OLS residuals, @code{@var{r} = @var{y} - @var{x}*@var{beta}}. ## @end table ## @seealso{gls, pinv} ## @end deftypefn ## Author: Teresa Twaroch ## Created: May 1993 ## Adapted-By: jwe function [beta, sigma, r] = ols (y, x) if (nargin != 2) print_usage (); endif if (! (isnumeric (x) && isnumeric (y))) error ("ols: X and Y must be numeric matrices or vectors"); endif if (ndims (x) != 2 || ndims (y) != 2) error ("ols: X and Y must be 2-D matrices or vectors"); endif [nr, nc] = size (x); [ry, cy] = size (y); if (nr != ry) error ("ols: number of rows of X and Y must be equal"); endif if (isinteger (x)) x = double (x); endif if (isinteger (y)) y = double (y); endif ## Start of algorithm z = x' * x; [u, p] = chol (z); if (p) beta = pinv (x) * y; else beta = u \ (u' \ (x' * y)); endif if (isargout (2) || isargout (3)) r = y - x * beta; endif if (isargout (2)) ## z is of full rank, avoid the SVD in rnk if (p == 0) rnk = columns (z); else rnk = rank (z); endif sigma = r' * r / (nr - rnk); endif endfunction %!test %! x = [1:5]'; %! y = 3*x + 2; %! x = [x, ones(5,1)]; %! assert (ols (y,x), [3; 2], 50*eps); %!test %! x = [1, 2; 3, 4]; %! y = [1; 2]; %! [b, s, r] = ols (x, y); %! assert (b, [1.4, 2], 2*eps); %! assert (s, [0.2, 0; 0, 0], 2*eps); %! assert (r, [-0.4, 0; 0.2, 0], 2*eps); %!test %! x = [1, 2; 3, 4]; %! y = [1; 2]; %! [b, s] = ols (x, y); %! assert (b, [1.4, 2], 2*eps); %! assert (s, [0.2, 0; 0, 0], 2*eps); %!test %! x = [1, 2; 3, 4]; %! y = [1; 2]; %! b = ols (x, y); %! assert (b, [1.4, 2], 2*eps); ## Test input validation %!error ols () %!error ols (1) %!error ols (1, 2, 3) %!error ols ([true, true], [1, 2]) %!error ols ([1, 2], [true, true]) %!error ols (ones (2,2,2), ones (2,2)) %!error ols (ones (2,2), ones (2,2,2)) %!error ols (ones (1,2), ones (2,2)) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/crosstab.m0000644000000000000000000000006213443447555022730 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/crosstab.m0000644000175000017500000000410113443447555023433 0ustar00johndjohnd00000000000000## Copyright (C) 2018 John Donoghue ## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {@var{t} =} crosstab (@var{x}, @var{y}) ## Create a cross-tabulation (contingency table) @var{t} from data vectors. ## ## The inputs @var{x}, @var{y} must be vectors of equal length with a data ## type of numeric, logical, or char. ## ## Currently, only 1- and 2-dimensional tables are supported. ## @end deftypefn function t = crosstab (x, y) if (nargin != 2) print_usage (); endif if (! ( isvector (x) && isreal (x) && isvector (y) && isreal (y) && (numel (x) == numel (y)))) error ("crosstab: X and Y must be real vectors of the same length"); endif x = x(:); y = y(:); v = unique (x); w = unique (y); for i = 1 : length (v) for j = 1 : length (w) t(i,j) = sum ((x == v(i) | isnan (v(i)) * isnan (x)) & (y == w(j) | isnan (w(j)) * isnan (y))); endfor endfor endfunction ## Test input validation %!error crosstab () %!error crosstab (1) %!error crosstab (1, 2, 3) %!error crosstab (ones (2), [1 1]) %!error crosstab ([1 1], ones (2)) %!error crosstab ({true, true}, [1 1]) %!error crosstab ([1 1], {true, true}) %!error crosstab ([1], [1 1]) %!error crosstab ([1 1], [1]) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/probit.m0000644000000000000000000000006213443447555022407 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/probit.m0000644000175000017500000000234713443447555023124 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} probit (@var{p}) ## Return the probit (the quantile of the standard normal distribution) for ## each element of @var{p}. ## @seealso{logit} ## @end deftypefn ## Written by KH on 1995/02/04 ## Description: Probit transformation function y = probit (p) if (nargin != 1) print_usage (); endif y = stdnormal_inv (p); endfunction %!assert (probit ([-1, 0, 0.5, 1, 2]), [NaN, -Inf, 0, Inf, NaN]) ## Test input validation %!error probit () %!error probit (1, 2) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/ranks.m0000644000000000000000000000006213443447555022226 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/ranks.m0000644000175000017500000000574013443447555022743 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} ranks (@var{x}, @var{dim}) ## Return the ranks of @var{x} along the first non-singleton dimension ## adjusted for ties. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## @seealso{spearman, kendall} ## @end deftypefn ## Author: KH ## Description: Compute ranks ## This code was rather ugly, since it didn't use sort due to the ## fact of how to deal with ties. Now it does use sort and its ## even uglier! At least it handles NDArrays. function y = ranks (x, dim) if (nargin != 1 && nargin != 2) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("ranks: X must be a numeric vector or matrix"); endif nd = ndims (x); sz = size (x); if (nargin != 2) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (!(isscalar (dim) && dim == fix (dim)) || !(1 <= dim && dim <= nd)) error ("ranks: DIM must be an integer and a valid dimension"); endif endif if (sz(dim) == 1) y = ones (sz); else ## The algorithm works only on dim = 1, so permute if necesary. if (dim != 1) perm = [1 : nd]; perm(1) = dim; perm(dim) = 1; x = permute (x, perm); endif sz = size (x); infvec = -Inf ([1, sz(2 : end)]); [xs, xi] = sort (x); eq_el = find (diff ([xs; infvec]) == 0); if (isempty (eq_el)) [eq_el, y] = sort (xi); else runs = setdiff (eq_el, eq_el+1); len = diff (find (diff ([Inf; eq_el; -Inf]) != 1)) + 1; [eq_el, y] = sort (xi); for i = 1 : length (runs) y (xi (runs (i) + [0:(len(i)-1)]) + floor (runs (i) ./ sz(1)) * sz(1)) = eq_el(runs(i)) + (len(i) - 1) / 2; endfor endif if (dim != 1) y = permute (y, perm); endif endif endfunction %!assert (ranks (1:2:10), 1:5) %!assert (ranks (10:-2:1), 5:-1:1) %!assert (ranks ([2, 1, 2, 4]), [2.5, 1, 2.5, 4]) %!assert (ranks (ones (1, 5)), 3*ones (1, 5)) %!assert (ranks (1e6*ones (1, 5)), 3*ones (1, 5)) %!assert (ranks (rand (1, 5), 1), ones (1, 5)) ## Test input validation %!error ranks () %!error ranks (1, 2, 3) %!error ranks ({1, 2}) %!error ranks (['A'; 'B']) %!error ranks (1, 1.5) %!error ranks (1, 0) %!error ranks (1, 3) statistics-1.4.1/install-conditionally/base/PaxHeaders.29769/mean.m0000644000000000000000000000006213443447555022030 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/install-conditionally/base/mean.m0000644000175000017500000002176513443447555022552 0ustar00johndjohnd00000000000000## Copyright (C) 1995-2017 Kurt Hornik ## ## This program is free software: you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation, either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {} {} mean (@var{x}) ## @deftypefnx {} {} mean (@var{x}, @var{dim}) ## @deftypefnx {} {} mean (@var{x}, @var{opt}) ## @deftypefnx {} {} mean (@var{x}, @var{dim}, @var{opt}) ## Compute the mean of the elements of the vector @var{x}. ## ## The mean is defined as ## ## @tex ## $$ {\rm mean}(x) = \bar{x} = {1\over N} \sum_{i=1}^N x_i $$ ## where $N$ is the number of elements of @var{x}. ## ## @end tex ## @ifnottex ## ## @example ## mean (@var{x}) = SUM_i @var{x}(i) / N ## @end example ## ## where @math{N} is the length of the @var{x} vector. ## ## @end ifnottex ## If @var{x} is a matrix, compute the mean for each column and return them ## in a row vector. ## ## If the optional argument @var{dim} is given, operate along this dimension. ## ## The optional argument @var{opt} selects the type of mean to compute. ## The following options are recognized: ## ## @table @asis ## @item @qcode{"a"} ## Compute the (ordinary) arithmetic mean. [default] ## ## @item @qcode{"g"} ## Compute the geometric mean. ## ## @item @qcode{"h"} ## Compute the harmonic mean. ## @end table ## ## Both @var{dim} and @var{opt} are optional. If both are supplied, either ## may appear first. ## @seealso{median, mode} ## @end deftypefn ## Author: KH ## Description: Compute arithmetic, geometric, and harmonic mean function retval = mean (x, opt1, opt2) if (nargin < 1 || nargin > 3) print_usage (); endif if (! (isnumeric (x) || islogical (x))) error ("mean: X must be a numeric vector or matrix"); endif need_dim = false; if (nargin == 1) opt = "a"; need_dim = true; elseif (nargin == 2) if (ischar (opt1)) opt = opt1; need_dim = true; else dim = opt1; opt = "a"; endif elseif (nargin == 3) if (ischar (opt1)) opt = opt1; dim = opt2; elseif (ischar (opt2)) opt = opt2; dim = opt1; else error ("mean: OPT must be a string"); endif else print_usage (); endif nd = ndims (x); sz = size (x); if (need_dim) ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else if (! (isscalar (dim) && dim == fix (dim) && dim > 0)) error ("mean: DIM must be an integer and a valid dimension"); endif endif n = size (x, dim); if (isempty (x)) %% codepath for Matlab compatibility. empty x produces NaN output, but %% for ndim > 2, output depends on size of x and whether DIM is set. if ((nd == 2) && (max (sz) < 2) && need_dim) retval = NaN; else if (~need_dim) sz(dim) = 1; else sz (find ((sz ~= 1), 1)) = 1; endif retval = NaN (sz); endif if (isa (x, "single")) retval = single (retval); endif elseif (strcmp (opt, "a")) retval = sum (x, dim) / n; elseif (strcmp (opt, "g")) if (all (x(:) >= 0)) retval = exp (sum (log (x), dim) ./ n); else error ("mean: X must not contain any negative values"); endif elseif (strcmp (opt, "h")) retval = n ./ sum (1 ./ x, dim); else error ("mean: option '%s' not recognized", opt); endif endfunction %!test %! x = -10:10; %! y = x'; %! z = [y, y+10]; %! assert (mean (x), 0); %! assert (mean (y), 0); %! assert (mean (z), [0, 10]); ## Test small numbers %!assert (mean (repmat (0.1, 1, 1000), "g"), 0.1, 20*eps) %!assert (mean (magic (3), 1), [5, 5, 5]) %!assert (mean (magic (3), 2), [5; 5; 5]) %!assert (mean ([2 8], "g"), 4) %!assert (mean ([4 4 2], "h"), 3) %!assert (mean (logical ([1 0 1 1])), 0.75) %!assert (mean (single ([1 0 1 1])), single (0.75)) %!assert (mean ([1 2], 3), [1 2]) ##tests for empty input Matlab compatibility (bug #48690) %!assert (mean ([]), NaN) %!assert (mean (single([])), single(NaN)) %!assert (mean (ones (0, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (mean (ones (0, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (mean (ones (0, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (mean (ones (0, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (mean (ones (0, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (mean (ones (0, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (mean (ones (0, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (mean (ones (0, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (mean (ones (0, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (mean (ones (0, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (mean (ones (0, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (mean (ones (0, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (mean (ones (0, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (mean (ones (0, 1, 1, 1)), NaN (1, 1, 1, 1)) %!assert (mean (ones (0, 1, 1, 2)), NaN (1, 1, 1, 2)) %!assert (mean (ones (0, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (mean (ones (0, 1, 2, 1)), NaN (1, 1, 2, 1)) %!assert (mean (ones (0, 1, 2, 2)), NaN (1, 1, 2, 2)) %!assert (mean (ones (0, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (mean (ones (0, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (mean (ones (0, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (mean (ones (0, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (mean (ones (0, 2, 1, 1)), NaN (1, 2, 1, 1)) %!assert (mean (ones (0, 2, 1, 2)), NaN (1, 2, 1, 2)) %!assert (mean (ones (0, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (mean (ones (0, 2, 2, 1)), NaN (1, 2, 2, 1)) %!assert (mean (ones (0, 2, 2, 2)), NaN (1, 2, 2, 2)) %!assert (mean (ones (1, 0, 0, 0)), NaN (1, 1, 0, 0)) %!assert (mean (ones (1, 0, 0, 1)), NaN (1, 1, 0, 1)) %!assert (mean (ones (1, 0, 0, 2)), NaN (1, 1, 0, 2)) %!assert (mean (ones (1, 0, 1, 0)), NaN (1, 1, 1, 0)) %!assert (mean (ones (1, 0, 1, 1)), NaN (1, 1, 1, 1)) %!assert (mean (ones (1, 0, 1, 2)), NaN (1, 1, 1, 2)) %!assert (mean (ones (1, 0, 2, 0)), NaN (1, 1, 2, 0)) %!assert (mean (ones (1, 0, 2, 1)), NaN (1, 1, 2, 1)) %!assert (mean (ones (1, 0, 2, 2)), NaN (1, 1, 2, 2)) %!assert (mean (ones (1, 1, 0, 0)), NaN (1, 1, 1, 0)) %!assert (mean (ones (1, 1, 0, 1)), NaN (1, 1, 1, 1)) %!assert (mean (ones (1, 1, 0, 2)), NaN (1, 1, 1, 2)) %!assert (mean (ones (1, 1, 1, 0)), NaN (1, 1, 1, 1)) %!assert (mean (ones (1, 1, 2, 0)), NaN (1, 1, 1, 0)) %!assert (mean (ones (1, 2, 0, 0)), NaN (1, 1, 0, 0)) %!assert (mean (ones (1, 2, 0, 1)), NaN (1, 1, 0, 1)) %!assert (mean (ones (1, 2, 0, 2)), NaN (1, 1, 0, 2)) %!assert (mean (ones (1, 2, 1, 0)), NaN (1, 1, 1, 0)) %!assert (mean (ones (1, 2, 2, 0)), NaN (1, 1, 2, 0)) %!assert (mean (ones (2, 0, 0, 0)), NaN (1, 0, 0, 0)) %!assert (mean (ones (2, 0, 0, 1)), NaN (1, 0, 0, 1)) %!assert (mean (ones (2, 0, 0, 2)), NaN (1, 0, 0, 2)) %!assert (mean (ones (2, 0, 1, 0)), NaN (1, 0, 1, 0)) %!assert (mean (ones (2, 0, 1, 1)), NaN (1, 0, 1, 1)) %!assert (mean (ones (2, 0, 1, 2)), NaN (1, 0, 1, 2)) %!assert (mean (ones (2, 0, 2, 0)), NaN (1, 0, 2, 0)) %!assert (mean (ones (2, 0, 2, 1)), NaN (1, 0, 2, 1)) %!assert (mean (ones (2, 0, 2, 2)), NaN (1, 0, 2, 2)) %!assert (mean (ones (2, 1, 0, 0)), NaN (1, 1, 0, 0)) %!assert (mean (ones (2, 1, 0, 1)), NaN (1, 1, 0, 1)) %!assert (mean (ones (2, 1, 0, 2)), NaN (1, 1, 0, 2)) %!assert (mean (ones (2, 1, 1, 0)), NaN (1, 1, 1, 0)) %!assert (mean (ones (2, 1, 2, 0)), NaN (1, 1, 2, 0)) %!assert (mean (ones (2, 2, 0, 0)), NaN (1, 2, 0, 0)) %!assert (mean (ones (2, 2, 0, 1)), NaN (1, 2, 0, 1)) %!assert (mean (ones (2, 2, 0, 2)), NaN (1, 2, 0, 2)) %!assert (mean (ones (2, 2, 1, 0)), NaN (1, 2, 1, 0)) %!assert (mean (ones (2, 2, 2, 0)), NaN (1, 2, 2, 0)) %!assert (mean (ones (1, 1, 0, 0, 0)), NaN (1, 1, 1, 0, 0)) %!assert (mean (ones (1, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 1)) %!assert (mean (ones (2, 1, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) %!assert (mean (ones (1, 2, 1, 1, 0)), NaN (1, 1, 1, 1, 0)) %!assert (mean (ones (1, 3, 0, 2)), NaN (1, 1, 0, 2)) %!assert (mean (single (ones (1, 3, 0, 2))), single (NaN (1, 1, 0, 2))) %!assert (mean ([], 1), NaN (1, 0)) %!assert (mean ([], 2), NaN (0, 1)) %!assert (mean ([], 3), []) %!assert (mean (ones (1, 0), 1), NaN (1, 0)) %!assert (mean (ones (1, 0), 2), NaN) %!assert (mean (ones (1, 0), 3), NaN (1, 0)) %!assert (mean (ones (0, 1), 1), NaN) %!assert (mean (ones (0, 1), 2), NaN (0, 1)) %!assert (mean (ones (0, 1), 3), NaN (0, 1)) ## Test input validation %!error mean () %!error mean (1, 2, 3, 4) %!error mean ({1:5}) %!error mean (1, 2, 3) %!error mean (1, ones (2, 2)) %!error mean (1, 1.5) %!error mean (1, 0) %!error mean ([1 -1], "g") %!error

Additional statistics functions for GNU Octave statistics cross-validation probability distributions regression data fitting ANOVA boxplot dendrogram Hidden Markov models Hypothesis testing randomization machine learning PCA principal component analysis k-means clustering http://octave.sourceforge.net/statistics https://savannah.gnu.org/bugs/?func=additem&group=octave GPL-3.0+ maintainers@octave.org FSFAP statistics-1.4.1/PaxHeaders.29769/src0000644000000000000000000000013213444214613014200 xustar0030 mtime=1553013131.673852871 30 atime=1553013131.677852968 30 ctime=1553013131.677852968 statistics-1.4.1/src/0000755000175000017500000000000013444214613014766 5ustar00johndjohnd00000000000000statistics-1.4.1/src/PaxHeaders.29769/config.sub0000644000000000000000000000006213443447555016253 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/src/config.sub0000755000175000017500000010677613443447555017006 0ustar00johndjohnd00000000000000#! /bin/sh # Configuration validation subroutine script. # Copyright 1992-2016 Free Software Foundation, Inc. timestamp='2016-11-19' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # Please send patches to . # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases # that are meaningful with *any* GNU software. # Each package is responsible for reporting which valid configurations # it does not support. The user should be able to distinguish # a failure to support a valid configuration from a meaningless # configuration. # The goal of this file is to map all the various variations of a given # machine specification into a single specification in the form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or in some cases, the newer four-part form: # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.sub ($timestamp) Copyright 1992-2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" exit 1 ;; *local*) # First pass through any local machine types. echo $1 exit ;; * ) break ;; esac done case $# in 0) echo "$me: missing argument$help" >&2 exit 1;; 1) ;; *) echo "$me: too many arguments$help" >&2 exit 1;; esac # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \ kopensolaris*-gnu* | cloudabi*-eabi* | \ storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; android-linux) os=-linux-android basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown ;; *) basic_machine=`echo $1 | sed 's/-[^-]*$//'` if [ $basic_machine != $1 ] then os=`echo $1 | sed 's/.*-/-/'` else os=; fi ;; esac ### Let's recognize common machines as not being operating systems so ### that things like config.sub decstation-3100 work. We also ### recognize some manufacturers as not being operating systems, so we ### can provide default operating systems below. case $os in -sun*os*) # Prevent following clause from handling this invalid input. ;; -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ -apple | -axis | -knuth | -cray | -microblaze*) os= basic_machine=$1 ;; -bluegene*) os=-cnk ;; -sim | -cisco | -oki | -wec | -winbond) os= basic_machine=$1 ;; -scout) ;; -wrs) os=-vxworks basic_machine=$1 ;; -chorusos*) os=-chorusos basic_machine=$1 ;; -chorusrdb) os=-chorusrdb basic_machine=$1 ;; -hiux*) os=-hiuxwe2 ;; -sco6) os=-sco5v6 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco5) os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco4) os=-sco3.2v4 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco3.2.[4-9]*) os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco3.2v[4-9]*) # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco5v6*) # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco*) os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -udk*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -isc) os=-isc2.2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -clix*) basic_machine=clipper-intergraph ;; -isc*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -lynx*178) os=-lynxos178 ;; -lynx*5) os=-lynxos5 ;; -lynx*) os=-lynxos ;; -ptx*) basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` ;; -windowsnt*) os=`echo $os | sed -e 's/windowsnt/winnt/'` ;; -psos*) os=-psos ;; -mint | -mint[0-9]*) basic_machine=m68k-atari os=-mint ;; esac # Decode aliases for certain CPU-COMPANY combinations. case $basic_machine in # Recognize the basic CPU types without company name. # Some are omitted here because they have special meanings below. 1750a | 580 \ | a29k \ | aarch64 | aarch64_be \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ | am33_2.0 \ | arc | arceb \ | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ | avr | avr32 \ | ba \ | be32 | be64 \ | bfin \ | c4x | c8051 | clipper \ | d10v | d30v | dlx | dsp16xx \ | e2k | epiphany \ | fido | fr30 | frv | ft32 \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | hexagon \ | i370 | i860 | i960 | ia64 \ | ip2k | iq2000 \ | k1om \ | le32 | le64 \ | lm32 \ | m32c | m32r | m32rle | m68000 | m68k | m88k \ | maxq | mb | microblaze | microblazeel | mcore | mep | metag \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ | mips64octeon | mips64octeonel \ | mips64orion | mips64orionel \ | mips64r5900 | mips64r5900el \ | mips64vr | mips64vrel \ | mips64vr4100 | mips64vr4100el \ | mips64vr4300 | mips64vr4300el \ | mips64vr5000 | mips64vr5000el \ | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ | mipsisa32r6 | mipsisa32r6el \ | mipsisa64 | mipsisa64el \ | mipsisa64r2 | mipsisa64r2el \ | mipsisa64r6 | mipsisa64r6el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ | mipsr5900 | mipsr5900el \ | mipstx39 | mipstx39el \ | mn10200 | mn10300 \ | moxie \ | mt \ | msp430 \ | nds32 | nds32le | nds32be \ | nios | nios2 | nios2eb | nios2el \ | ns16k | ns32k \ | open8 | or1k | or1knd | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle \ | pru \ | pyramid \ | riscv32 | riscv64 \ | rl78 | rx \ | score \ | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ | spu \ | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \ | ubicom32 \ | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \ | visium \ | we32k \ | x86 | xc16x | xstormy16 | xtensa \ | z8k | z80) basic_machine=$basic_machine-unknown ;; c54x) basic_machine=tic54x-unknown ;; c55x) basic_machine=tic55x-unknown ;; c6x) basic_machine=tic6x-unknown ;; leon|leon[3-9]) basic_machine=sparc-$basic_machine ;; m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip) basic_machine=$basic_machine-unknown os=-none ;; m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) ;; ms1) basic_machine=mt-unknown ;; strongarm | thumb | xscale) basic_machine=arm-unknown ;; xgate) basic_machine=$basic_machine-unknown os=-none ;; xscaleeb) basic_machine=armeb-unknown ;; xscaleel) basic_machine=armel-unknown ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and # (2) the word "unknown" tends to confuse beginning users. i*86 | x86_64) basic_machine=$basic_machine-pc ;; # Object if more than one company name word. *-*-*) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 ;; # Recognize the basic CPU types with company name. 580-* \ | a29k-* \ | aarch64-* | aarch64_be-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* | avr32-* \ | ba-* \ | be32-* | be64-* \ | bfin-* | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* \ | c8051-* | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | e2k-* | elxsi-* \ | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | hexagon-* \ | i*86-* | i860-* | i960-* | ia64-* \ | ip2k-* | iq2000-* \ | k1om-* \ | le32-* | le64-* \ | lm32-* \ | m32c-* | m32r-* | m32rle-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ | microblaze-* | microblazeel-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ | mips64octeon-* | mips64octeonel-* \ | mips64orion-* | mips64orionel-* \ | mips64r5900-* | mips64r5900el-* \ | mips64vr-* | mips64vrel-* \ | mips64vr4100-* | mips64vr4100el-* \ | mips64vr4300-* | mips64vr4300el-* \ | mips64vr5000-* | mips64vr5000el-* \ | mips64vr5900-* | mips64vr5900el-* \ | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa32r6-* | mipsisa32r6el-* \ | mipsisa64-* | mipsisa64el-* \ | mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64r6-* | mipsisa64r6el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipsr5900-* | mipsr5900el-* \ | mipstx39-* | mipstx39el-* \ | mmix-* \ | mt-* \ | msp430-* \ | nds32-* | nds32le-* | nds32be-* \ | nios-* | nios2-* | nios2eb-* | nios2el-* \ | none-* | np1-* | ns16k-* | ns32k-* \ | open8-* \ | or1k*-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ | pru-* \ | pyramid-* \ | riscv32-* | riscv64-* \ | rl78-* | romp-* | rs6000-* | rx-* \ | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ | sparclite-* \ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \ | tahoe-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tile*-* \ | tron-* \ | ubicom32-* \ | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \ | vax-* \ | visium-* \ | we32k-* \ | x86-* | x86_64-* | xc16x-* | xps100-* \ | xstormy16-* | xtensa*-* \ | ymp-* \ | z8k-* | z80-*) ;; # Recognize the basic CPU types without company name, with glob match. xtensa*) basic_machine=$basic_machine-unknown ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. 386bsd) basic_machine=i386-unknown os=-bsd ;; 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) basic_machine=m68000-att ;; 3b*) basic_machine=we32k-att ;; a29khif) basic_machine=a29k-amd os=-udi ;; abacus) basic_machine=abacus-unknown ;; adobe68k) basic_machine=m68010-adobe os=-scout ;; alliant | fx80) basic_machine=fx80-alliant ;; altos | altos3068) basic_machine=m68k-altos ;; am29k) basic_machine=a29k-none os=-bsd ;; amd64) basic_machine=x86_64-pc ;; amd64-*) basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; amdahl) basic_machine=580-amdahl os=-sysv ;; amiga | amiga-*) basic_machine=m68k-unknown ;; amigaos | amigados) basic_machine=m68k-unknown os=-amigaos ;; amigaunix | amix) basic_machine=m68k-unknown os=-sysv4 ;; apollo68) basic_machine=m68k-apollo os=-sysv ;; apollo68bsd) basic_machine=m68k-apollo os=-bsd ;; aros) basic_machine=i386-pc os=-aros ;; asmjs) basic_machine=asmjs-unknown ;; aux) basic_machine=m68k-apple os=-aux ;; balance) basic_machine=ns32k-sequent os=-dynix ;; blackfin) basic_machine=bfin-unknown os=-linux ;; blackfin-*) basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; bluegene*) basic_machine=powerpc-ibm os=-cnk ;; c54x-*) basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'` ;; c55x-*) basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'` ;; c6x-*) basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'` ;; c90) basic_machine=c90-cray os=-unicos ;; cegcc) basic_machine=arm-unknown os=-cegcc ;; convex-c1) basic_machine=c1-convex os=-bsd ;; convex-c2) basic_machine=c2-convex os=-bsd ;; convex-c32) basic_machine=c32-convex os=-bsd ;; convex-c34) basic_machine=c34-convex os=-bsd ;; convex-c38) basic_machine=c38-convex os=-bsd ;; cray | j90) basic_machine=j90-cray os=-unicos ;; craynv) basic_machine=craynv-cray os=-unicosmp ;; cr16 | cr16-*) basic_machine=cr16-unknown os=-elf ;; crds | unos) basic_machine=m68k-crds ;; crisv32 | crisv32-* | etraxfs*) basic_machine=crisv32-axis ;; cris | cris-* | etrax*) basic_machine=cris-axis ;; crx) basic_machine=crx-unknown os=-elf ;; da30 | da30-*) basic_machine=m68k-da30 ;; decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) basic_machine=mips-dec ;; decsystem10* | dec10*) basic_machine=pdp10-dec os=-tops10 ;; decsystem20* | dec20*) basic_machine=pdp10-dec os=-tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) basic_machine=m68k-motorola ;; delta88) basic_machine=m88k-motorola os=-sysv3 ;; dicos) basic_machine=i686-pc os=-dicos ;; djgpp) basic_machine=i586-pc os=-msdosdjgpp ;; dpx20 | dpx20-*) basic_machine=rs6000-bull os=-bosx ;; dpx2* | dpx2*-bull) basic_machine=m68k-bull os=-sysv3 ;; e500v[12]) basic_machine=powerpc-unknown os=$os"spe" ;; e500v[12]-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` os=$os"spe" ;; ebmon29k) basic_machine=a29k-amd os=-ebmon ;; elxsi) basic_machine=elxsi-elxsi os=-bsd ;; encore | umax | mmax) basic_machine=ns32k-encore ;; es1800 | OSE68k | ose68k | ose | OSE) basic_machine=m68k-ericsson os=-ose ;; fx2800) basic_machine=i860-alliant ;; genix) basic_machine=ns32k-ns ;; gmicro) basic_machine=tron-gmicro os=-sysv ;; go32) basic_machine=i386-pc os=-go32 ;; h3050r* | hiux*) basic_machine=hppa1.1-hitachi os=-hiuxwe2 ;; h8300hms) basic_machine=h8300-hitachi os=-hms ;; h8300xray) basic_machine=h8300-hitachi os=-xray ;; h8500hms) basic_machine=h8500-hitachi os=-hms ;; harris) basic_machine=m88k-harris os=-sysv3 ;; hp300-*) basic_machine=m68k-hp ;; hp300bsd) basic_machine=m68k-hp os=-bsd ;; hp300hpux) basic_machine=m68k-hp os=-hpux ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) basic_machine=hppa1.0-hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) basic_machine=m68000-hp ;; hp9k3[2-9][0-9]) basic_machine=m68k-hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) basic_machine=hppa1.0-hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) basic_machine=hppa1.1-hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp basic_machine=hppa1.1-hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp basic_machine=hppa1.1-hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) basic_machine=hppa1.1-hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) basic_machine=hppa1.0-hp ;; hppa-next) os=-nextstep3 ;; hppaosf) basic_machine=hppa1.1-hp os=-osf ;; hppro) basic_machine=hppa1.1-hp os=-proelf ;; i370-ibm* | ibm*) basic_machine=i370-ibm ;; i*86v32) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv32 ;; i*86v4*) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv4 ;; i*86v) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv ;; i*86sol2) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-solaris2 ;; i386mach) basic_machine=i386-mach os=-mach ;; i386-vsta | vsta) basic_machine=i386-unknown os=-vsta ;; iris | iris4d) basic_machine=mips-sgi case $os in -irix*) ;; *) os=-irix4 ;; esac ;; isi68 | isi) basic_machine=m68k-isi os=-sysv ;; leon-*|leon[3-9]-*) basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'` ;; m68knommu) basic_machine=m68k-unknown os=-linux ;; m68knommu-*) basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; m88k-omron*) basic_machine=m88k-omron ;; magnum | m3230) basic_machine=mips-mips os=-sysv ;; merlin) basic_machine=ns32k-utek os=-sysv ;; microblaze*) basic_machine=microblaze-xilinx ;; mingw64) basic_machine=x86_64-pc os=-mingw64 ;; mingw32) basic_machine=i686-pc os=-mingw32 ;; mingw32ce) basic_machine=arm-unknown os=-mingw32ce ;; miniframe) basic_machine=m68000-convergent ;; *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) basic_machine=m68k-atari os=-mint ;; mips3*-*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` ;; mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; monitor) basic_machine=m68k-rom68k os=-coff ;; morphos) basic_machine=powerpc-unknown os=-morphos ;; moxiebox) basic_machine=moxie-unknown os=-moxiebox ;; msdos) basic_machine=i386-pc os=-msdos ;; ms1-*) basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` ;; msys) basic_machine=i686-pc os=-msys ;; mvs) basic_machine=i370-ibm os=-mvs ;; nacl) basic_machine=le32-unknown os=-nacl ;; ncr3000) basic_machine=i486-ncr os=-sysv4 ;; netbsd386) basic_machine=i386-unknown os=-netbsd ;; netwinder) basic_machine=armv4l-rebel os=-linux ;; news | news700 | news800 | news900) basic_machine=m68k-sony os=-newsos ;; news1000) basic_machine=m68030-sony os=-newsos ;; news-3600 | risc-news) basic_machine=mips-sony os=-newsos ;; necv70) basic_machine=v70-nec os=-sysv ;; next | m*-next ) basic_machine=m68k-next case $os in -nextstep* ) ;; -ns2*) os=-nextstep2 ;; *) os=-nextstep3 ;; esac ;; nh3000) basic_machine=m68k-harris os=-cxux ;; nh[45]000) basic_machine=m88k-harris os=-cxux ;; nindy960) basic_machine=i960-intel os=-nindy ;; mon960) basic_machine=i960-intel os=-mon960 ;; nonstopux) basic_machine=mips-compaq os=-nonstopux ;; np1) basic_machine=np1-gould ;; neo-tandem) basic_machine=neo-tandem ;; nse-tandem) basic_machine=nse-tandem ;; nsr-tandem) basic_machine=nsr-tandem ;; op50n-* | op60c-*) basic_machine=hppa1.1-oki os=-proelf ;; openrisc | openrisc-*) basic_machine=or32-unknown ;; os400) basic_machine=powerpc-ibm os=-os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson os=-ose ;; os68k) basic_machine=m68k-none os=-os68k ;; pa-hitachi) basic_machine=hppa1.1-hitachi os=-hiuxwe2 ;; paragon) basic_machine=i860-intel os=-osf ;; parisc) basic_machine=hppa-unknown os=-linux ;; parisc-*) basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; pbd) basic_machine=sparc-tti ;; pbb) basic_machine=m68k-tti ;; pc532 | pc532-*) basic_machine=ns32k-pc532 ;; pc98) basic_machine=i386-pc ;; pc98-*) basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentium | p5 | k5 | k6 | nexgen | viac3) basic_machine=i586-pc ;; pentiumpro | p6 | 6x86 | athlon | athlon_*) basic_machine=i686-pc ;; pentiumii | pentium2 | pentiumiii | pentium3) basic_machine=i686-pc ;; pentium4) basic_machine=i786-pc ;; pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentiumpro-* | p6-* | 6x86-* | athlon-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentium4-*) basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pn) basic_machine=pn-gould ;; power) basic_machine=power-ibm ;; ppc | ppcbe) basic_machine=powerpc-unknown ;; ppc-* | ppcbe-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppcle | powerpclittle) basic_machine=powerpcle-unknown ;; ppcle-* | powerpclittle-*) basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppc64) basic_machine=powerpc64-unknown ;; ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppc64le | powerpc64little) basic_machine=powerpc64le-unknown ;; ppc64le-* | powerpc64little-*) basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ps2) basic_machine=i386-ibm ;; pw32) basic_machine=i586-unknown os=-pw32 ;; rdos | rdos64) basic_machine=x86_64-pc os=-rdos ;; rdos32) basic_machine=i386-pc os=-rdos ;; rom68k) basic_machine=m68k-rom68k os=-coff ;; rm[46]00) basic_machine=mips-siemens ;; rtpc | rtpc-*) basic_machine=romp-ibm ;; s390 | s390-*) basic_machine=s390-ibm ;; s390x | s390x-*) basic_machine=s390x-ibm ;; sa29200) basic_machine=a29k-amd os=-udi ;; sb1) basic_machine=mipsisa64sb1-unknown ;; sb1el) basic_machine=mipsisa64sb1el-unknown ;; sde) basic_machine=mipsisa32-sde os=-elf ;; sei) basic_machine=mips-sei os=-seiux ;; sequent) basic_machine=i386-sequent ;; sh) basic_machine=sh-hitachi os=-hms ;; sh5el) basic_machine=sh5le-unknown ;; sh64) basic_machine=sh64-unknown ;; sparclite-wrs | simso-wrs) basic_machine=sparclite-wrs os=-vxworks ;; sps7) basic_machine=m68k-bull os=-sysv2 ;; spur) basic_machine=spur-unknown ;; st2000) basic_machine=m68k-tandem ;; stratus) basic_machine=i860-stratus os=-sysv4 ;; strongarm-* | thumb-*) basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'` ;; sun2) basic_machine=m68000-sun ;; sun2os3) basic_machine=m68000-sun os=-sunos3 ;; sun2os4) basic_machine=m68000-sun os=-sunos4 ;; sun3os3) basic_machine=m68k-sun os=-sunos3 ;; sun3os4) basic_machine=m68k-sun os=-sunos4 ;; sun4os3) basic_machine=sparc-sun os=-sunos3 ;; sun4os4) basic_machine=sparc-sun os=-sunos4 ;; sun4sol2) basic_machine=sparc-sun os=-solaris2 ;; sun3 | sun3-*) basic_machine=m68k-sun ;; sun4) basic_machine=sparc-sun ;; sun386 | sun386i | roadrunner) basic_machine=i386-sun ;; sv1) basic_machine=sv1-cray os=-unicos ;; symmetry) basic_machine=i386-sequent os=-dynix ;; t3e) basic_machine=alphaev5-cray os=-unicos ;; t90) basic_machine=t90-cray os=-unicos ;; tile*) basic_machine=$basic_machine-unknown os=-linux-gnu ;; tx39) basic_machine=mipstx39-unknown ;; tx39el) basic_machine=mipstx39el-unknown ;; toad1) basic_machine=pdp10-xkl os=-tops20 ;; tower | tower-32) basic_machine=m68k-ncr ;; tpf) basic_machine=s390x-ibm os=-tpf ;; udi29k) basic_machine=a29k-amd os=-udi ;; ultra3) basic_machine=a29k-nyu os=-sym1 ;; v810 | necv810) basic_machine=v810-nec os=-none ;; vaxv) basic_machine=vax-dec os=-sysv ;; vms) basic_machine=vax-dec os=-vms ;; vpp*|vx|vx-*) basic_machine=f301-fujitsu ;; vxworks960) basic_machine=i960-wrs os=-vxworks ;; vxworks68) basic_machine=m68k-wrs os=-vxworks ;; vxworks29k) basic_machine=a29k-wrs os=-vxworks ;; w65*) basic_machine=w65-wdc os=-none ;; w89k-*) basic_machine=hppa1.1-winbond os=-proelf ;; xbox) basic_machine=i686-pc os=-mingw32 ;; xps | xps100) basic_machine=xps100-honeywell ;; xscale-* | xscalee[bl]-*) basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'` ;; ymp) basic_machine=ymp-cray os=-unicos ;; z8k-*-coff) basic_machine=z8k-unknown os=-sim ;; z80-*-coff) basic_machine=z80-unknown os=-sim ;; none) basic_machine=none-none os=-none ;; # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. w89k) basic_machine=hppa1.1-winbond ;; op50n) basic_machine=hppa1.1-oki ;; op60c) basic_machine=hppa1.1-oki ;; romp) basic_machine=romp-ibm ;; mmix) basic_machine=mmix-knuth ;; rs6000) basic_machine=rs6000-ibm ;; vax) basic_machine=vax-dec ;; pdp10) # there are many clones, so DEC is not a safe bet basic_machine=pdp10-unknown ;; pdp11) basic_machine=pdp11-dec ;; we32k) basic_machine=we32k-att ;; sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) basic_machine=sparc-sun ;; cydra) basic_machine=cydra-cydrome ;; orion) basic_machine=orion-highlevel ;; orion105) basic_machine=clipper-highlevel ;; mac | mpw | mac-mpw) basic_machine=m68k-apple ;; pmac | pmac-mpw) basic_machine=powerpc-apple ;; *-unknown) # Make sure to match an already-canonicalized machine name. ;; *) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 ;; esac # Here we canonicalize certain aliases for manufacturers. case $basic_machine in *-digital*) basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` ;; *-commodore*) basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` ;; *) ;; esac # Decode manufacturer-specific aliases for certain operating systems. if [ x"$os" != x"" ] then case $os in # First match some system type aliases # that might get confused with valid system types. # -solaris* is a basic system type, with this one exception. -auroraux) os=-auroraux ;; -solaris1 | -solaris1.*) os=`echo $os | sed -e 's|solaris1|sunos4|'` ;; -solaris) os=-solaris2 ;; -svr4*) os=-sysv4 ;; -unixware*) os=-sysv4.2uw ;; -gnu/linux*) os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` ;; # First accept the basic system types. # The portable systems comes first. # Each alternative MUST END IN A *, to match a version number. # -sysv* is not here because it comes later, after sysvr4. -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ | -sym* | -kopensolaris* | -plan9* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ | -aos* | -aros* | -cloudabi* | -sortix* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* | -cegcc* | -glidix* \ | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ | -linux-newlib* | -linux-musl* | -linux-uclibc* \ | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \ | -onefs* | -tirtos* | -phoenix* | -fuchsia*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) case $basic_machine in x86-* | i*86-*) ;; *) os=-nto$os ;; esac ;; -nto-qnx*) ;; -nto*) os=`echo $os | sed -e 's|nto|nto-qnx|'` ;; -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) ;; -mac*) os=`echo $os | sed -e 's|mac|macos|'` ;; -linux-dietlibc) os=-linux-dietlibc ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; -sunos5*) os=`echo $os | sed -e 's|sunos5|solaris2|'` ;; -sunos6*) os=`echo $os | sed -e 's|sunos6|solaris3|'` ;; -opened*) os=-openedition ;; -os400*) os=-os400 ;; -wince*) os=-wince ;; -osfrose*) os=-osfrose ;; -osf*) os=-osf ;; -utek*) os=-bsd ;; -dynix*) os=-bsd ;; -acis*) os=-aos ;; -atheos*) os=-atheos ;; -syllable*) os=-syllable ;; -386bsd) os=-bsd ;; -ctix* | -uts*) os=-sysv ;; -nova*) os=-rtmk-nova ;; -ns2 ) os=-nextstep2 ;; -nsk*) os=-nsk ;; # Preserve the version number of sinix5. -sinix5.*) os=`echo $os | sed -e 's|sinix|sysv|'` ;; -sinix*) os=-sysv4 ;; -tpf*) os=-tpf ;; -triton*) os=-sysv3 ;; -oss*) os=-sysv3 ;; -svr4) os=-sysv4 ;; -svr3) os=-sysv3 ;; -sysvr4) os=-sysv4 ;; # This must come after -sysvr4. -sysv*) ;; -ose*) os=-ose ;; -es1800*) os=-ose ;; -xenix) os=-xenix ;; -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) os=-mint ;; -aros*) os=-aros ;; -zvmoe) os=-zvmoe ;; -dicos*) os=-dicos ;; -nacl*) ;; -ios) ;; -none) ;; *) # Get rid of the `-' at the beginning of $os. os=`echo $os | sed 's/[^-]*-//'` echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 exit 1 ;; esac else # Here we handle the default operating systems that come with various machines. # The value should be what the vendor currently ships out the door with their # machine or put another way, the most popular os provided with the machine. # Note that if you're going to try to match "-MANUFACTURER" here (say, # "-sun"), then you have to tell the case statement up towards the top # that MANUFACTURER isn't an operating system. Otherwise, code above # will signal an error saying that MANUFACTURER isn't an operating # system, and we'll never get to this point. case $basic_machine in score-*) os=-elf ;; spu-*) os=-elf ;; *-acorn) os=-riscix1.2 ;; arm*-rebel) os=-linux ;; arm*-semi) os=-aout ;; c4x-* | tic4x-*) os=-coff ;; c8051-*) os=-elf ;; hexagon-*) os=-elf ;; tic54x-*) os=-coff ;; tic55x-*) os=-coff ;; tic6x-*) os=-coff ;; # This must come before the *-dec entry. pdp10-*) os=-tops20 ;; pdp11-*) os=-none ;; *-dec | vax-*) os=-ultrix4.2 ;; m68*-apollo) os=-domain ;; i386-sun) os=-sunos4.0.2 ;; m68000-sun) os=-sunos3 ;; m68*-cisco) os=-aout ;; mep-*) os=-elf ;; mips*-cisco) os=-elf ;; mips*-*) os=-elf ;; or32-*) os=-coff ;; *-tti) # must be before sparc entry or we get the wrong os. os=-sysv3 ;; sparc-* | *-sun) os=-sunos4.1.1 ;; *-be) os=-beos ;; *-haiku) os=-haiku ;; *-ibm) os=-aix ;; *-knuth) os=-mmixware ;; *-wec) os=-proelf ;; *-winbond) os=-proelf ;; *-oki) os=-proelf ;; *-hp) os=-hpux ;; *-hitachi) os=-hiux ;; i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) os=-sysv ;; *-cbm) os=-amigaos ;; *-dg) os=-dgux ;; *-dolphin) os=-sysv3 ;; m68k-ccur) os=-rtu ;; m88k-omron*) os=-luna ;; *-next ) os=-nextstep ;; *-sequent) os=-ptx ;; *-crds) os=-unos ;; *-ns) os=-genix ;; i370-*) os=-mvs ;; *-next) os=-nextstep3 ;; *-gould) os=-sysv ;; *-highlevel) os=-bsd ;; *-encore) os=-bsd ;; *-sgi) os=-irix ;; *-siemens) os=-sysv4 ;; *-masscomp) os=-rtu ;; f30[01]-fujitsu | f700-fujitsu) os=-uxpv ;; *-rom68k) os=-coff ;; *-*bug) os=-coff ;; *-apple) os=-macos ;; *-atari*) os=-mint ;; *) os=-none ;; esac fi # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. vendor=unknown case $basic_machine in *-unknown) case $os in -riscix*) vendor=acorn ;; -sunos*) vendor=sun ;; -cnk*|-aix*) vendor=ibm ;; -beos*) vendor=be ;; -hpux*) vendor=hp ;; -mpeix*) vendor=hp ;; -hiux*) vendor=hitachi ;; -unos*) vendor=crds ;; -dgux*) vendor=dg ;; -luna*) vendor=omron ;; -genix*) vendor=ns ;; -mvs* | -opened*) vendor=ibm ;; -os400*) vendor=ibm ;; -ptx*) vendor=sequent ;; -tpf*) vendor=ibm ;; -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; -aux*) vendor=apple ;; -hms*) vendor=hitachi ;; -mpw* | -macos*) vendor=apple ;; -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) vendor=atari ;; -vos*) vendor=stratus ;; esac basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac echo $basic_machine$os exit # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: statistics-1.4.1/src/PaxHeaders.29769/configure0000644000000000000000000000013213444214613016161 xustar0030 mtime=1553013131.669852774 30 atime=1553013131.617851507 30 ctime=1553013131.677852968 statistics-1.4.1/src/configure0000755000175000017500000034002613444214613016702 0ustar00johndjohnd00000000000000#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69 for statistics 1.4.1. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='statistics' PACKAGE_TARNAME='statistics' PACKAGE_VERSION='1.4.1' PACKAGE_STRING='statistics 1.4.1' PACKAGE_BUGREPORT='' PACKAGE_URL='' ac_subst_vars='LTLIBOBJS LIBOBJS OCTAVE_CLI HAVE_WINDOWS OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC crosscompiling target_os target_vendor target_cpu target host_os host_vendor host_cpu host build_os build_vendor build_cpu build target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir runstatedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -runstatedir | --runstatedir | --runstatedi | --runstated \ | --runstate | --runstat | --runsta | --runst | --runs \ | --run | --ru | --r) ac_prev=runstatedir ;; -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ | --run=* | --ru=* | --r=*) runstatedir=$ac_optarg ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures statistics 1.4.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/statistics] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] --target=TARGET configure for building compilers for TARGET [HOST] _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of statistics 1.4.1:";; esac cat <<\_ACEOF Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF statistics configure 1.4.1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by statistics $as_me 1.4.1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do if test -f "$ac_dir/install-sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install-sh -c" break elif test -f "$ac_dir/install.sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install.sh -c" break elif test -f "$ac_dir/shtool"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/shtool install -c" break fi done if test -z "$ac_aux_dir"; then as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 fi # These three variables are undocumented and unsupported, # and are intended to be withdrawn in a future Autoconf release. # They can cause serious problems if a builder's source tree is in a directory # whose full name contains unusual characters. ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. # Make sure we can run config.sub. $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 $as_echo_n "checking build system type... " >&6; } if ${ac_cv_build+:} false; then : $as_echo_n "(cached) " >&6 else ac_build_alias=$build_alias test "x$ac_build_alias" = x && ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` test "x$ac_build_alias" = x && as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 $as_echo "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; esac build=$ac_cv_build ac_save_IFS=$IFS; IFS='-' set x $ac_cv_build shift build_cpu=$1 build_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: build_os=$* IFS=$ac_save_IFS case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 $as_echo_n "checking host system type... " >&6; } if ${ac_cv_host+:} false; then : $as_echo_n "(cached) " >&6 else if test "x$host_alias" = x; then ac_cv_host=$ac_cv_build else ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 $as_echo "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; esac host=$ac_cv_host ac_save_IFS=$IFS; IFS='-' set x $ac_cv_host shift host_cpu=$1 host_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: host_os=$* IFS=$ac_save_IFS case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5 $as_echo_n "checking target system type... " >&6; } if ${ac_cv_target+:} false; then : $as_echo_n "(cached) " >&6 else if test "x$target_alias" = x; then ac_cv_target=$ac_cv_host else ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $target_alias failed" "$LINENO" 5 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_target" >&5 $as_echo "$ac_cv_target" >&6; } case $ac_cv_target in *-*-*) ;; *) as_fn_error $? "invalid value of canonical target" "$LINENO" 5;; esac target=$ac_cv_target ac_save_IFS=$IFS; IFS='-' set x $ac_cv_target shift target_cpu=$1 target_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: target_os=$* IFS=$ac_save_IFS case $target_os in *\ *) target_os=`echo "$target_os" | sed 's/ /-/g'`;; esac # The aliases save the names the user supplied, while $host etc. # will get canonicalized. test -n "$target_alias" && test "$program_prefix$program_suffix$program_transform_name" = \ NONENONEs,x,x, && program_prefix=${target_alias}- if test "x${build}" != "x${host}"; then crosscompiling=true else crosscompiling=false fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if ${ac_cv_c_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if ${ac_cv_prog_cc_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if ${ac_cv_prog_cc_c89+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu # Check for Windows { $as_echo "$as_me:${as_lineno-$LINENO}: checking for windows" >&5 $as_echo_n "checking for windows... " >&6; } have_windows=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #ifndef __WIN32__ #error "Not windows!" #endif int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } have_windows=yes else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext # if windows, we can build some of the packages just by having # windows.h if test $have_windows = yes; then HAVE_WINDOWS=1 # Extract the first word of "octave-cli", so it can be a program name with args. set dummy octave-cli; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCTAVE_CLI+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCTAVE_CLI"; then ac_cv_prog_OCTAVE_CLI="$OCTAVE_CLI" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCTAVE_CLI="octave-cli" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCTAVE_CLI=$ac_cv_prog_OCTAVE_CLI if test -n "$OCTAVE_CLI"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCTAVE_CLI" >&5 $as_echo "$OCTAVE_CLI" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi else HAVE_WINDOWS=0 fi ac_config_files="$ac_config_files Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. # # If the first sed substitution is executed (which looks for macros that # take arguments), then branch to the quote section. Otherwise, # look for a macro that doesn't take arguments. ac_script=' :mline /\\$/{ N s,\\\n,, b mline } t clear :clear s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g t quote s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g t quote b any :quote s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g s/\[/\\&/g s/\]/\\&/g s/\$/$$/g H :any ${ g s/^\n// s/\n/ /g p } ' DEFS=`sed -n "$ac_script" confdefs.h` ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by statistics $as_me 1.4.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE Configuration files: $config_files Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ statistics config.status 1.4.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --he | --h | --help | --hel | -h ) $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to `$tmp'. $debug || { tmp= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" eval set X " :F $CONFIG_FILES " shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 $as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when `$srcdir' = `.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi statistics-1.4.1/src/PaxHeaders.29769/install-sh0000644000000000000000000000006213443447555016274 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/src/install-sh0000755000175000017500000003452413443447555017016 0ustar00johndjohnd00000000000000#!/bin/sh # install - install a program, script, or datafile scriptversion=2016-01-11.22; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # 'make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. tab=' ' nl=' ' IFS=" $tab$nl" # Set DOITPROG to "echo" to test this script. doit=${DOITPROG-} doit_exec=${doit:-exec} # Put in absolute file names if you don't have them in your path; # or use environment vars. chgrpprog=${CHGRPPROG-chgrp} chmodprog=${CHMODPROG-chmod} chownprog=${CHOWNPROG-chown} cmpprog=${CMPPROG-cmp} cpprog=${CPPROG-cp} mkdirprog=${MKDIRPROG-mkdir} mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} posix_mkdir= # Desired mode of installed file. mode=0755 chgrpcmd= chmodcmd=$chmodprog chowncmd= mvcmd=$mvprog rmcmd="$rmprog -f" stripcmd= src= dst= dir_arg= dst_arg= copy_on_change=false is_target_a_directory=possibly usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --help display this help and exit. --version display version info and exit. -c (ignored) -C install only if different (preserve the last data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -s $stripprog installed files. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG " while test $# -ne 0; do case $1 in -c) ;; -C) copy_on_change=true;; -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 case $mode in *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac shift;; -o) chowncmd="$chownprog $2" shift;; -s) stripcmd=$stripprog;; -t) is_target_a_directory=always dst_arg=$2 # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac shift;; -T) is_target_a_directory=never;; --version) echo "$0 $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac shift done # We allow the use of options -d and -T together, by making -d # take the precedence; this is for compatibility with GNU install. if test -n "$dir_arg"; then if test -n "$dst_arg"; then echo "$0: target directory not allowed when installing a directory." >&2 exit 1 fi fi if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dst_arg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dst_arg" shift # fnord fi shift # arg dst_arg=$arg # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call 'install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then if test $# -gt 1 || test "$is_target_a_directory" = always; then if test ! -d "$dst_arg"; then echo "$0: $dst_arg: Is not a directory." >&2 exit 1 fi fi fi if test -z "$dir_arg"; then do_exit='(exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names problematic for 'test' and other utilities. case $src in -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dst_arg # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then if test "$is_target_a_directory" = never; then echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi dstdir=$dst dst=$dstdir/`basename "$src"` dstdir_status=0 else dstdir=`dirname "$dst"` test -d "$dstdir" dstdir_status=$? fi fi obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # Create intermediate dirs using mode 755 as modified by the umask. # This is like FreeBSD 'install' as of 1997-10-28. umask=`umask` case $stripcmd.$umask in # Optimize common cases. *[2367][2367]) mkdir_umask=$umask;; .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; *[0-7]) mkdir_umask=`expr $umask + 22 \ - $umask % 100 % 40 + $umask % 20 \ - $umask % 10 % 4 + $umask % 2 `;; *) mkdir_umask=$umask,go-w;; esac # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false case $umask in *[123567][0-7][0-7]) # POSIX mkdir -p sets u+wx bits regardless of umask, which # is incompatible with FreeBSD 'install' when (umask & 300) != 0. ;; *) tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 if (umask $mkdir_umask && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. ls_ld_tmpdir=`ls -ld "$tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/d" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null fi trap '' 0;; esac;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # The umask is ridiculous, or mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix='/';; [-=\(\)!]*) prefix='./';; *) prefix='';; esac oIFS=$IFS IFS=/ set -f set fnord $dstdir shift set +f IFS=$oIFS prefixes= for d do test X"$d" = X && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask=$mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ rmtmp=$dstdir/_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. { # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { test ! -f "$dst" || $doit $rmcmd -f "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: statistics-1.4.1/src/PaxHeaders.29769/Makefile.in0000644000000000000000000000006213443447555016340 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/src/Makefile.in0000644000175000017500000000370413443447555017053 0ustar00johndjohnd00000000000000## Makefile for statistics package for Octave ## ## Copyright (C) 2017 Olaf Till ## 2018 Oliver Heimlich ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 3 of the ## License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see ## . ## During pkg install, these will be provided by the calling Octave MKOCTFILE ?= mkoctfile OCTAVE_CONFIG ?= octave-config OCTAVE ?= octave HAVE_WINDOWS := @HAVE_WINDOWS@ ifeq ($(HAVE_WINDOWS),1) OCTAVE := @OCTAVE_CLI@ endif CP ?= cp cond_srcdir := ../install-conditionally instdir := ../inst testdir := ../test utilsdir := ../utils crosscompiling := @crosscompiling@ ## Octave function, contained in this package in the $(utilsdir) ## directory, for conditional installation cond_inst := conditional_installation .PHONY: all clean all: | $(instdir)/test $(CP) ../INDEX.in ../INDEX $(OCTAVE) \ --no-gui \ --silent \ --norc \ --eval 'addpath ("$(utilsdir)");' \ --eval '$(cond_inst) ("$(cond_srcdir)", "$(instdir)", $(crosscompiling), "../INDEX");' $(CP) $(testdir)/*.dat $(instdir)/test/ $(instdir)/test: @mkdir -p "$@" ## remove files corresponding to files under the directory for ## conditional installation clean: $(RM) `cd $(cond_srcdir) && find . -name '*.m' -printf '$(instdir)/%p '` -$(RM) `cd $(testdir) && find . -name '*.dat' -printf '$(instdir)/data/%p '` distclean: clean $(RM) config.log config.status maintainer-clean: distclean statistics-1.4.1/src/PaxHeaders.29769/configure.ac0000644000000000000000000000007413443447555016564 xustar0030 atime=1553013131.545849752 30 ctime=1553013131.677852968 statistics-1.4.1/src/configure.ac0000644000175000017500000000165613443447555017300 0ustar00johndjohnd00000000000000# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([statistics], [1.4.1]) AC_CANONICAL_TARGET if test "x${build}" != "x${host}"; then AC_SUBST([crosscompiling], [true]) else AC_SUBST([crosscompiling], [false]) fi AC_PROG_CC # Check for Windows AC_MSG_CHECKING([for windows]) have_windows=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include #ifndef __WIN32__ #error "Not windows!" #endif ]], [])], [AC_MSG_RESULT([yes]) have_windows=yes], [AC_MSG_RESULT([no])]) # if windows, we can build some of the packages just by having # windows.h if test $have_windows = yes; then AC_SUBST([HAVE_WINDOWS], [1], [build for windows target]) AC_CHECK_PROG(OCTAVE_CLI, octave-cli, octave-cli) else AC_SUBST([HAVE_WINDOWS], [0], [build for not a windows target]) fi AC_CONFIG_FILES([Makefile]) AC_OUTPUT statistics-1.4.1/src/PaxHeaders.29769/config.guess0000644000000000000000000000006213443447555016610 xustar0020 atime=1552830317 30 ctime=1553013131.677852968 statistics-1.4.1/src/config.guess0000755000175000017500000012564413443447555017336 0ustar00johndjohnd00000000000000#! /bin/sh # Attempt to guess a canonical system name. # Copyright 1992-2016 Free Software Foundation, Inc. timestamp='2016-10-02' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # # Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess # # Please send patches to . me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. Copyright 1992-2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; * ) break ;; esac done if test $# != 0; then echo "$me: too many arguments$help" >&2 exit 1 fi trap 'exit 1' 1 2 15 # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a # headache to deal with in a portable fashion. # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still # use `HOST_CC' if defined, but it is deprecated. # Portable tmp directory creation inspired by the Autoconf team. set_cc_for_build=' trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; : ${TMPDIR=/tmp} ; { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; dummy=$tmp/dummy ; tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; case $CC_FOR_BUILD,$HOST_CC,$CC in ,,) echo "int x;" > $dummy.c ; for c in cc gcc c89 c99 ; do if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then CC_FOR_BUILD="$c"; break ; fi ; done ; if test x"$CC_FOR_BUILD" = x ; then CC_FOR_BUILD=no_compiler_found ; fi ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; esac ; set_cc_for_build= ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) if (test -f /.attbin/uname) >/dev/null 2>&1 ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown case "${UNAME_SYSTEM}" in Linux|GNU|GNU/*) # If the system lacks a compiler, then just pick glibc. # We could probably try harder. LIBC=gnu eval $set_cc_for_build cat <<-EOF > $dummy.c #include #if defined(__UCLIBC__) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc #else LIBC=gnu #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` ;; esac # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward # compatibility and a consistent mechanism for selecting the # object file format. # # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". sysctl="sysctl -n hw.machine_arch" UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ /sbin/$sysctl 2>/dev/null || \ /usr/sbin/$sysctl 2>/dev/null || \ echo unknown)` case "${UNAME_MACHINE_ARCH}" in armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; earmv*) arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'` endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'` machine=${arch}${endian}-unknown ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently (or will in the future) and ABI. case "${UNAME_MACHINE_ARCH}" in earm*) os=netbsdelf ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) eval $set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). # Return netbsd for either. FIX? os=netbsd else os=netbsdelf fi ;; *) os=netbsd ;; esac # Determine ABI tags. case "${UNAME_MACHINE_ARCH}" in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"` ;; esac # The OS release # Debian GNU/NetBSD machines have a different userland, and # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. case "${UNAME_VERSION}" in Debian*) release='-gnu' ;; *) release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}${abi}" exit ;; *:Bitrig:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE} exit ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} exit ;; *:LibertyBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` echo ${UNAME_MACHINE_ARCH}-unknown-libertybsd${UNAME_RELEASE} exit ;; *:ekkoBSD:*:*) echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} exit ;; *:SolidBSD:*:*) echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} exit ;; macppc:MirBSD:*:*) echo powerpc-unknown-mirbsd${UNAME_RELEASE} exit ;; *:MirBSD:*:*) echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} exit ;; *:Sortix:*:*) echo ${UNAME_MACHINE}-unknown-sortix exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` ;; *5.*) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` case "$ALPHA_CPU_TYPE" in "EV4 (21064)") UNAME_MACHINE=alpha ;; "EV4.5 (21064)") UNAME_MACHINE=alpha ;; "LCA4 (21066/21068)") UNAME_MACHINE=alpha ;; "EV5 (21164)") UNAME_MACHINE=alphaev5 ;; "EV5.6 (21164A)") UNAME_MACHINE=alphaev56 ;; "EV5.6 (21164PC)") UNAME_MACHINE=alphapca56 ;; "EV5.7 (21164PC)") UNAME_MACHINE=alphapca57 ;; "EV6 (21264)") UNAME_MACHINE=alphaev6 ;; "EV6.7 (21264A)") UNAME_MACHINE=alphaev67 ;; "EV6.8CB (21264C)") UNAME_MACHINE=alphaev68 ;; "EV6.8AL (21264B)") UNAME_MACHINE=alphaev68 ;; "EV6.8CX (21264D)") UNAME_MACHINE=alphaev68 ;; "EV6.9A (21264/EV69A)") UNAME_MACHINE=alphaev69 ;; "EV7 (21364)") UNAME_MACHINE=alphaev7 ;; "EV7.9 (21364A)") UNAME_MACHINE=alphaev79 ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` # Reset EXIT trap before exiting to avoid spurious non-zero exit code. exitcode=$? trap '' 0 exit $exitcode ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead # of the specific Alpha model? echo alpha-pc-interix exit ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 exit ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 exit ;; *:[Aa]miga[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-amigaos exit ;; *:[Mm]orph[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-morphos exit ;; *:OS/390:*:*) echo i370-ibm-openedition exit ;; *:z/VM:*:*) echo s390-ibm-zvmoe exit ;; *:OS400:*:*) echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit ;; arm*:riscos:*:*|arm*:RISCOS:*:*) echo arm-unknown-riscos exit ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp exit ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then echo pyramid-pyramid-sysv3 else echo pyramid-pyramid-bsd fi exit ;; NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 exit ;; DRS?6000:unix:4.0:6*) echo sparc-icl-nx6 exit ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in sparc) echo sparc-icl-nx7; exit ;; esac ;; s390x:SunOS:*:*) echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) echo i386-pc-auroraux${UNAME_RELEASE} exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) eval $set_cc_for_build SUN_ARCH=i386 # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. if [ "$CC_FOR_BUILD" != no_compiler_found ]; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then SUN_ARCH=x86_64 fi fi echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:*:*) case "`/usr/bin/arch -k`" in Series*|S4*) UNAME_RELEASE=`uname -v` ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` exit ;; sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x${UNAME_RELEASE}" = x && UNAME_RELEASE=3 case "`/bin/arch`" in sun3) echo m68k-sun-sunos${UNAME_RELEASE} ;; sun4) echo sparc-sun-sunos${UNAME_RELEASE} ;; esac exit ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} exit ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor # > m68000). The system name ranges from "MiNT" over "FreeMiNT" # to the lowercase version "mint" (or "freemint"). Finally # the system name "TOS" denotes a system which is actually not # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) echo m68k-milan-mint${UNAME_RELEASE} exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) echo m68k-hades-mint${UNAME_RELEASE} exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) echo m68k-unknown-mint${UNAME_RELEASE} exit ;; m68k:machten:*:*) echo m68k-apple-machten${UNAME_RELEASE} exit ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit ;; RISC*:ULTRIX:*:*) echo mips-dec-ultrix${UNAME_RELEASE} exit ;; VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix${UNAME_RELEASE} exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { #else int main (argc, argv) int argc; char *argv[]; { #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF $CC_FOR_BUILD -o $dummy $dummy.c && dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && SYSTEM_NAME=`$dummy $dummyarg` && { echo "$SYSTEM_NAME"; exit; } echo mips-mips-riscos${UNAME_RELEASE} exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax exit ;; Motorola:*:4.3:PL8-*) echo powerpc-harris-powermax exit ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) echo powerpc-harris-powermax exit ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix exit ;; m88k:CX/UX:7*:*) echo m88k-harris-cxux7 exit ;; m88k:*:4*:R4*) echo m88k-motorola-sysv4 exit ;; m88k:*:3*:R3*) echo m88k-motorola-sysv3 exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] then if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ [ ${TARGET_BINARY_INTERFACE}x = x ] then echo m88k-dg-dgux${UNAME_RELEASE} else echo m88k-dg-dguxbcs${UNAME_RELEASE} fi else echo i586-dg-dgux${UNAME_RELEASE} fi exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 exit ;; M88*:*:R3*:*) # Delta 88k system running SVR3 echo m88k-motorola-sysv3 exit ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) echo m88k-tektronix-sysv3 exit ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix exit ;; ia64:AIX:*:*) if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} exit ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #include main() { if (!__power_pc()) exit(1); puts("powerpc-ibm-aix3.2.5"); exit(0); } EOF if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` then echo "$SYSTEM_NAME" else echo rs6000-ibm-aix3.2.5 fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 else echo rs6000-ibm-aix3.2 fi exit ;; *:AIX:*:[4567]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi if [ -x /usr/bin/lslpp ] ; then IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` else IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} exit ;; *:AIX:*:*) echo rs6000-ibm-aix exit ;; ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 exit ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx exit ;; DPX/2?00:B.O.S.:*:*) echo m68k-bull-sysv3 exit ;; 9000/[34]??:4.3bsd:1.*:*) echo m68k-hp-bsd exit ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 exit ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in 9000/31? ) HP_ARCH=m68000 ;; 9000/[34]?? ) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) if [ -x /usr/bin/getconf ]; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` case "${sc_cpu_version}" in 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 case "${sc_kernel_bits}" in 32) HP_ARCH=hppa2.0n ;; 64) HP_ARCH=hppa2.0w ;; '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 esac ;; esac fi if [ "${HP_ARCH}" = "" ]; then eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #define _HPUX_SOURCE #include #include int main () { #if defined(_SC_KERNEL_BITS) long bits = sysconf(_SC_KERNEL_BITS); #endif long cpu = sysconf (_SC_CPU_VERSION); switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0"); break; case CPU_PA_RISC1_1: puts ("hppa1.1"); break; case CPU_PA_RISC2_0: #if defined(_SC_KERNEL_BITS) switch (bits) { case 64: puts ("hppa2.0w"); break; case 32: puts ("hppa2.0n"); break; default: puts ("hppa2.0"); break; } break; #else /* !defined(_SC_KERNEL_BITS) */ puts ("hppa2.0"); break; #endif default: puts ("hppa1.0"); break; } exit (0); } EOF (CCOPTS="" $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac if [ ${HP_ARCH} = hppa2.0w ] then eval $set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler # generating 64-bit code. GNU and HP use different nomenclature: # # $ CC_FOR_BUILD=cc ./config.guess # => hppa2.0w-hp-hpux11.23 # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then HP_ARCH=hppa2.0w else HP_ARCH=hppa64 fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} exit ;; ia64:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ia64-hp-hpux${HPUX_REV} exit ;; 3050*:HI-UX:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #include int main () { long cpu = sysconf (_SC_CPU_VERSION); /* The order matters, because CPU_IS_HP_MC68K erroneously returns true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct results, however. */ if (CPU_IS_PA_RISC (cpu)) { switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; default: puts ("hppa-hitachi-hiuxwe2"); break; } } else if (CPU_IS_HP_MC68K (cpu)) puts ("m68k-hitachi-hiuxwe2"); else puts ("unknown-hitachi-hiuxwe2"); exit (0); } EOF $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 exit ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) echo hppa1.1-hp-bsd exit ;; 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd exit ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix exit ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf exit ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf exit ;; i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else echo ${UNAME_MACHINE}-unknown-osf1 fi exit ;; parisc*:Lites*:*:*) echo hppa1.1-hp-lites exit ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd exit ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd exit ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd exit ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd exit ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*T3E:*:*:*) echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*SV1:*:*:*) echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; *:UNICOS/mp:*:*) echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} exit ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi${UNAME_RELEASE} exit ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit ;; *:FreeBSD:*:*) UNAME_PROCESSOR=`/usr/bin/uname -p` case ${UNAME_PROCESSOR} in amd64) echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; *) echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; esac exit ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin exit ;; *:MINGW64*:*) echo ${UNAME_MACHINE}-pc-mingw64 exit ;; *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; *:MSYS*:*) echo ${UNAME_MACHINE}-pc-msys exit ;; i*:windows32*:*) # uname -m includes "-pc" on this system. echo ${UNAME_MACHINE}-mingw32 exit ;; i*:PW*:*) echo ${UNAME_MACHINE}-pc-pw32 exit ;; *:Interix*:*) case ${UNAME_MACHINE} in x86) echo i586-pc-interix${UNAME_RELEASE} exit ;; authenticamd | genuineintel | EM64T) echo x86_64-unknown-interix${UNAME_RELEASE} exit ;; IA64) echo ia64-unknown-interix${UNAME_RELEASE} exit ;; esac ;; [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) echo i${UNAME_MACHINE}-pc-mks exit ;; 8664:Windows_NT:*) echo x86_64-pc-mks exit ;; i*:Windows_NT*:* | Pentium*:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we # UNAME_MACHINE based on the output of uname instead of i386? echo i586-pc-interix exit ;; i*:UWIN*:*) echo ${UNAME_MACHINE}-pc-uwin exit ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) echo x86_64-unknown-cygwin exit ;; p*:CYGWIN*:*) echo powerpcle-unknown-cygwin exit ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; *:GNU:*:*) # the GNU system echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} exit ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix exit ;; aarch64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; PCA57) UNAME_MACHINE=alphapca56 ;; EV6) UNAME_MACHINE=alphaev6 ;; EV67) UNAME_MACHINE=alphaev67 ;; EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; arc:Linux:*:* | arceb:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; arm*:Linux:*:*) eval $set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then echo ${UNAME_MACHINE}-unknown-linux-${LIBC} else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi else echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf fi fi exit ;; avr32*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; cris:Linux:*:*) echo ${UNAME_MACHINE}-axis-linux-${LIBC} exit ;; crisv32:Linux:*:*) echo ${UNAME_MACHINE}-axis-linux-${LIBC} exit ;; e2k:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; frv:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; hexagon:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; i*86:Linux:*:*) echo ${UNAME_MACHINE}-pc-linux-${LIBC} exit ;; ia64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; k1om:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; m32r*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; mips:Linux:*:* | mips64:Linux:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #undef CPU #undef ${UNAME_MACHINE} #undef ${UNAME_MACHINE}el #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) CPU=${UNAME_MACHINE}el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) CPU=${UNAME_MACHINE} #else CPU= #endif #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } ;; mips64el:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; openrisc*:Linux:*:*) echo or1k-unknown-linux-${LIBC} exit ;; or32:Linux:*:* | or1k*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; padre:Linux:*:*) echo sparc-unknown-linux-${LIBC} exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) echo hppa64-unknown-linux-${LIBC} exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in PA7*) echo hppa1.1-unknown-linux-${LIBC} ;; PA8*) echo hppa2.0-unknown-linux-${LIBC} ;; *) echo hppa-unknown-linux-${LIBC} ;; esac exit ;; ppc64:Linux:*:*) echo powerpc64-unknown-linux-${LIBC} exit ;; ppc:Linux:*:*) echo powerpc-unknown-linux-${LIBC} exit ;; ppc64le:Linux:*:*) echo powerpc64le-unknown-linux-${LIBC} exit ;; ppcle:Linux:*:*) echo powerpcle-unknown-linux-${LIBC} exit ;; riscv32:Linux:*:* | riscv64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; s390:Linux:*:* | s390x:Linux:*:*) echo ${UNAME_MACHINE}-ibm-linux-${LIBC} exit ;; sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; sh*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; tile*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; vax:Linux:*:*) echo ${UNAME_MACHINE}-dec-linux-${LIBC} exit ;; x86_64:Linux:*:*) echo ${UNAME_MACHINE}-pc-linux-${LIBC} exit ;; xtensa*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. echo i386-sequent-sysv4 exit ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} exit ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo ${UNAME_MACHINE}-pc-os2-emx exit ;; i*86:XTS-300:*:STOP) echo ${UNAME_MACHINE}-unknown-stop exit ;; i*86:atheos:*:*) echo ${UNAME_MACHINE}-unknown-atheos exit ;; i*86:syllable:*:*) echo ${UNAME_MACHINE}-pc-syllable exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) echo i386-unknown-lynxos${UNAME_RELEASE} exit ;; i*86:*DOS:*:*) echo ${UNAME_MACHINE}-pc-msdosdjgpp exit ;; i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} else echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi exit ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 echo ${UNAME_MACHINE}-pc-sco$UNAME_REL else echo ${UNAME_MACHINE}-pc-sysv32 fi exit ;; pc:*:*:*) # Left here for compatibility: # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub # prints for the "djgpp" host, or else GDB configure will decide that # this is a cross-build. echo i586-pc-msdosdjgpp exit ;; Intel:Mach:3*:*) echo i386-pc-mach3 exit ;; paragon:*:*:*) echo i860-intel-osf1 exit ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 fi exit ;; mini*:CTIX:SYS*5:*) # "miniframe" echo m68010-convergent-sysv exit ;; mc68k:UNIX:SYSTEM5:3.51m) echo m68k-convergent-sysv exit ;; M680?0:D-NIX:5.3:*) echo m68k-diab-dnix exit ;; M68*:*:R3V[5678]*:*) test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4; exit; } ;; NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} exit ;; rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) echo powerpc-unknown-lynxos${UNAME_RELEASE} exit ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 exit ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` echo ${UNAME_MACHINE}-sni-sysv4 else echo ns32k-sni-sysv fi exit ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says echo i586-unisys-sysv4 exit ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm echo hppa1.1-stratus-sysv4 exit ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 exit ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. echo ${UNAME_MACHINE}-stratus-vos exit ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos exit ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} exit ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos exit ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. echo powerpc-apple-beos exit ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos exit ;; BePC:Haiku:*:*) # Haiku running on Intel PC compatible. echo i586-pc-haiku exit ;; x86_64:Haiku:*:*) echo x86_64-unknown-haiku exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} exit ;; SX-5:SUPER-UX:*:*) echo sx5-nec-superux${UNAME_RELEASE} exit ;; SX-6:SUPER-UX:*:*) echo sx6-nec-superux${UNAME_RELEASE} exit ;; SX-7:SUPER-UX:*:*) echo sx7-nec-superux${UNAME_RELEASE} exit ;; SX-8:SUPER-UX:*:*) echo sx8-nec-superux${UNAME_RELEASE} exit ;; SX-8R:SUPER-UX:*:*) echo sx8r-nec-superux${UNAME_RELEASE} exit ;; SX-ACE:SUPER-UX:*:*) echo sxace-nec-superux${UNAME_RELEASE} exit ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} exit ;; *:Rhapsody:*:*) echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} exit ;; *:Darwin:*:*) UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown eval $set_cc_for_build if test "$UNAME_PROCESSOR" = unknown ; then UNAME_PROCESSOR=powerpc fi if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then if [ "$CC_FOR_BUILD" != no_compiler_found ]; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then case $UNAME_PROCESSOR in i386) UNAME_PROCESSOR=x86_64 ;; powerpc) UNAME_PROCESSOR=powerpc64 ;; esac fi fi elif test "$UNAME_PROCESSOR" = i386 ; then # Avoid executing cc on OS X 10.9, as it ships with a stub # that puts up a graphical alert prompting to install # developer tools. Any system running Mac OS X 10.7 or # later (Darwin 11 and later) is required to have a 64-bit # processor. This is not true of the ARM version of Darwin # that Apple uses in portable devices. UNAME_PROCESSOR=x86_64 fi echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = x86; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} exit ;; *:QNX:*:4*) echo i386-pc-qnx exit ;; NEO-?:NONSTOP_KERNEL:*:*) echo neo-tandem-nsk${UNAME_RELEASE} exit ;; NSE-*:NONSTOP_KERNEL:*:*) echo nse-tandem-nsk${UNAME_RELEASE} exit ;; NSR-?:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux exit ;; BS2000:POSIX*:*:*) echo bs2000-siemens-sysv exit ;; DS/*:UNIX_System_V:*:*) echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} exit ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. if test "$cputype" = 386; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" fi echo ${UNAME_MACHINE}-unknown-plan9 exit ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 exit ;; *:TENEX:*:*) echo pdp10-unknown-tenex exit ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 exit ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) echo pdp10-xkl-tops20 exit ;; *:TOPS-20:*:*) echo pdp10-unknown-tops20 exit ;; *:ITS:*:*) echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) echo mips-sei-seiux${UNAME_RELEASE} exit ;; *:DragonFly:*:*) echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit ;; *:*VMS:*:*) UNAME_MACHINE=`(uname -p) 2>/dev/null` case "${UNAME_MACHINE}" in A*) echo alpha-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;; V*) echo vax-dec-vms ; exit ;; esac ;; *:XENIX:*:SysV) echo i386-pc-xenix exit ;; i*86:skyos:*:*) echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE} | sed -e 's/ .*$//'` exit ;; i*86:rdos:*:*) echo ${UNAME_MACHINE}-pc-rdos exit ;; i*86:AROS:*:*) echo ${UNAME_MACHINE}-pc-aros exit ;; x86_64:VMkernel:*:*) echo ${UNAME_MACHINE}-unknown-esx exit ;; amd64:Isilon\ OneFS:*:*) echo x86_64-unknown-onefs exit ;; esac cat >&2 </dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` /bin/uname -X = `(/bin/uname -X) 2>/dev/null` hostinfo = `(hostinfo) 2>/dev/null` /bin/universe = `(/bin/universe) 2>/dev/null` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` /bin/arch = `(/bin/arch) 2>/dev/null` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` UNAME_MACHINE = ${UNAME_MACHINE} UNAME_RELEASE = ${UNAME_RELEASE} UNAME_SYSTEM = ${UNAME_SYSTEM} UNAME_VERSION = ${UNAME_VERSION} EOF exit 1 # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: statistics-1.4.1/src/PaxHeaders.29769/bootstrap0000644000000000000000000000007413443447555016236 xustar0030 atime=1553013131.345844879 30 ctime=1553013131.681853066 statistics-1.4.1/src/bootstrap0000755000175000017500000000001113443447555016735 0ustar00johndjohnd00000000000000autoconf statistics-1.4.1/PaxHeaders.29769/NEWS0000644000000000000000000000006213443447555014203 xustar0020 atime=1552830317 30 ctime=1553013131.681853066 statistics-1.4.1/NEWS0000644000175000017500000002235013443447555014714 0ustar00johndjohnd00000000000000Summary of important user-visible changes for statistics 1.4.1: ------------------------------------------------------------------- ** update install scripts for octave 5.0 depreciated functions ** bug fixes to the following functions: pdist2.m: use max in distEucSq (Bug #50377) normpdf: use eps tolerance in tests (Bug #51963) fitgmdist: fix an output bug in fitgmdist t_test: Set tolerance on t_test BISTS (Bug #54557) gpXXXXX: change order of inputs to match matlab (Bug #54009) bartlett_test: df = k-1 (Bug #45894) gppdf: apply scale factor (Bug #54009) gmdistribution: updates for bug #54278, ##54279 wishrnd: Bug #55860 Summary of important user-visible changes for statistics 1.4.0: ------------------------------------------------------------------- ** The following functions are new: canoncorr fitgmdist gmdistribution sigma_pts ** The following functions have been moved from the statistics package but are conditionally installed: mad ** The following functions have been moved from octave to be conditionally installed: BASE cloglog logit prctile probit qqplot table (renamed to crosstab) DISTRIBUTIONS betacdf betainv betapdf betarnd binocdf binoinv binopdf binornd cauchy_cdf cauchy_inv cauchy_pdf cauchy_rnd chi2cdf chi2inv chi2pdf chi2rnd expcdf expinv exppdf exprnd fcdf finv fpdf frnd gamcdf gaminv gampdf gamrnd geocdf geoinv geopdf geornd hygecdf hygeinv hygepdf hygernd kolmogorov_smirnov_cdf laplace_cdf laplace_inv laplace_pdf laplace_rnd logistic_cdf logistic_inv logistic_pdf logistic_rnd logncdf logninv lognpdf lognrnd nbincdf nbininv nbinpdf nbinrnd normcdf norminv normpdf normrnd poisscdf poissinv poisspdf poissrnd stdnormal_cdf stdnormal_inv stdnormal_pdf stdnormal_rnd tcdf tinv tpdf trnd unidcdf unidinv unidpdf unidrnd unifcdf unifinv unifpdf unifrnd wblcdf wblinv wblpdf wblrnd wienrnd MODELS logistic_regression TESTS anova bartlett_test chisquare_test_homogeneity chisquare_test_independence cor_test f_test_regression hotelling_test hotelling_test_2 kolmogorov_smirnov_test kolmogorov_smirnov_test_2 kruskal_wallis_test manova mcnemar_test prop_test_2 run_test sign_test t_test t_test_2 t_test_regression u_test var_test welch_test wilcoxon_test z_test z_test_2 ** Functions marked with known test failures: grp2idx: bug #51928 gevfir_lmom: bug #31070 ** Other functions that have been changed for smaller bugfixes, increased Matlab compatibility, or performance: dcov: returned dcov instead of dcor. added demo. violin: can be used with subplots. violin quality improved. princomp: Fix expected values of tsquare in unit tests fitgmdist: test number inputs to function hist3: fix removal of rows with NaN values ** added the packages test data to install Summary of important user-visible changes for statistics 1.3.0: ------------------------------------------------------------------- ** The following functions are new: bbscdf bbsinv bbspdf bbsrnd binotest burrcdf burrinv burrpdf burrrnd gpcdf gpinv gppdf gprnd grp2idx mahal mvtpdf nakacdf nakainv nakapdf nakarnd pdf tricdf triinv tripdf trirnd violin ** Other functions that have been changed for smaller bugfixes, increased Matlab compatibility, or performance: betastat binostat cdf combnk gevfit hist3 kmeans linkage randsample squareform ttest Summary of important user-visible changes for statistics 1.2.4: ------------------------------------------------------------------- ** Made princomp work with nargout < 2. ** Renamed dendogram to dendrogram. ** Added isempty check to kmeans. ** Transposed output of hist3. ** Converted calculation in hmmviterbi to log space. ** Bug fixes for stepwisefit wishrnd. ** Rewrite of cmdscale for improved compatibility. ** Fix in squareform for improved compatibility. ** New cvpartition class, with methods: display repartition test training ** New sample data file fisheriris.txt for tests ** The following functions are new: cdf crossval dcov pdist2 qrandn randsample signtest ttest ttest2 vartest vartest2 ztest Summary of important user-visible changes for statistics 1.2.3: ------------------------------------------------------------------- ** Made sure that output of nanstd is real. ** Fixed second output of nanmax and nanmin. ** Corrected handle for outliers in boxplot. ** Bug fix and enhanced functionality for mvnrnd. ** The following functions are new: wishrnd iwishrnd wishpdf iwishpdf cmdscale Summary of important user-visible changes for statistics 1.2.2: ------------------------------------------------------------------- ** Fixed documentation of dendogram and hist3 to work with TexInfo 5. Summary of important user-visible changes for statistics 1.2.1: ------------------------------------------------------------------- ** The following functions are new: pcares pcacov runstest stepwisefit hist3 ** dendogram now returns the leaf node numbers and order that the nodes were displayed in. ** New faster implementation of princomp. Summary of important user-visible changes for statistics 1.2.0: ------------------------------------------------------------------- ** The following functions are new: regress_gp dendogram plsregress ** New functions for the generalized extreme value (GEV) distribution: gevcdf gevfit gevfit_lmom gevinv gevlike gevpdf gevrnd gevstat ** The interface of the following functions has been modified: mvnrnd ** `kmeans' has been fixed to deal with clusters that contain only one element. ** `normplot' has been fixed to avoid use of functions that have been removed from Octave core. Also, the plot produced should now display some aesthetic elements and appropriate legends. ** The help text of `mvtrnd' has been improved. ** Package is no longer autoloaded. Summary of important user-visible changes for statistics 1.1.3: ------------------------------------------------------------------- ** The following functions are new in 1.1.3: copularnd mvtrnd ** The functions mnpdf and mnrnd are now also usable for greater numbers of categories for which the rows do not exactly sum to 1. Summary of important user-visible changes for statistics 1.1.2: ------------------------------------------------------------------- ** The following functions are new in 1.1.2: mnpdf mnrnd ** The package is now dependent on the io package (version 1.0.18 or later) since the functions that it depended of from miscellaneous package have been moved to io. ** The function `kmeans' now accepts the 'emptyaction' property with the 'singleton' value. This allows for the kmeans algorithm to handle empty cluster better. It also throws an error if the user does not request an empty cluster handling, and there is an empty cluster. Plus, the returned items are now a closer match to Matlab. Summary of important user-visible changes for statistics 1.1.1: ------------------------------------------------------------------- ** The following functions are new in 1.1.1: monotone_smooth kmeans jackknife ** Bug fixes on the functions: normalise_distribution combnk repanova ** The following functions were removed since equivalents are now part of GNU octave core: zscore ** boxplot.m now returns a structure with handles to the plot elemenets. Summary of important user-visible changes for statistics 1.1.0: ------------------------------------------------------------------- ** IMPORTANT note about `fstat' shadowing core library function: GNU octave's 3.2 release added a new function `fstat' to return information of a file. Statistics' `fstat' computes F mean and variance. Since MatLab's `fstat' is the equivalent to statistics' `fstat' (not to core's `fstat'), and to avoid problems with the statistics package, `fstat' has been deprecated in octave 3.4 and will be removed in Octave 3.8. In the mean time, please ignore this warning when installing the package. ** The following functions are new in 1.1.0: normalise_distribution repanova combnk ** The following functions were removed since equivalents are now part of GNU octave core: prctile ** The __tbl_delim__ function is now private. ** The function `boxplot' now accepts named arguments. ** Bug fixes on the functions: harmmean nanmax nanmin regress ** Small improvements on help text. statistics-1.4.1/PaxHeaders.29769/PKG_ADD0000644000000000000000000000006213443447555014520 xustar0020 atime=1552830317 30 ctime=1553013131.681853066 statistics-1.4.1/PKG_ADD0000644000175000017500000000145413443447555015233 0ustar00johndjohnd00000000000000## three problems: ## - the directory returned by 'mfilename' must not be added also ## (endless loop) ## - 'genpath' of Octave 4.0 includes directories indiscriminately, ## e.g. 'private' directories ## - PKG_ADD (and PKG_DEL?) is run during installation, too, from the ## root directory of the package, where no such subdirectories ## exist. if exist ("isfolder") == 0 if (isdir (fullfile (fileparts (mfilename ("fullpath")), "base"))) addpath (fullfile (fileparts (mfilename ("fullpath")), {"base", "distributions", "models", "tests"}){:}); endif else if (isfolder (fullfile (fileparts (mfilename ("fullpath")), "base"))) addpath (fullfile (fileparts (mfilename ("fullpath")), {"base", "distributions", "models", "tests"}){:}); endif endif