Skip to content

Commit

Permalink
Merge pull request #95 from marikap00/master
Browse files Browse the repository at this point in the history
fixed some typos.
  • Loading branch information
AldoCorbelliniUNIPR authored Nov 29, 2024
2 parents 35585c3 + c38f2b9 commit 2c44f82
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 128 deletions.
56 changes: 28 additions & 28 deletions toolbox/multivariate/barnardtest.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
%
% N : Contingency table (default) or n-by-2 input dataset.
% Matrix or Table.
% Matrix or table which contains the input contingency
% Matrix or table that contains the input contingency
% table (say of size I-by-J) or the original data matrix.
% In this last case N=crosstab(N(:,1),N(:,2)). As default
% procedure assumes that the input is a contingency table.
Expand All @@ -23,17 +23,17 @@
%
% resolution: The resolution of the search space for the nuisance
% parameter.
% Scalar. Small number which defines the resolution. See the
% More About section for more details.
% Scalar. Small number that defines the resolution. See the
% "More About" section for more details.
% The default value of the resolution is 0.001.
% Example - 'resolution',0.01
% Data Types - single | double
%
% datamatrix : Data matrix or contingency table. Boolean.
% If datamatrix is true the first input argument N is forced
% to be interpreted as a data matrix, else if the input
% argument is false N is treated as a contingency table. The
% default value of datamatrix is false, that is the procedure
% datamatrix: Data matrix or contingency table. Boolean.
% If datamatrix is true, the first input argument N is forced
% to be interpreted as a data matrix; otherwise if the input
% argument is false, N is treated as a contingency table. The
% default value of datamatrix is false; that is, the procedure
% automatically considers N as a contingency table.
% Example - 'datamatrix',true
% Data Types - logical
Expand All @@ -42,7 +42,7 @@
% Output:
%
% pval: p-value of the test. Scalar.
% pval is the p-value, i.e. the probability of
% pval is the p-value, i.e., represents the probability of
% observing the given result, or one more extreme, by
% chance if the null hypothesis of independence between
% rows and columns is true. Small values of pval cast doubt
Expand Down Expand Up @@ -70,7 +70,7 @@
%
% Barnard's test considers all tables with category sizes $c_1$ and $c_2$ for a
% given $p$. The p-value is the sum of probabilities of the tables having a
% score in the rejection region, e.g. having significantly large difference
% score in the rejection region, e.g., having a significantly large difference
% in proportions for a two-sided test. The p-value of the test is the
% maximum p-value calculated over all $p$ between 0 and 1. The input
% resolution parameter controls the resolution to search for.
Expand Down Expand Up @@ -123,19 +123,19 @@

%{
%% Barnard test with all the default options.
% N= 2x2 Input contingency table
% N= 2x2 Input contingency table.
N=[8,14; 1,3];
pval=barnardtest(N);
disp(['The p-value of the test is: ' num2str(pval)])
%}

%{
%% Resolution option.
% N= 2x2 Input contingency table
% N= 2x2 Input contingency table.
N=[20,14; 10,13];
% pvalue with the default resolution (0.001)
% p-value with the default resolution (0.001).
pval001=barnardtest(N);
% p value with a resolution of 0.01
% p-value with a resolution of 0.01.
pval01=barnardtest(N,'resolution',0.01);
disp(['The p-value with a resolution 0.01 is: ' num2str(pval01)])
disp(['The p-value a resolution 0.001 is: ' num2str(pval001)])
Expand All @@ -158,9 +158,9 @@
%{
% An example when the input is a datamatrix.
N=[40,14;10,30];
% Recreate the orginal data matrix
% Recreate the original data matrix.
X=crosstab2datamatrix(N);
% barnardtest when input is a datamatrix
% barnardtest when input is a datamatrix.
pval=barnardtest(X,'datamatrix',true);
%}

Expand All @@ -171,20 +171,20 @@
pval=barnardtest(N);
% our p-value is 0.456054
% This value coincides with the R implementation (package barnard)
% based on a C routine. On the other hand the vectorized implementation
% of Barnard test http://www.mathworks.com/matlabcentral/fileexchange/25760
% called using mybarnard(N,1000) gives a p-value of 0.456051
% based on a C routine. On the other hand, the vectorized implementation
% of the Barnard test http://www.mathworks.com/matlabcentral/fileexchange/25760
% called using mybarnard(N,1000) gives a p-value of 0.456051.
%}


%% Beginning of code

% Check MATLAB version. If it is not smaller than 2013b than output is
% shown in table format
% shown in table format.
verMatlab=verLessThan('matlab','8.2.0');

% Check whether N is a contingency table or a n-by-p input dataset (in this
% last case the contingency table is built using the first two columns of the
% last case, the contingency table is built using the first two columns of the
% input dataset).
if ~isempty(varargin)
[varargin{:}] = convertStringsToChars(varargin{:});
Expand All @@ -200,12 +200,12 @@
end

% If input is a datamatrix it is necessary to construct the contingency
% table
% table.
if datamatrix == true
N =crosstab(N(:,1),N(:,2));
end

% 1. The deafault resolution of the search space.
% 1. The default resolution of the search space.
resolution=0.001;

[varargin{:}] = convertStringsToChars(varargin{:});
Expand All @@ -216,15 +216,15 @@

UserOptions=varargin(1:2:length(varargin));
if ~isempty(UserOptions)
% Check if number of supplied options is valid
% Check if number of supplied options is valid.
if length(varargin) ~= 2*length(UserOptions)
error('FSDA:barnardtest:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.');
end
% Check if user options are valid options
% Check if user options are valid options.
aux.chkoptions(options,UserOptions)
end

% Write in structure 'options' the options chosen by the user
% Write in structure 'options' the options chosen by the user.
if nargin > 2
for i=1:2:length(varargin)
options.(varargin{i})=varargin{i+1};
Expand All @@ -233,7 +233,7 @@
resolution=options.resolution;
end

% transform table in array
% transform table in array.
if verMatlab ==0 && istable(N)
N=table2array(N);
end
Expand Down Expand Up @@ -304,7 +304,7 @@

for i = 0:c1

% The loop below is replaced by a series of vectorized instructions
% The loop below is replaced by a series of vectorized instructions.
% for j = 0:c2
% if p>0
% S(rI) = exp(F1(end)-F1(end-i)-F1(i+1)+ F2(end)-F2(end-j)-F2(j+1) +(i+j)*log(p)+(C-(i+j))*log(1-p));
Expand Down
144 changes: 72 additions & 72 deletions toolbox/multivariate/biplotFS.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function biplotFS(Y,varargin)
%biplotFS calls biplotAPP.mlapp to show a dynamic biplot
%biplotFS calls biplotAPP.mlapp to show a dynamic biplot.
%
%<a href="matlab: docsearchFS('biplotFS')">Link to the help function</a>
%
Expand All @@ -13,8 +13,8 @@ function biplotFS(Y,varargin)
% \]
% where $U_{(2)}$ is $n \times 2$ matrix (first two columns of $U$)
% and $V_{(2)}$ is $p \times 2$ (first two columns of matrix $V$,
% $\Gamma_{(2)}^*$ is a $2 \times 2$ diagonal matrix
% which contains the frist two largest singular values of matrix $Z$
% $\Gamma_{(2)}^*$ is a $2 \times 2$ diagonal matrix,
% which contains the first two largest singular values of matrix $Z$
% (square root of the eigenvalues of matrix $Z^TZ=(n-1)R$) where $R$ is the
% correlation matrix.
%
Expand Down Expand Up @@ -53,7 +53,7 @@ function biplotFS(Y,varargin)
% \[
% \sqrt{n-1} U_{(2)}= Z V_{(2)} \Gamma_{(2)}^{-1}
% \]
% that is row points are the standardized principal components scores.
% that is, row points are the standardized principal components scores.
% \[
% cov (\sqrt{n-1} U_{(2)}) = I_2= \left(
% \begin{array}{cc}
Expand All @@ -66,10 +66,10 @@ function biplotFS(Y,varargin)
% \[
% \Gamma_{(2)} V_{(2)}^T
% \]
% that is the arrows are associated with the correlations between the
% variables and the first two principal components
% The length of the arrow is exactly equal to the communality of the asoociated variable.
% In this case the unit circle is also shown on the screen and option axis
% that is, the arrows are associated with the correlations between the
% variables and the first two principal components.
% The length of the arrow is exactly equal to the communality of the associated variable.
% In this case, the unit circle is also shown on the screen and option axis
% equal is set.
%
% On the other hand, if $\omega=1$ and $\alpha=1$
Expand All @@ -78,7 +78,7 @@ function biplotFS(Y,varargin)
% \[
% \sqrt{n-1} U_{(2)} \Gamma_{(2)} = Z V_{(2)}
% \]
% In this case the row points are the (non normalized) scores, that is
% In this case, the row points are the (non normalized) scores, that is
% \[
% cov(\sqrt{n-1} U_{(2)} \Gamma_{(2)}) =cov( Z V_{(2)})= \left(
% \begin{array}{cc}
Expand All @@ -92,10 +92,10 @@ function biplotFS(Y,varargin)
% \[
% V_{(2)}^T
% \]
% Also in this case the unit circle is given and option axis equal is set.
% Also in this case, the unit circle is given and option axis equal is set.
%
% In general if $\omega$ decreases, the length of the arrows increases
% and the coordinates of row points are squeezed towards the origin
% and the coordinates of row points are squeezed towards the origin.
%
% In the app it is also possible to color row points depending on the
% orthogonal distance ($OD_i$) of each observation to the PCA subspace.
Expand All @@ -107,9 +107,9 @@ function biplotFS(Y,varargin)
% OD_i=|| z_i- V_{(2)} V_{(2)}' z_i ||
% \]
%
% If optional input argument bsb or bdp is specified it is possible to have
% in the app two tabs which enable the user to select the breakdown point
% of the analysis of the subset size to use in the svd. The units which are
% If an optional input argument, bsb or bdp, is specified, it is possible to have
% in the app two tabs that enable the user to select the breakdown point
% of the analysis of the subset size to use in the svd. The units that are
% declared as outliers or the units outside the subset are shown in the
% plot with filled circles.
%
Expand All @@ -127,70 +127,70 @@ function biplotFS(Y,varargin)
%
% Optional input arguments:
%
% bsb : units forming subset on which to perform PCA. vector.
% Vector containing the list of the untis to use to
% compute the svd. The other units are projected in the
% space of the first two PC. bsb can be either a numeric
% vector of length m (m<=n) containin the list of the
% units (e.g. 1:50) or a logical vector of length n
% containing the true for the units which have to be used
% in the calculation of svd. For example bsb=true(n,1),
% bsb(13)=false; excludes from the svd unit number 13.
% Note that if bsb is supplied bdp must be empty.
% Example - 'bsb',[2 10:90 93]
% Data Types - double or logical
%
% bdp : breakdown point. Scalar.
% bsb : units forming a subset on which to perform PCA. vector.
% Vector containing the list of the units to use to
% compute the svd. The other units are projected in the
% space of the first two PC. bsb can be either a numeric
% vector of length m (m<=n), containing the list of the
% units (e.g., 1:50), or a logical vector of length n
% containing the true for the units that have to be used
% in the calculation of svd. For example, bsb=true(n,1),
% bsb(13)=false; excludes from the svd unit number 13.
% Note that if bsb is supplied, bdp must be empty.
% Example - 'bsb',[2 10:90 93]
% Data Types - double or logical
%
% bdp : breakdown point. Scalar.
% It measures the fraction of outliers the algorithm should
% resist. In this case any value greater than 0 but smaller
% or equal than 0.5 will do fine. Note that if bdp is
% supplied bsb must be empty.
% Example - 'bdp',0.4
% Data Types - double
% resist. In this case, any value greater than 0, but smaller
% or equal than 0.5, will do fine. Note that if bdp is
% supplied, bsb must be empty.
% Example - 'bdp',0.4
% Data Types - double
%
%
% standardize : standardize data. boolean. Boolean which specifies
% whether to standardize the variables, that is we operate on
% standardize : standardize data. boolean. Boolean that specifies
% whether to standardize the variables, that is, we operate on
% the correlation matrix (default) or simply remove column
% means (in this last case we operate on the covariance
% matrix).
% Example - 'standardize',false
% Data Types - boolean
%
% alpha : svd parameter. Scalar. Scalar in the interval [0 1] (see
% section additional details for more help). This parameter can
% be controllad by the corresponding sliding bar when the app is
% shown.
% Example - 'alpha',0.6
% Data Types - double
%
% omega : svd parameter. Scalar. Scalar in the interval [0 1] (see
% section additional details for more help). This parameter can
% be controllad by the corresponding sliding bar when the app is
% shown.
% Example - 'omega',1
% Data Types - double
%
% showRowPoints : hide or show row point. Boolean. If showRowPoints is true
% row points are shown in the biplot (default) else there are hidden.
% Example - 'standardize',false
% Data Types - boolean
%
% showRowNames : hide or show labels of row points. Boolean. If showRowNames is true
% labels of row names are shown in the biplot else (default) there are hidden.
% Example - 'showRowNames',false
% Data Types - boolean
%
% showArrows : hide or show arrows. Boolean. If showArrows is true
% arrows (associated labels) labels are shown in the biplot (default)
% else there are hidden.
% Example - 'showArrows',false
% Data Types - boolean
% Example - 'standardize',false
% Data Types - boolean
%
% alpha : svd parameter. Scalar. Scalar in the interval [0 1] (see
% section "additional details" for more help). This parameter can
% be controlled by the corresponding sliding bar when the app is
% shown.
% Example - 'alpha',0.6
% Data Types - double
%
% omega : svd parameter. Scalar. Scalar in the interval [0 1] (see
% section "additional details" for more help). This parameter can
% be controlled by the corresponding sliding bar when the app is
% shown.
% Example - 'omega',1
% Data Types - double
%
% showRowPoints : hide or show row point. Boolean. If showRowPoints is true,
% row points are shown in the biplot (default); otherwise they are hidden.
% Example - 'standardize',false
% Data Types - boolean
%
% showRowNames : hide or show labels of row points. Boolean. If showRowNames is true,
% labels of row names are shown in the biplot, otherwise (default) they are hidden.
% Example - 'showRowNames',false
% Data Types - boolean
%
% showArrows : hide or show arrows. Boolean. If showArrows is true,
% arrows (associated labels) labels are shown in the biplot (default);
% otherwise they are hidden.
% Example - 'showArrows',false
% Data Types - boolean
%
% Output:
% when the biplotAPP is closed in the base workspace a new variable
% called bsbfinalFromAPP is created which contains a logical vector
% of length n containing true for the units which have been used in
% when the biplotAPP is closed, in the base workspace, a new variable
% called bsbfinalFromAPP is created, which contains a logical vector
% of length n containing true for the units that have been used in
% the svd.
%
%
Expand All @@ -214,9 +214,9 @@ function biplotFS(Y,varargin)
%% use of biplotFS on the ingredients dataset.
load hald
% Operate on the correlation matrix (default).
% use standardized principal components (for row points) and
% Use standardized principal components (for row points) and
% correlation between variables and principal components (for column
% points, arrows)
% points, arrows).
close all
biplotFS(ingredients,'omega',1,'alpha',0);
%}
Expand Down
Loading

0 comments on commit 2c44f82

Please sign in to comment.