You are here

Group Exercise: Probability and Odds

Select a different measure of political participation and produce a percentage table and interpret the probabilities. Then recode it into a 2x2 table and compute the odds ratio and interpret the results. Post your interpretations and your R code as a comment to this page.

Comments

>library(gmodels)
>ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
>CrossTable(V161307,V162257,prop.t=F,prop.r=F,prop.chisq=F,prop.c=T)
>socialclass2016<-ifelse(V161307<=2,1,0)
> polmedia<-ifelse(V162257==4,1,0)
> CrossTable(socialclass2016,polmedia,prop.t=F,prop.r=F,prop.chisq=F,prop.c=T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2258

| polmedia
socialclass2016 | 0 | 1 | Row Total |
----------------|-----------|-----------|-----------|
0 | 1225 | 55 | 1280 |
| 0.578 | 0.399 | |
----------------|-----------|-----------|-----------|
1 | 895 | 83 | 978 |
| 0.422 | 0.601 | |
----------------|-----------|-----------|-----------|
Column Total | 2120 | 138 | 2258 |
| 0.939 | 0.061 | |
----------------|-----------|-----------|-----------|

> fisher=T
> CrossTable(socialclass2016,polmedia,prop.t=F,prop.r=F,prop.chisq=F,prop.c=T,fisher=T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2258

| polmedia
socialclass2016 | 0 | 1 | Row Total |
----------------|-----------|-----------|-----------|
0 | 1225 | 55 | 1280 |
| 0.578 | 0.399 | |
----------------|-----------|-----------|-----------|
1 | 895 | 83 | 978 |
| 0.422 | 0.601 | |
----------------|-----------|-----------|-----------|
Column Total | 2120 | 138 | 2258 |
| 0.939 | 0.061 | |
----------------|-----------|-----------|-----------|

Fisher's Exact Test for Count Data
------------------------------------------------------------
Sample estimate odds ratio: 2.064868

Alternative hypothesis: true odds ratio is not equal to 1
p = 5.748817e-05
95% confidence interval: 1.434192 2.992391

Alternative hypothesis: true odds ratio is less than 1
p = 0.9999859
95% confidence interval: 0 2.823637

Alternative hypothesis: true odds ratio is greater than 1
p = 3.038461e-05
95% confidence interval: 1.516154 Inf

Interpretation:
Lower class, and working class people are most likely to follow politics in media and vice versa.

library(gmodels)
> Surv2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016_userguidecodebook.pdf")
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
more columns than column names
> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
> CrossTable(V161307,V162018d,prop.r = F,prop.t = F,prop.c =T,prop.chisq =F,chisq =F )

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2264

| V162018d
V161307 | 1 | 2 | Row Total |
-------------|-----------|-----------|-----------|
1 | 25 | 214 | 239 |
| 0.052 | 0.120 | |
-------------|-----------|-----------|-----------|
2 | 120 | 621 | 741 |
| 0.250 | 0.348 | |
-------------|-----------|-----------|-----------|
3 | 296 | 888 | 1184 |
| 0.617 | 0.498 | |
-------------|-----------|-----------|-----------|
4 | 39 | 61 | 100 |
| 0.081 | 0.034 | |
-------------|-----------|-----------|-----------|
Column Total | 480 | 1784 | 2264 |
| 0.212 | 0.788 | |
-------------|-----------|-----------|-----------|

> SocClass<-ifelse(V16203<=2,0,1)
Error in ifelse(V16203 <= 2, 0, 1) : object 'V16203' not found
> SocClass2016(V161307<=2,1,0)
Error in SocClass2016(V161307 <= 2, 1, 0) :
could not find function "SocClass2016"
> CrossTable(V162018d,V161307,prop.r = F,prop.t = F,prop.c =T,prop.chisq =F,chisq =F )

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2264

| V161307
V162018d | 1 | 2 | 3 | 4 | Row Total |
-------------|-----------|-----------|-----------|-----------|-----------|
1 | 25 | 120 | 296 | 39 | 480 |
| 0.105 | 0.162 | 0.250 | 0.390 | |
-------------|-----------|-----------|-----------|-----------|-----------|
2 | 214 | 621 | 888 | 61 | 1784 |
| 0.895 | 0.838 | 0.750 | 0.610 | |
-------------|-----------|-----------|-----------|-----------|-----------|
Column Total | 239 | 741 | 1184 | 100 | 2264 |
| 0.106 | 0.327 | 0.523 | 0.044 | |
-------------|-----------|-----------|-----------|-----------|-----------|

> SocClass<-ifelse(V161307<=2,1,0)
> CrossTable(SocClass,V162018d,prop.c = T,prop.t = F,prop.r = F,prop.chisq = F,chisq = F, fisher = T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2264

| V162018d
SocClass | 1 | 2 | Row Total |
-------------|-----------|-----------|-----------|
0 | 335 | 949 | 1284 |
| 0.698 | 0.532 | |
-------------|-----------|-----------|-----------|
1 | 145 | 835 | 980 |
| 0.302 | 0.468 | |
-------------|-----------|-----------|-----------|
Column Total | 480 | 1784 | 2264 |
| 0.212 | 0.788 | |
-------------|-----------|-----------|-----------|

Fisher's Exact Test for Count Data
------------------------------------------------------------
Sample estimate odds ratio: 2.032207

Alternative hypothesis: true odds ratio is not equal to 1
p = 5.086873e-11
95% confidence interval: 1.63051 2.541397

Alternative hypothesis: true odds ratio is less than 1
p = 1
95% confidence interval: 0 2.453014

Alternative hypothesis: true odds ratio is greater than 1
p = 2.85285e-11
95% confidence interval: 1.687073 Inf

> library(gmodels)
> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
> CrossTable(V162005, V161307)

Cell Contents
|-------------------------|
| N |
| Chi-square contribution |
| N / Row Total |
| N / Col Total |
| N / Table Total |
|-------------------------|

Total Observations in Table: 2266

| V161307
V162005 | 1 | 2 | 3 | 4 | Row Total |
-------------|-----------|-----------|-----------|-----------|-----------|
1 | 118 | 299 | 394 | 18 | 829 |
| 10.386 | 2.874 | 3.603 | 9.441 | |
| 0.142 | 0.361 | 0.475 | 0.022 | 0.366 |
| 0.492 | 0.404 | 0.332 | 0.180 | |
| 0.052 | 0.132 | 0.174 | 0.008 | |
-------------|-----------|-----------|-----------|-----------|-----------|
2 | 46 | 191 | 258 | 11 | 506 |
| 1.076 | 3.940 | 0.165 | 5.749 | |
| 0.091 | 0.377 | 0.510 | 0.022 | 0.223 |
| 0.192 | 0.258 | 0.218 | 0.110 | |
| 0.020 | 0.084 | 0.114 | 0.005 | |
-------------|-----------|-----------|-----------|-----------|-----------|
3 | 49 | 159 | 267 | 19 | 494 |
| 0.211 | 0.040 | 0.291 | 0.360 | |
| 0.099 | 0.322 | 0.540 | 0.038 | 0.218 |
| 0.204 | 0.215 | 0.225 | 0.190 | |
| 0.022 | 0.070 | 0.118 | 0.008 | |
-------------|-----------|-----------|-----------|-----------|-----------|
4 | 27 | 92 | 266 | 52 | 437 |
| 8.035 | 18.132 | 6.144 | 55.497 | |
| 0.062 | 0.211 | 0.609 | 0.119 | 0.193 |
| 0.112 | 0.124 | 0.224 | 0.520 | |
| 0.012 | 0.041 | 0.117 | 0.023 | |
-------------|-----------|-----------|-----------|-----------|-----------|
Column Total | 240 | 741 | 1185 | 100 | 2266 |
| 0.106 | 0.327 | 0.523 | 0.044 | |
-------------|-----------|-----------|-----------|-----------|-----------|
> CrossTable(V162005, V161307, prop.t=F, prop.r=F, prob.chisq=F, prop.c=T, fisher=T)

Cell Contents
|-------------------------|
| N |
| Chi-square contribution |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2266

| V161307
V162005 | 1 | 2 | 3 | 4 | Row Total |
-------------|-----------|-----------|-----------|-----------|-----------|
1 | 118 | 299 | 394 | 18 | 829 |
| 10.386 | 2.874 | 3.603 | 9.441 | |
| 0.492 | 0.404 | 0.332 | 0.180 | |
-------------|-----------|-----------|-----------|-----------|-----------|
2 | 46 | 191 | 258 | 11 | 506 |
| 1.076 | 3.940 | 0.165 | 5.749 | |
| 0.192 | 0.258 | 0.218 | 0.110 | |
-------------|-----------|-----------|-----------|-----------|-----------|
3 | 49 | 159 | 267 | 19 | 494 |
| 0.211 | 0.040 | 0.291 | 0.360 | |
| 0.204 | 0.215 | 0.225 | 0.190 | |
-------------|-----------|-----------|-----------|-----------|-----------|
4 | 27 | 92 | 266 | 52 | 437 |
| 8.035 | 18.132 | 6.144 | 55.497 | |
| 0.112 | 0.124 | 0.224 | 0.520 | |
-------------|-----------|-----------|-----------|-----------|-----------|
Column Total | 240 | 741 | 1185 | 100 | 2266 |
| 0.106 | 0.327 | 0.523 | 0.044 | |
-------------|-----------|-----------|-----------|-----------|-----------|
> socialclass<-ifelse(V161307<=2,1,0)
> readings<-ifelse(V162005<=2,1,0)
> CrossTable(readings, socialclass, prop.t=F, prop.r=F, prob.chisq=F, prop.c=T, fisher=T)

Cell Contents
|-------------------------|
| N |
| Chi-square contribution |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2266

| socialclass
readings | 0 | 1 | Row Total |
-------------|-----------|-----------|-----------|
0 | 604 | 327 | 931 |
| 10.955 | 14.350 | |
| 0.470 | 0.333 | |
-------------|-----------|-----------|-----------|
1 | 681 | 654 | 1335 |
| 7.640 | 10.007 | |
| 0.530 | 0.667 | |
-------------|-----------|-----------|-----------|
Column Total | 1285 | 981 | 2266 |
| 0.567 | 0.433 | |
-------------|-----------|-----------|-----------|

Fisher's Exact Test for Count Data
------------------------------------------------------------
Sample estimate odds ratio: 1.77344

Alternative hypothesis: true odds ratio is not equal to 1
p = 5.393131e-11
95% confidence interval: 1.487996 2.115512

Alternative hypothesis: true odds ratio is less than 1
p = 1
95% confidence interval: 0 2.0574

Alternative hypothesis: true odds ratio is greater than 1
p = 3.131874e-11
95% confidence interval: 1.529482 Inf

> library(gmodels)
> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
> CrossTable(V162258,V161307,prop.t=F,prop.r=F,prop.chisq=F,prop.c=T,fisher=T)
Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2259

| V161307
V162258 | 1 | 2 | 3 | 4 | Row Total |
-------------|-----------|-----------|-----------|-----------|-----------|
1 | 42 | 92 | 201 | 33 | 368 |
| 0.176 | 0.124 | 0.170 | 0.330 | |
-------------|-----------|-----------|-----------|-----------|-----------|
2 | 81 | 351 | 627 | 49 | 1108 |
| 0.339 | 0.475 | 0.531 | 0.490 | |
-------------|-----------|-----------|-----------|-----------|-----------|
3 | 66 | 174 | 204 | 10 | 454 |
| 0.276 | 0.235 | 0.173 | 0.100 | |
-------------|-----------|-----------|-----------|-----------|-----------|
4 | 33 | 91 | 124 | 7 | 255 |
| 0.138 | 0.123 | 0.105 | 0.070 | |
-------------|-----------|-----------|-----------|-----------|-----------|
5 | 17 | 31 | 25 | 1 | 74 |
| 0.071 | 0.042 | 0.021 | 0.010 | |
-------------|-----------|-----------|-----------|-----------|-----------|
Column Total | 239 | 739 | 1181 | 100 | 2259 |
| 0.106 | 0.327 | 0.523 | 0.044 | |
-------------|-----------|-----------|-----------|-----------|-----------|

Error in fisher.test(t, alternative = "two.sided") : FEXACT error 501.
The hash table key cannot be computed because the largest key
is larger than the largest representable int.
The algorithm cannot proceed.
Reduce the workspace size or use another algorithm.

polissues2016<-ifelse(V162258>=2,1,0)
> CrossTable(V162258,polissues2016,prop.t=F,prop.r=F,prop.chisq=F,prop.c=T,fisher=T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 3635

| polissues2016
V162258 | 0 | 1 | Row Total |
-------------|-----------|-----------|-----------|
1 | 0 | 582 | 582 |
| 0.000 | 0.248 | |
-------------|-----------|-----------|-----------|
2 | 0 | 1767 | 1767 |
| 0.000 | 0.752 | |
-------------|-----------|-----------|-----------|
3 | 754 | 0 | 754 |
| 0.586 | 0.000 | |
-------------|-----------|-----------|-----------|
4 | 418 | 0 | 418 |
| 0.325 | 0.000 | |
-------------|-----------|-----------|-----------|
5 | 114 | 0 | 114 |
| 0.089 | 0.000 | |
-------------|-----------|-----------|-----------|
Column Total | 1286 | 2349 | 3635 |
| 0.354 | 0.646 | |
-------------|-----------|-----------|-----------|

Error in fisher.test(t, alternative = "two.sided") : FEXACT error 6.
LDKEY is too small for this problem.
Try increasing the size of the workspace.

> socialclass<-ifelse(V161307<=2,1,0)
> CrossTable(polissues2016,socialclass,prop.t=F,prop.r=F,prop.chisq=F,prop.c=T,fisher=T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2259

| socialclass
polissues2016 | 0 | 1 | Row Total |
--------------|-----------|-----------|-----------|
0 | 234 | 134 | 368 |
| 0.183 | 0.137 | |
--------------|-----------|-----------|-----------|
1 | 1047 | 844 | 1891 |
| 0.817 | 0.863 | |
--------------|-----------|-----------|-----------|
Column Total | 1281 | 978 | 2259 |
| 0.567 | 0.433 | |
--------------|-----------|-----------|-----------|

Fisher's Exact Test for Count Data
------------------------------------------------------------
Sample estimate odds ratio: 1.407474

Alternative hypothesis: true odds ratio is not equal to 1
p = 0.004001522
95% confidence interval: 1.111221 1.787712

Alternative hypothesis: true odds ratio is less than 1
p = 0.9985902
95% confidence interval: 0 1.721629

Alternative hypothesis: true odds ratio is greater than 1
p = 0.002051776
95% confidence interval: 1.152663 Inf

> library(gmodels)
> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
> CrossTable(V161307,v162194,prop.t=F,prop.r=F,prop.chisq=F,prop.c=T)
Error in CrossTable(V161307, v162194, prop.t = F, prop.r = F, prop.chisq = F, :
object 'v162194' not found
> CrossTable(V161307,V162257,prop.t=F,prop.r=F,prop.chisq=F,prop.c=T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2258

| V162257
V161307 | 1 | 2 | 3 | 4 | Row Total |
-------------|-----------|-----------|-----------|-----------|-----------|
1 | 36 | 95 | 75 | 33 | 239 |
| 0.081 | 0.088 | 0.125 | 0.239 | |
-------------|-----------|-----------|-----------|-----------|-----------|
2 | 101 | 357 | 231 | 50 | 739 |
| 0.229 | 0.331 | 0.386 | 0.362 | |
-------------|-----------|-----------|-----------|-----------|-----------|
3 | 268 | 582 | 277 | 54 | 1181 |
| 0.606 | 0.539 | 0.463 | 0.391 | |
-------------|-----------|-----------|-----------|-----------|-----------|
4 | 37 | 46 | 15 | 1 | 99 |
| 0.084 | 0.043 | 0.025 | 0.007 | |
-------------|-----------|-----------|-----------|-----------|-----------|
Column Total | 442 | 1080 | 598 | 138 | 2258 |
| 0.196 | 0.478 | 0.265 | 0.061 | |
-------------|-----------|-----------|-----------|-----------|-----------|

> socialclass<-ifelse(V161307<2,1,0)
> polmedia<-ifelse(V162257==4,1,0)
> CrossTable(socialclass,polmedia,prop.t=F,prop.r=F,prop.chisq=F,prop.c=T,fisher=T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 2258

| polmedia
socialclass | 0 | 1 | Row Total |
-------------|-----------|-----------|-----------|
0 | 1914 | 105 | 2019 |
| 0.903 | 0.761 | |
-------------|-----------|-----------|-----------|
1 | 206 | 33 | 239 |
| 0.097 | 0.239 | |
-------------|-----------|-----------|-----------|
Column Total | 2120 | 138 | 2258 |
| 0.939 | 0.061 | |
-------------|-----------|-----------|-----------|

Fisher's Exact Test for Count Data
------------------------------------------------------------
Sample estimate odds ratio: 2.918106

Alternative hypothesis: true odds ratio is not equal to 1
p = 2.66287e-06
95% confidence interval: 1.861251 4.482366

Alternative hypothesis: true odds ratio is less than 1
p = 0.9999992
95% confidence interval: 0 4.205188

Alternative hypothesis: true odds ratio is greater than 1
p = 2.545392e-06
95% confidence interval: 1.998279 Inf

> library(gmodels)
> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
> CrossTable(V162041,V161307, prop.t=F,prop.r=F,prop.chisq=F,prop.c=T,fisher=T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 127

| V161307
V162041 | 1 | 2 | 3 | 4 | Row Total |
-------------|-----------|-----------|-----------|-----------|-----------|
1 | 6 | 15 | 26 | 8 | 55 |
| 0.545 | 0.385 | 0.394 | 0.727 | |
-------------|-----------|-----------|-----------|-----------|-----------|
2 | 3 | 21 | 35 | 3 | 62 |
| 0.273 | 0.538 | 0.530 | 0.273 | |
-------------|-----------|-----------|-----------|-----------|-----------|
3 | 2 | 3 | 5 | 0 | 10 |
| 0.182 | 0.077 | 0.076 | 0.000 | |
-------------|-----------|-----------|-----------|-----------|-----------|
Column Total | 11 | 39 | 66 | 11 | 127 |
| 0.087 | 0.307 | 0.520 | 0.087 | |
-------------|-----------|-----------|-----------|-----------|-----------|

Fisher's Exact Test for Count Data
------------------------------------------------------------
Alternative hypothesis: two.sided
p = 0.2531873

> socialclass<-ifelse(V161307<=2,1,0)
> CrossTable(V162041,V161307, prop.t=F,prop.r=F,prop.chisq=F,prop.c=T,fisher=T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 127

| V161307
V162041 | 1 | 2 | 3 | 4 | Row Total |
-------------|-----------|-----------|-----------|-----------|-----------|
1 | 6 | 15 | 26 | 8 | 55 |
| 0.545 | 0.385 | 0.394 | 0.727 | |
-------------|-----------|-----------|-----------|-----------|-----------|
2 | 3 | 21 | 35 | 3 | 62 |
| 0.273 | 0.538 | 0.530 | 0.273 | |
-------------|-----------|-----------|-----------|-----------|-----------|
3 | 2 | 3 | 5 | 0 | 10 |
| 0.182 | 0.077 | 0.076 | 0.000 | |
-------------|-----------|-----------|-----------|-----------|-----------|
Column Total | 11 | 39 | 66 | 11 | 127 |
| 0.087 | 0.307 | 0.520 | 0.087 | |
-------------|-----------|-----------|-----------|-----------|-----------|

Fisher's Exact Test for Count Data
------------------------------------------------------------
Alternative hypothesis: two.sided
p = 0.2531873

> CrossTable(V162041,V161307, prop.t=F,prop.r=F,prop.chisq=F,prop.c=T,fisher=T)

Cell Contents
|-------------------------|
| N |
| N / Col Total |
|-------------------------|

Total Observations in Table: 127

| V161307
V162041 | 1 | 2 | 3 | 4 | Row Total |
-------------|-----------|-----------|-----------|-----------|-----------|
1 | 6 | 15 | 26 | 8 | 55 |
| 0.545 | 0.385 | 0.394 | 0.727 | |
-------------|-----------|-----------|-----------|-----------|-----------|
2 | 3 | 21 | 35 | 3 | 62 |
| 0.273 | 0.538 | 0.530 | 0.273 | |
-------------|-----------|-----------|-----------|-----------|-----------|
3 | 2 | 3 | 5 | 0 | 10 |
| 0.182 | 0.077 | 0.076 | 0.000 | |
-------------|-----------|-----------|-----------|-----------|-----------|
Column Total | 11 | 39 | 66 | 11 | 127 |
| 0.087 | 0.307 | 0.520 | 0.087 | |
-------------|-----------|-----------|-----------|-----------|-----------|

Fisher's Exact Test for Count Data
------------------------------------------------------------
Alternative hypothesis: two.sided
p = 0.2531873

> socialclass<-ifelse(V161307<=2,1,0)
> .545/.087
[1] 6.264368
> Voted2016<-ifelse(V162041==410)
Error in ifelse(V162041 == 410) :
argument "no" is missing, with no default
> Voted2016<-ifelse(V162041==4,1,0)