Statistics Toolbox
  Go to function:
    Search    Help Desk 
crosstab    Examples   See Also

Cross-tabulation of two vectors.

Syntax

Description

table = crosstab(col1,col2) takes two vectors of positive integers and returns a matrix, table, of cross-tabulations. The ijth element of table contains the count of all instances where col1 = i and col2 = j.

[table,chi2,p] = crosstab(col1,col2) also returns the chisquare statistic, chi2, for testing the independence of the rows and columns table. The scalar, p, is the significance level of the test. Values of p near zero cast doubt on the assumption of independence of the rows and columns of table.

Example

We generate 2 columns of 50 discrete uniform random numbers. The first column has numbers from one to three. The second has only ones and twos. The two columns are independent so we would be surprised if p were near zero.

The result, 0.1242, is not a surprise. A very small value of p would make us suspect the "randomness" of the random number generator.

See Also



[ Previous | Help Desk | Next ]