Re: [R] crosstab for n-way contingency tables

From: Marc Schwartz (via MN) <mschwartz_at_mn.rr.com>
Date: Wed 31 Aug 2005 - 05:54:22 EST

On Tue, 2005-08-30 at 12:28 -0700, Isotta Felli wrote:
> Dear list.
>
> New to R, I'm looking for a way of using crosstab to output
> low-dimensional (higher than 2) contingency tables (frequencies,
> per-cents by rows, % by columns, mean, quantiles....) I'm looking for
> something of the following sort
>
> dataframe: singers,
> categorical variates: voice category (soprano,mezzo-soprano, ...) ,
> voice type( drammatic, spinto, lirico-spinto, lirico, leggero), school
> (german, italian, french, russian, anglo-saxon, other);repertory
> (opera, Lieder, oratorio, operetta)
> continuous variate: age
>
> I would like to tabulate the frequencies (relative percentages) say
> in the following way
> columns: school repertory
> rows : voice category voice type
>
> or to output in the cells of the above table, the statistics
> (mean/median/quantiles) for age
>
>
> I've seen that the function bwplot(age~school | repertory, data=
> singers, layout=c(4,2)) would do graphically something similar to what
> I want, but I desire the output also in tabular form
>
> Thanks
>
> Isotta

I don't know that you will find a single function that will do all of what you desire, but you can look at the ctab() function, which is in the 'catspec' package on CRAN by John Hendrickx. This will do multi-way tables with summary row/col statistics.

There is also the CrossTable() function in the 'gmodels' package on CRAN, though this will only do one way and two way tables, with summary row/col statistics.

Neither of the above provide typical summary output for continuous data. They are more for categorical variables.

For simple count multi-way output, you can also look at the ftable() function which is in the base package. Also look at the summary() function in the base package which will provide range, mean, quantile data for continuous variables. It may just be a matter of formatting the output in a fashion that you desire on a post analysis basis.

HTH, Marc Schwartz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Aug 31 06:00:59 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 16:09:16 EST