Coventry University Logo Sigma Logo

Chi-squared Tests in R (Using R Studio): Further Results

Exploring Chi-squared results further

The worksheet called Introduction to Chi-Squared Tests Using JASP, showed how to run a Chi-squared test.

Evidence was found that there is an association between colour and personality type. However, this does not tell us about the nature of that association. This worksheet shows you how to discover more.

Example

Unlike in the previous worksheet, we want contingency tables that show raw frequencies and row percentages. Begin by creating a contingency table using the same code as previously:

contingency_table <- table(personality_colours$personality, personality_colours$colour)

Next, add margins to obtain sums for both personality and colour.

addmargins(contingency_table)
##            
##             Red Yellow Green Blue Sum
##   Introvert  20      6    30   44 100
##   Extrovert 180     34    50   36 300
##   Sum       200     40    80   80 400

The frequency table shows the number of people in each personality group that chose each colour. This helps us see the size of each group and how many people made each choice.

The function prop.table() can be used to get row percentages for each personality type against colour.

prop.table(contingency_table, margin=1)*100
##            
##                  Red   Yellow    Green     Blue
##   Introvert 20.00000  6.00000 30.00000 44.00000
##   Extrovert 60.00000 11.33333 16.66667 12.00000

The row percentages demonstrate that more than half of the extroverts prefer the colour red (60%), while in contrast, almost three-quarters of introverts (74%) prefer blue (44%) and green (30%).

Phi and Cramer’s V provide a measure of the effect size (see the ‘Nominal’ table below). Both measure strength of association between two categorical variables, but are used for different sized tables:

  • Phi is used with 2 X 2 tables (and is equivalent to the correlation coefficient r).

  • Cramer’s V is used with larger tables.

Note: to add additional functions to Rstudio we can install external packages. These can add more capabilities not present in the default Rstudio or when there is no other way to carry on an analysis.

We calculate these statistics by first installing the R package vcd.

# Install the package
install.packages("vcd", repos = "https://cloud.r-project.org")

After installing the package we need to call it by using library(). This will indicate Rstudio to use the functions inside this package to run calculations or procedures requested by the user. We can then use the function assocstats().

library(vcd)
## Calculate Cramer's V
assocstats(contingency_table)
##                     X^2 df   P(> X^2)
## Likelihood Ratio 70.066  3 4.1078e-15
## Pearson          71.200  3 2.3315e-15
## 
## Phi-Coefficient   : NA 
## Contingency Coeff.: 0.389 
## Cramer's V        : 0.422

Since we have a 2x4 table (2 rows and 4 columns) we use a Cramer’s V of 0.422. Phi’s coefficient is NaN as our table is not 2x4, not 2x2 as required to obtain a coefficient. We can interpret what this means using Cohen’s guidelines in the table below. To use that table we need to determine what our degrees of freedom (df) is. To determine the df, we choose the smallest of the number of rows (2) and the number of columns (4); in this case the smallest is 2. We then minus 1 from this to get our df=2-1=1. Hence, we look for this value in the column labelled df in the table below and look along the row labelled 1. Our Cramer’s V of 0.42 is between the table values 0.3 and 0.5, so our effect size is medium to large.

Cohen’s (1988) implied guidelines for interpreting Phi and Cramer’s V

df small medium large
1 0.10 0.30 0.50
2 0.07 0.21 0.35
3 0.06 0.17 0.29
4 0.05 0.15 0.25
5 0.04 0.13 0.22

Reporting Results

We could report the results as:

“A Chi-Squared test was undertaken to examine the relationship between personality type and colour preference. There is strong evidence that colour preference is associated with personality type, χ^2(3, N=400) = 71.20, p<0.001. This association was a medium to strong association (V=0.42) where introverts seem more likely to prefer blue (40%) and green (34%) whereas extroverts are more likely to prefer red (60%).”

For more resources, see sigma.coventry.ac.uk Adapted from material developed by Coventry University Creative Commons License