Session Ready
Exercise

Set up a crosstable! (2)

Alternatively, the gmodels package offers the CrossTable() function. It provides output much more like SAS, SPSS and Stata and it does so with a single function that works similarly to the equivalent functions in the other packages.

The function allows for performing a Chi-Square test by setting the chisq argument equal to TRUE. Also row proportions (prop.r), column proportions (prop.c), table proportions (prop.t) and the chi-square contribution of each cell (prop.chisq) might be added to the table by simply setting the argument equal to TRUE. Moreover, the results of the function might be printed in the output format of SAS or SPSS by setting format equal to respectively SAS or SPSS.

To illustrate the use of the function, the talent dataset is used and, again, a crosstable is set up for gender and fulltime.

Instructions
100 XP
  • Set up a crosstable for gender and fulltime using the CrossTable() function. Assign the name gender_fulltime_2 and print the output.
  • Use the CrossTable() function to set up a crosstable for gender and fulltime in which only the results for the chi-square test are included, and the row proportions.
  • Use the CrossTable() function to set up a crosstable for gender and fulltime from which the output is printed in SAS format.
  • Use the CrossTable() function to set up a crosstable for gender and fulltime from which the output is printed in SPSS format.

Make use of the dollar sign to select variables. The arguments chisq, prop.r, prop.c, prop.t and prop.chisq are set TRUE by default in CrossTable(). Make sure to place gender first, and fulltime second in the table.