Comparing two proportions for paired samples (3)
Now that we've got our 2 parameters, we can actually check whether the difference is significant. To do so, we will use the McNemar test. The formula for the McNemar test is displayed below:
$$z = \frac{n_{01} - n_{10}}{\sqrt{n_{01} + n_{10}}}$$
Let's fill in some of the parameters using our own data (see below). To calculate this Z value, you would need to fill in the gaps. $n01$ in this case is the value in row zero and the first column. This would thus be the value of 50. $n10$ in this case is the value in the first row and column zero. This would thus be 35.
This exercise is part of the course
Inferential Statistics
Exercise instructions
- Calculate the z statistic using the McNemar test. Assign this to a variable
z_value
- Use the function
pnorm()
to check the p value that pertains to the z value and print it to the console. To use thepnorm()
function, you can just fill in the thez_value
as the first parameter. Also make sure to set thelower.tail
argument toFALSE
. Lastly, make sure to multiply the p value by 2 as we are doing a two-sided hypothesis test. - Is there a significant difference between the amount of surveyed people that approve of the European Union and the amount of their partners that approve of the European union? Assign either a
yes
or ano
to the variabledifference
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# calculate the z value and assign it to the variable z_value
# calculate the p value that pertains to the z value
# assign a yes or a no to the variable difference