Wednesday, July 22, 2020

colPercents

With colPercents you can get row, column, and total percents for a contingency table (the marginal values I write about in the table topic).

The colPercents command is part of the RcmdrMisc package that I installed as part of STAT 3743. From the R community, it looks like you can get the same value using prop.table and cbind, though that's a multi-step process.

Just two parameters, the table of frequency counts, and optional digits for % display.

R Example


This example uses the carData package Mroz data, which contains labor force participation for married women. This example shows labor force participation (lfp) against whether the wife attended college (wfc).

> colPercents(xtabs(~ lfp + wc, data=Mroz))
wc
lfp       no   yes
  no     47.5  32.1
  yes    52.5  67.9
  Total 100.0 100.0
  Count 541.0 212.0



This table reports that 47.5% of married women who did not attend college do not work.

No comments:

Post a Comment

Please help to combat malicious use of the Internet.