Sign In for Full Access

Quick access through the institutional single sign-on Manchester Met Sign In
Skip this for now
|
Public Access Here

Sign In for Free Access

Login with email for free guest access to a range of Rise content
Go!
Logging You In!
Incorrect Password (Click Here to Reset)! Passwords Must Match Password must be more than 8 characters
Skip this for now
|
Man Met Access Here
menu

How to conduct Chi Square and Cramer’s V strength of association tests in R Studio

This guide will walk you through step by step how to conduct a chi-square and Cramer’s V strength of association test using SPSS. This guide may refer to some skills discussed in previous intensives, such as descriptive univariate and bivariate courses. it may be beneficial to complete those first or refer to them if you find yourself struggling.

For this guide we will be using the Attitudes to Animal Research dataset

Insert link here 

Remember: It is always good practice to run Descriptives and clean our data before performing any inferential tests! If you are unsure how to do this, cleaning data and recoding is covered in the univariate analysis RISE intensive, why not give it a go!

For this example, we will be using the following variables:

DVgenerationGeneration respondent was born in
IVregionRegion respondent lives in

Association between variables

Without any tests or research, do you think there could be an association between the two variables and why?

OPTIONAL

Create either a one or two-tail hypothesis for the above variables

Remember: you need both a null and research hypothesis.

OPTIONAL

Step 1 – set your working directory! We also need to import our data from an excel file into R Studio using the ‘readxl’ package. If you require a more in-depth tutorial on how to do this refer to the introduction and univariate analysis intensives for R Studio.

Step 2 – We can now shorten our dataset name to make it easier to code further along. To do this we need to use the following code:

Remember: to enter code we need to press ctrl + Ent

The <- symbol allows us to create new variables and shortened datasets! For this example, we have shortened it to ‘anres’, this should be available to view in the environment pane.

Step 3 – Now we need to produce tables for out two variables, we can also shorten these to make future coding easier also.

To create the table, we need to use the following code:

table (dataset$variable)

so, for our two variables in this instance it should look like this:

We can then shorten these to just gen and reg for future use, again using the <- symbol like so.

These should appear in your environment field as values.

The frequency tables produced should look like the following be sure to compare to make sure you are correct!

Step 4 – With our shortened variables we can now produce a bivariate table.

Again, we can shorten this to one word using the following code:

This means that every time we type ‘tbl’ it will produce the bivariate crosstab for our variables!

Step 5 – We can now add sums to this table by using:

Step 6 – To perform the chi-square test, use the following code:

Step 7 – If the p value looks like so. You can use:

Press ctrl and Ent. Then return to the end of Chi-Square Code, be sure to click and press ctrl+ Ent again. This should change the p value.

This makes the value a decimal instead. Round to 3 d.p.

Step 8 – To run a Cramer’s V test. We need to install the ‘lsr’ package. This is a companion package to learning statistics with R Studio! To do this we use the following code:

We can then select it from the packages screen.

After this, we can use the following code to run the test!

WELL DONE! YOU SUCCESSFULLY PERFORMED A CHI SQUARE AND CRAMER’S V TEST!