Code covered by the BSD License  

Highlights from
Indicator matrix generation from survey questions.

2.0

2.0 | 1 rating Rate this file 0 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)

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

| 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 (10584)

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 (10584)

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

Contact us at files@mathworks.com