Skip to content
Snippets Groups Projects
Select Git revision
  • 9d01b17e03b35199c1b82a0e9edeffd8ae23fc4c
  • master default
  • fcst_shock_decomp
  • 4.5
  • clang+openmp
  • local_state_space_iteration_k
  • dynamic-striated
  • occbin
  • exo_steady_state
  • filter_initial_state
  • declare_vars_in_model_block
  • exceptions
  • rmExtraExo
  • julia
  • error_msg_undeclared_model_vars
  • static_aux_vars
  • slice
  • aux_func
  • penalty
  • 4.4
  • separateM_
  • 4.5.7
  • 4.5.6
  • 4.5.5
  • 4.5.4
  • 4.5.3
  • 4.5.2
  • 4.5.1
  • 4.5.0
  • 4.4.3
  • 4.4.2
  • 4.4.1
  • 4.4.0
  • 4.4-beta1
  • 4.3.3
  • 4.3.2
  • 4.3.1
  • 4.3.0
  • 4.2.5
  • 4.2.4
  • 4.2.3
41 results

corr.m

Blame
  • Forked from Dynare / dynare
    Source project has a limited visibility.
    corr.m 4.62 KiB
    function retval = corr(x, y) % --*-- Unitary tests --*--
    %@info:
    %! @deftypefn  {Function File} {} corr (@var{x})
    %! @deftypefnx {Function File} {} corr (@var{x}, @var{y})
    %! Compute matrix of correlation coefficients.
    %! @anchor{corr}
    %!
    %! 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 (x,y) = cov (x,y) / (std (x) * std (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}.
    %! @end deftypefn
    %@eod:
    %
    % Notes:    - the original Octave code has been rewritten to avoid calling cov, since
    %               there is a long-standing incompatiblity between Matlab's cov and Octave's cov
    %               (see https://savannah.gnu.org/bugs/?40751)
    %           - For compatibility with Matlab, the correlation of a constant
    %               is defined as NaN, not 1
    %
    % Adapted for Matlab (R) from GNU Octave 4.0.1
    % Original files: statistics\base\corr.m, statistics\base\cov.m, and packages\stk-2.3.4\misc\mole\corr\corr.m
    % Original authors: Kurt Hornik <hornik@wu-wien.ac.at> and Julien Bect  <julien.bect@supelec.fr>
    
    % Copyright (C) 1993-1996 Kurt Hornik
    % Copyright (C) 1996-2015 John W. Eaton
    % Copyright (C) 2013-2015 Julien Bect
    % Copyright (C) 2016-2017 Dynare Team
    %
    % This file is part of Dynare.
    %
    % Dynare 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.
    %
    % Dynare 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 Dynare.  If not, see <http://www.gnu.org/licenses/>.
    
    
    if (nargin < 1 || nargin > 2)
        error('corr needs to be called with 1 or 2 input arguments')
    end
    
    % Input validation
    if (nargin==1 && ~(isnumeric (x) || islogical (x))) || ...
               (nargin==2 && ~(isnumeric (x) || islogical (x) || isnumeric (y) || islogical (y)))
        error ('corr: X and Y must be numeric matrices or vectors');
    end
    
    if (nargin==1 && ~ismatrix(x)) || (nargin==2 && (~ismatrix(y) || ~ismatrix(x)))