Data
load("sejong_poll.rda")
sejong.poll[4:1]
## region class vote counts
## 1 Seoul high yes 21
## 2 Seoul high no 194
## 3 Seoul third.current yes 259
## 4 Seoul third.current no 393
## 5 Seoul third.ex yes 443
## 6 Seoul third.ex no 117
## 7 yuhu ordinary yes 1123
## 8 yuhu ordinary no 71
## 9 gyunggi chief yes 29
## 10 gyunggi chief no 5
## 11 gyunggi ordinary yes 17076
## 12 gyunggi ordinary no 236
## 13 pyungan high no 1
## 14 pyungan chief yes 6
## 15 pyungan chief no 35
## 16 pyungan ordinary yes 1326
## 17 pyungan ordinary no 28474
## 18 hwanghae chief yes 17
## 19 hwanghae chief no 17
## 20 hwanghae ordinary yes 4454
## 21 hwanghae ordinary no 15601
## 22 chungcheong high no 2
## 23 chungcheong chief yes 35
## 24 chungcheong chief no 26
## 25 chungcheong ordinary yes 6982
## 26 chungcheong ordinary no 14013
## 27 kangwon chief yes 5
## 28 kangwon chief no 10
## 29 kangwon ordinary yes 939
## 30 kangwon ordinary no 6888
## 31 hamgil high no 1
## 32 hamgil chief yes 3
## 33 hamgil chief no 14
## 34 hamgil ordinary yes 75
## 35 hamgil ordinary no 7387
## 36 gyungsang chief yes 55
## 37 gyungsang chief no 16
## 38 gyungsang ordinary yes 36262
## 39 gyungsang ordinary no 377
## 40 jeolla high no 2
## 41 jeolla chief yes 42
## 42 jeolla chief no 12
## 43 jeolla ordinary yes 29505
## 44 jeolla ordinary no 257
xtabs(counts~vote,data=sejong.poll)[2:1]
## vote
## yes no
## 98657 74149
round(prop.table(xtabs(counts~vote,data=sejong.poll)[2:1]),digits=3)
## vote
## yes no
## 0.571 0.429
o.vote<-c(2,1)
o.class<-c(2,1,4,5,3)
o.region<-c(9,10,2,8,5,1,7,4,3,6)
xtabs(counts~vote+class,data=sejong.poll)[2:1,c(2,1,4,5,3)]
## class
## vote high chief third.current third.ex ordinary
## yes 21 192 259 443 97742
## no 200 135 393 117 73304
round(prop.table(xtabs(counts~vote+class,data=sejong.poll)[o.vote,o.class],margin=2),digits=3)
## class
## vote high chief third.current third.ex ordinary
## yes 0.095 0.587 0.397 0.791 0.571
## no 0.905 0.413 0.603 0.209 0.429
xtabs(counts~vote+region,data=sejong.poll)[o.vote,o.region]
## region
## vote Seoul yuhu gyunggi pyungan hwanghae chungcheong kangwon hamgil
## yes 723 1123 17105 1332 4471 7017 944 78
## no 704 71 241 28510 15618 14041 6898 7402
## region
## vote gyungsang jeolla
## yes 36317 29547
## no 393 271
round(prop.table(xtabs(counts~vote+region,data=sejong.poll)[o.vote,o.region],margin=2),digits=3)
## region
## vote Seoul yuhu gyunggi pyungan hwanghae chungcheong kangwon hamgil
## yes 0.507 0.941 0.986 0.045 0.223 0.333 0.12 0.01
## no 0.493 0.059 0.014 0.955 0.777 0.667 0.88 0.99
## region
## vote gyungsang jeolla
## yes 0.989 0.991
## no 0.011 0.009
ftable(xtabs(counts~vote+class+region,data=sejong.poll)[o.vote,o.class,o.region])
## region Seoul yuhu gyunggi pyungan hwanghae chungcheong kangwon hamgil gyungsang jeolla
## vote class
## yes high 21 0 0 0 0 0 0 0 0 0
## chief 0 0 29 6 17 35 5 3 55 42
## third.current 259 0 0 0 0 0 0 0 0 0
## third.ex 443 0 0 0 0 0 0 0 0 0
## ordinary 0 1123 17076 1326 4454 6982 939 75 36262 29505
## no high 194 0 0 1 0 2 0 1 0 2
## chief 0 0 5 35 17 26 10 14 16 12
## third.current 393 0 0 0 0 0 0 0 0 0
## third.ex 117 0 0 0 0 0 0 0 0 0
## ordinary 0 71 236 28474 15601 14013 6888 7387 377 257
- Regionwise proportion, check that the coloumn sum calculates up to 1.
ftable(round(prop.table(xtabs(counts~vote+class+region,data=sejong.poll)[o.vote,o.class,o.region],margin=3),digits=3))
## region Seoul yuhu gyunggi pyungan hwanghae chungcheong kangwon hamgil gyungsang jeolla
## vote class
## yes high 0.015 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## chief 0.000 0.000 0.002 0.000 0.001 0.002 0.001 0.000 0.001 0.001
## third.current 0.181 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## third.ex 0.310 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## ordinary 0.000 0.941 0.984 0.044 0.222 0.332 0.120 0.010 0.988 0.990
## no high 0.136 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## chief 0.000 0.000 0.000 0.001 0.001 0.001 0.001 0.002 0.000 0.000
## third.current 0.275 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## third.ex 0.082 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## ordinary 0.000 0.059 0.014 0.954 0.777 0.665 0.878 0.988 0.010 0.009
- Classwise proportion, chaeck that the sum for each class calculates up to 1. This is not what we want.
ftable(round(prop.table(xtabs(counts~vote+class+region,data=sejong.poll)[o.vote,o.class,o.region],margin=2),digits=3))
## region Seoul yuhu gyunggi pyungan hwanghae chungcheong kangwon hamgil gyungsang jeolla
## vote class
## yes high 0.095 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## chief 0.000 0.000 0.089 0.018 0.052 0.107 0.015 0.009 0.168 0.128
## third.current 0.397 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## third.ex 0.791 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## ordinary 0.000 0.007 0.100 0.008 0.026 0.041 0.005 0.000 0.212 0.172
## no high 0.878 0.000 0.000 0.005 0.000 0.009 0.000 0.005 0.000 0.009
## chief 0.000 0.000 0.015 0.107 0.052 0.080 0.031 0.043 0.049 0.037
## third.current 0.603 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## third.ex 0.209 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
## ordinary 0.000 0.000 0.001 0.166 0.091 0.082 0.040 0.043 0.002 0.002
- To compare the vote for each class in each region, and for the convenience of viewing, rearrange the variables, and the margin. See the NaNs.
ftable(xtabs(counts~class+vote+region,data=sejong.poll)[o.class,o.vote,o.region])
## region Seoul yuhu gyunggi pyungan hwanghae chungcheong kangwon hamgil gyungsang jeolla
## class vote
## high yes 21 0 0 0 0 0 0 0 0 0
## no 194 0 0 1 0 2 0 1 0 2
## chief yes 0 0 29 6 17 35 5 3 55 42
## no 0 0 5 35 17 26 10 14 16 12
## third.current yes 259 0 0 0 0 0 0 0 0 0
## no 393 0 0 0 0 0 0 0 0 0
## third.ex yes 443 0 0 0 0 0 0 0 0 0
## no 117 0 0 0 0 0 0 0 0 0
## ordinary yes 0 1123 17076 1326 4454 6982 939 75 36262 29505
## no 0 71 236 28474 15601 14013 6888 7387 377 257
ftable(round(prop.table(xtabs(counts~class+vote+region,data=sejong.poll)[o.class,o.vote,o.region],margin=c(1,3)),digits=3))
## region Seoul yuhu gyunggi pyungan hwanghae chungcheong kangwon hamgil gyungsang jeolla
## class vote
## high yes 0.098 NaN NaN 0.000 NaN 0.000 NaN 0.000 NaN 0.000
## no 0.902 NaN NaN 1.000 NaN 1.000 NaN 1.000 NaN 1.000
## chief yes NaN NaN 0.853 0.146 0.500 0.574 0.333 0.176 0.775 0.778
## no NaN NaN 0.147 0.854 0.500 0.426 0.667 0.824 0.225 0.222
## third.current yes 0.397 NaN NaN NaN NaN NaN NaN NaN NaN NaN
## no 0.603 NaN NaN NaN NaN NaN NaN NaN NaN NaN
## third.ex yes 0.791 NaN NaN NaN NaN NaN NaN NaN NaN NaN
## no 0.209 NaN NaN NaN NaN NaN NaN NaN NaN NaN
## ordinary yes NaN 0.941 0.986 0.044 0.222 0.333 0.120 0.010 0.990 0.991
## no NaN 0.059 0.014 0.956 0.778 0.667 0.880 0.990 0.010 0.009