📄 mcorran2.m
字号:
function mcorran2(X)
%MCORRAN2 Multiple Correspondence Analysis Based on the Burt Matrix.
% Statistics fundamentals of the Correspondence Analysis (CA) is presented
% in the CORRAN and MCORRAN1 m-files you can find in this FEX author''s page.
% CA can be extended to more than two categorical variables, called Multiple
% Correspondence Analysis (MCA). CA and MCA are graphical techniques for
% representing the information in a two-way or higher-order multiway
% contingency table. They contain the counts (frequencies) of items for a
% cross-classifications of the categorical variables (Rencher, 2000).
%
% Karl Pearson (1913) developed the antecedent of CA used by Procter&Gamble
% (Horst 1935). R.A. Fisher (1940) named the approach 'reciprocal averaging'
% because is reciprocally averages row and column percents in table data
% until they are reconciled. Since reciprocal averaging was inefficient,
% Europeans such as Mosaier (1946) and Benzecri (1969) related table data
% with computer programs for principal component (factor) analysis. Burt
% (1953) developed MCA (homogeneity analysis) of a binary indicator.
%
% Here, MCA is applied to the Burt matrix (B), the matrix of all two-way
% cross-tabulations of the categorical variables. The Burt matrix has a
% square block on the diagonal for each variable (the frequencies for the
% categories in the corresponding variable) and a rectangular block
% off-diagonal for each pair of variables (a two-way contingency table for
% the corresponding pair of variables). In the dual eigenanalysis or
% Singular Value Decomposition (SVD) we get the squares of the singular
% values, or principal inertias.
%
% The so-called 'percentage of inertia problem' can be improved by using
% adjusted inertias procedure or eigenvalue correction. The adjusted inertias
% are calculated only for each singular value that satisfies the inequality
% >= 1/number of variables. They are expressed as a percentage of the average
% off-diagonal inertia, which can be calculated either by direct calculation
% on the off-diagonal tables in the Burt matrix. The adjusted solution not
% only does it considerably improve the measure of fit, but it also removes
% the inconsistency about the Burt matrix to analyse. This inconsistency is
% due to artificial dimensions added because one categorical variable is
% coded with several columns. As a consequence, the inertia (i.e., variance)
% of the solution space is artificially inflated and therefore the percentage
% of inertia explained by the first dimension is severely underestimated.
%
% A complete statistics fundamentals explanation is found on Greenacre (2006).
%
% A MCA yields only rows or columns coordinates and each point represents a
% category (attribute) of one of the variables.
%
% Syntax: function mcorran2(X)
%
% Input:
% X - Data matrix=Burt matrix. Size: categorical variables x
% categorical variables (>2).
% Outputs:
% Complete Multiple Correspondence Analysis
% By default the adjusted inertias table is given
% Pair-wise Dimensions Plots. For the vertical and horizonal lines
% we use the hline.m and vline.m files kindly published on FEX
% by Brandon Kuczenski [http://www.mathworks.com/matlabcentral/
% fileexchange/1039]. For connecting lines to the originwe use
% the plot2org published on FEX by Jos
% [http://www.mathworks.com/matlabcentral/fileexchange/11337]
%
% Example: From the table 2.2 (Greenacre, 2006) we have the data on attitudes
% to science and the environment from the International Social Survey Program
% on environment (ISSP), showing the complete Burt matrix of all pairwise
% cross-tables of the four variables. Each variable with five categories. The
% number of respondents were 871.
% ----------------------------------------------------------------------------------
% Variable A Variable B Variable C Variable D
% ----------------------------------------------------------------------------------
% A1 A2 A3 A4 A5 B1 B2 B3 B4 B5 C1 C2 C3 C4 C5 D1 D2 D3 D4 D5
% ----------------------------------------------------------------------------------
% A1 119 0 0 0 0 27 28 30 22 12 49 40 18 7 5 15 25 17 34 28
% A2 0 322 0 0 0 38 74 84 96 30 67 142 60 41 12 22 102 76 68 54
% A3 0 0 204 0 0 3 48 63 73 17 18 75 70 34 7 10 44 68 58 24
% A4 0 0 0 178 0 3 21 23 79 52 16 50 40 56 16 9 52 28 54 35
% A5 0 0 0 0 48 0 3 5 11 29 2 9 9 16 12 4 9 13 12 10
% B1 27 38 3 3 0 71 0 0 0 0 43 19 4 3 2 9 17 10 10 25
% B2 28 74 48 21 3 0 174 0 0 0 36 88 34 15 1 16 51 42 45 20
% B3 30 84 63 23 5 0 0 205 0 0 37 90 57 19 2 10 53 63 51 28
% B4 22 96 73 79 11 0 0 0 281 0 27 88 75 74 17 6 66 70 92 47
% B5 12 30 17 52 29 0 0 0 0 140 9 31 27 43 30 19 45 17 28 31
% C1 49 67 18 16 2 43 36 37 27 9 152 0 0 0 0 25 24 15 38 50
% C2 40 142 75 50 9 19 88 90 88 31 0 316 0 0 0 15 97 67 89 48
% C3 18 60 70 40 9 4 34 57 75 27 0 0 197 0 0 5 51 83 41 17
% C4 7 41 34 56 16 3 15 19 74 43 0 0 0 154 0 6 44 30 51 23
% C5 5 12 7 16 12 2 1 2 17 30 0 0 0 0 52 9 16 7 7 13
% D1 15 22 10 9 4 9 16 10 6 19 25 15 5 6 9 60 0 0 0 0
% D2 25 102 44 52 9 17 51 53 66 45 24 97 51 44 16 0 232 0 0 0
% D3 17 76 68 28 13 10 42 63 70 17 15 67 83 30 7 0 0 202 0 0
% D4 34 68 58 54 12 10 45 51 92 28 38 89 41 51 7 0 0 0 226 0
% D5 28 54 24 35 10 25 20 28 47 31 50 48 17 23 13 0 0 0 0 151
% ----------------------------------------------------------------------------------
%
% Data matrix must be:
% X=[119 0 0 0 0 27 28 30 22 12 49 40 18 7 5 15 25 17 34 28;
% 0 322 0 0 0 38 74 84 96 30 67 142 60 41 12 22 102 76 68 54;
% 0 0 204 0 0 3 48 63 73 17 18 75 70 34 7 10 44 68 58 24;
% 0 0 0 178 0 3 21 23 79 52 16 50 40 56 16 9 52 28 54 35;
% 0 0 0 0 48 0 3 5 11 29 2 9 9 16 12 4 9 13 12 10;
% 27 38 3 3 0 71 0 0 0 0 43 19 4 3 2 9 17 10 10 25;
% 28 74 48 21 3 0 174 0 0 0 36 88 34 15 1 16 51 42 45 20;
% 30 84 63 23 5 0 0 205 0 0 37 90 57 19 2 10 53 63 51 28;
% 22 96 73 79 11 0 0 0 281 0 27 88 75 74 17 6 66 70 92 47;
% 12 30 17 52 29 0 0 0 0 140 9 31 27 43 30 19 45 17 28 31;
% 49 67 18 16 2 43 36 37 27 9 152 0 0 0 0 25 24 15 38 50;
% 40 142 75 50 9 19 88 90 88 31 0 316 0 0 0 15 97 67 89 48;
% 18 60 70 40 9 4 34 57 75 27 0 0 197 0 0 5 51 83 41 17;
% 7 41 34 56 16 3 15 19 74 43 0 0 0 154 0 6 44 30 51 23;
% 5 12 7 16 12 2 1 2 17 30 0 0 0 0 52 9 16 7 7 13;
% 15 22 10 9 4 9 16 10 6 19 25 15 5 6 9 60 0 0 0 0;
% 25 102 44 52 9 17 51 53 66 45 24 97 51 44 16 0 232 0 0 0;
% 17 76 68 28 13 10 42 63 70 17 15 67 83 30 7 0 0 202 0 0;
% 34 68 58 54 12 10 45 51 92 28 38 89 41 51 7 0 0 0 226 0;
% 28 54 24 35 10 25 20 28 47 31 50 48 17 23 13 0 0 0 0 151];
%
% Calling on Matlab the function:
% mcorran2(X)
% Answer is:
%
% Give me the vector of categories of each variable. Please, use [ ]: [5 5 5 5]
%
% Inertias of the Multiple Correspondence Analysis
% for the Burt matrix given.
% ----------------------------------------
% Eigenvalue Percent Cummulative
% (Inertia) Percent
% ----------------------------------------
% 0.2092 18.55 18.55
% 0.1857 16.47 35.02
% 0.1036 9.19 44.21
% 0.0939 8.33 52.54
% 0.0760 6.74 59.28
% 0.0635 5.63 64.91
% 0.0588 5.22 70.12
% 0.0552 4.90 75.02
% 0.0508 4.51 79.53
% 0.0487 4.32 83.84
% 0.0440 3.90 87.75
% 0.0389 3.45 91.20
% 0.0316 2.81 94.00
% 0.0286 2.54 96.54
% 0.0234 2.07 98.61
% 0.0157 1.39 100.00
% ----------------------------------------
% Total 100.00
% Variable categories = 5 5 5 5
% ----------------------------------------
%
% Adjusted inertias of the Multiple Correspondence
% Analysis for the Burt matrix given.
% ----------------------------------------
% Eigenvalue Percent Cummulative
% (Inertia) Percent
% ----------------------------------------
% 0.07646 44.91 44.91
% 0.05822 34.20 79.11
% 0.00920 5.40 84.51
% 0.00567 3.33 87.84
% 0.00117 0.69 88.53
% 0.00001 0.00 88.53
% ----------------------------------------
% Total 88.53
% Variable categories = 5 5 5 5
% ----------------------------------------
%
% Are you interested to get the dimensions plots? (y/n): y
% --------------
% The pair-wise plots you can get are: 120
% --------------
% Dm =
% 1 2
% 1 3
% 1 4
% . .
% . .
% 1 15
% 1 16
% 2 3
% 2 4
% . .
% . .
% 13 15
% 13 16
% 14 15
% 14 16
% 15 16
% --------------
% Give me the interested dimensions to plot. Please, use [a b]:[1 2]
%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -