2.0

2.0 | 1 rating Rate this file 52 downloads (last 30 days) File Size: 2.34 KB File ID: #22560

Indicator matrix generation from survey questions.

by Antonio Trujillo-Ortiz

 

31 Dec 2008 (Updated 05 Jan 2009)

Code covered by BSD License  

indicator matrix, multiple correspondence analysis, crosstabulation analysis, categorical analysis.

Download Now | Watch this File

File Information
Description

An indicator matrix (G), a binary coding matrix of the factors called dummy variables. The number of rows are the total sample items and the columns are the total categories of the variables. The elements in G are 1's if the item corresponding to the category of the variable or 0's if not. The indicator matrix is an alternative format to input data in a Multiple Correspondence Analysis from survey questions. One can get the Burt matrix (B) simply by B = G'G.

Syntax: function x=indmatgen(lcv,table)
     
Input:
lcv: maximum number of levels on each catagorical variable
table: table of data
             
Output:
- Indicator matrix

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
05 Jan 2009 Jos

You can use real input variables into your function, as in function x = indmatgen(lcv,table)? Also use the error function, instead of disp + return. Finally, pre-allocate your variables, and return b as an output directly, instead of copying it into x first.

05 Jan 2009 Antonio Trujillo-Ortiz

Dear Jos. Thanks for your valuable comments for improve this m-file script. They were taken into account.

28 Jan 2009 Jos

Again, learn how to use the function ERROR.
Secondly, avoid growing variables inside a loop. Try to pre-allocate X

Finally, this one-liner does the same
X = full(sparse(repmat(1:size(table,1),numel(lcv),1).' , bsxfun(@plus,table,[0 cumsum(lcv(1:end-1))]) , 1))

but this might be indeed to cryptic, so split it up into sub-units. Also add error checks, e.g. using for instance any(bsxfun(@gt,table,lcv))

Also take a look into SUB2IND.

In short, there is still room for improvement.

Please login to add a comment or rating.
Updates
31 Dec 2008

It was added an appropriate format to cite this file.

03 Jan 2009

Text was improved.

05 Jan 2009

We improved this m-file by the valuable comment of Jos (05/01/2009).

Tag Activity for this File
Tag Applied By Date/Time
indicator matrix Antonio Trujillo-Ortiz 31 Dec 2008 09:18:22
multiple correspondence analysis Antonio Trujillo-Ortiz 31 Dec 2008 09:18:22
crosstabulation analysis Antonio Trujillo-Ortiz 31 Dec 2008 09:18:22
categorical analysis Antonio Trujillo-Ortiz 31 Dec 2008 09:18:22
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com