/usr/share/octave/packages/statistics-1.3.0/pcacov.m is in octave-statistics 1.3.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | ## Copyright (C) 2013 Fernando Damian Nieuwveldt <fdnieuwveldt@gmail.com>
##
## 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 <http://www.gnu.org/licenses/>.
## -*- 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})
## @itemize @bullet
## @item
## pcacov performs principal component analysis on the nxn covariance matrix X
## @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 <fdnieuwveldt@gmail.com>
## 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)
|