1. Learn
  2. /
  3. Courses
  4. /
  5. Inferential Statistics

Exercise

Conditional Proportions

The data for your advertising experiment is still saved in your console as data. If you enter rowSums(data) into your console you can see that we had different numbers of people in each category. In order to compare the categories, we need to standardise the values accross rows. We can do this by finding the conditional proportions for each row. We obtain the conditional proportions per row by dividing the value in each cell by the row total.

We can index a row from our data using [,]. For example, data[1,] would index the first row (enter it into your console and have a look!). We can find the sum (or total) value in R using the function sum().

So, if we wanted to find the total value of the first row, we would enter sum(data[1,]). To divide the value of each cell in a row by the total, it's as simple as: data[1,]/sum(data[1,]) - this basically tells R: "take every value of the first row, and divide it by the total of all values in the first row".

We're going to do this for all three rows and assign it to a new table called datastand! We've done the first one for you, so you just have to do the second two.

Instructions

100 XP
  • In your script, add a line of code to calculate the conditional proportions per row for the second row.
  • In your script, add a line of code to calculate the conditional proportions per row for the third row.
  • In your script, print your new standardised contingency table datastand.
  • Remember, to index you use square brackets [ ], whereas for functions and calculations you use circle brackets ().