library(poliscidata)
## Warning: package 'poliscidata' was built under R version 3.6.3
## Registered S3 method overwritten by 'gdata':
##   method         from  
##   reorder.factor gplots

Q1

(Datasets: world, worldD. Variables: democ_regime, frac_eth3, gdp_cap2.) Some countries have democratic regimes, 
and other countries do not. What factors help to explain this difference? One idea is that the type of government 
is shaped by the ethnic and religious diversity in a country?s population. Countries that are relatively 
homogeneous, with most people sharing the same language and religious beliefs, are more likely to develop 
democratic systems than are countries having more linguistic conflicts and religious differences. Consider the 
ethnic heterogeneity hypothesis: Countries with lower levels of ethnic heterogeneity will be more likely to be 
democracies than will countries with higher levels of ethnic heterogeneity.

Q1, Part A

A higher percentage of democracies among countries having lower heterogeneity.

Q1, Part B

xtp(world, democ_regime, frac_eth3)

##    Cell Contents 
## |-------------------------|
## |                   Count | 
## |          Column Percent | 
## |-------------------------|
## 
## ================================================
##                 frac_eth3
## democ_regime       Low   Medium     High   Total
## ------------------------------------------------
## No                 11       21       29      61 
##                 23.91%   39.62%   55.77%        
## ------------------------------------------------
## Yes                35       32       23      90 
##                 76.09%   60.38%   44.23%        
## ------------------------------------------------
## Total              46       53       52     151 
##                 30.46%   35.10%   34.44%        
## ================================================

Q1, Part C

Correct

Q1, Part D

Higher level of ethnic fractionalization correspond to lower percentages of democratic regimes.  76.1% of countries with low ethnic fractionalization are democracies, but this figure declines to 60.4% among countries with medium-level ethnic fractionalization and further declines to 44.2% among countries with high ethnic fractionalization.  

Q1, Part E

xtabC(~democ_regime + frac_eth3 + gdp_cap2, worldD)
## , , gdp_cap2 = Low
## 
##             frac_eth3
## democ_regime    Low Medium   High
##        No     53.33  59.09  53.66
##        Yes    46.67  40.91  46.34
##        Total 100.00 100.00 100.00
##        Count  15.00  22.00  41.00
## 
## , , gdp_cap2 = High
## 
##             frac_eth3
## democ_regime    Low Medium High
##        No      9.68  21.43   60
##        Yes    90.32  78.57   40
##        Total 100.00 100.00  100
##        Count  31.00  28.00   10

Q1, Part F

world$democ.yes <- as.numeric(world$democ == "Yes")
world$democ.yes <- 100*world$democ.yes
worldD <- svydesign(id=~1, data=world)
## Warning in svydesign.default(...): No weights or probabilities supplied,
## assuming equal probability
world_10 <- head(world,10)
print(world_10,digits = NULL,
      quote = FALSE, right = TRUE, row.names = TRUE, max = NULL)
##        country gini10    dem_level4 dem_rank14 dem_score14 lifeex_f lifeex_m
## 1  Afghanistan   29.4 Authoritarian        151        2.77    45.25    44.79
## 2      Albania   33.0        Hybrid         88        5.67    80.30    74.82
## 3      Algeria   35.3 Authoritarian        117        3.83    76.31    72.78
## 4       Angola   58.6 Authoritarian        133        3.35    39.83    37.74
## 5    Argentina   48.8    Part Democ         52        6.84    80.36    73.71
## 6      Armenia   30.2        Hybrid        113        4.13    77.31    69.59
## 7    Australia   35.2    Full Democ          9        9.01    84.35    79.40
## 8      Austria   29.1    Full Democ         14        8.54    82.84    76.87
## 9   Azerbaijan     NA Authoritarian        148        2.83    72.01    63.20
## 10     Bahrain     NA Authoritarian        147        2.87    80.33    76.03
##    literacy     oil pop_0_14 pop_15_64 pop_65_older fertility govregrel
## 1      28.1       0     42.3      55.3          2.4      5.39    10.000
## 2        NA    5400     21.4      68.1         10.5      1.48     0.000
## 3      69.9 2125000     24.2      70.6          5.2      1.75     8.611
## 4      67.4 1948000     43.2      54.1          2.7      5.97     0.556
## 5      97.2  796300     25.4      63.6         11.0      2.31     0.000
## 6      99.4       0     17.6      72.4         10.1      1.37     6.944
## 7      99.0  589200     18.3      67.7         14.0      1.78     0.000
## 8      98.0   21880     14.0      67.7         18.2      1.40     1.389
## 9      98.8 1011000     23.2      70.3          6.4      2.02     7.222
## 10     86.5   48560     20.5      77.0          2.6      1.88     3.889
##                         regionun           religoin spendeduc spendhealth
## 1                           Asia             Muslim        NA         1.8
## 2                         Europe             Muslim       2.9         2.9
## 3                         Africa             Muslim       4.3         3.6
## 4                         Africa           Catholic       2.6         2.0
## 5        Latin America/Caribbean           Catholic       4.9         5.1
## 6                           Asia Orthodox Christian       3.0         2.1
## 7  Australia/New Zealand/Oceania           Catholic       4.7         6.0
## 8                         Europe           Catholic       5.4         7.7
## 9                           Asia             Muslim       1.9         1.0
## 10                          Asia             Muslim       2.9         2.6
##    spendmil   hdi pop_age sexratio pop_total pop_urban gender_unequal
## 1       1.9 0.349    16.9    106.0      29.1      22.6          0.797
## 2       2.0 0.719    30.0    107.0       3.2      51.9          0.545
## 3       3.0 0.677    26.2    104.6      35.4      66.5          0.594
## 4       3.0 0.403    17.4     99.9      19.0      58.5             NA
## 5       0.8 0.775    30.4    103.6      40.7      92.4          0.534
## 6       3.3 0.695    32.0    116.5       3.1      64.2          0.570
## 7       1.8 0.937    37.8    105.3      21.5      89.1          0.296
## 8       0.9 0.851    41.8    105.4       8.4      67.6          0.300
## 9       3.8 0.713    28.4    115.6       8.9      51.9          0.553
## 10      3.0 0.801    28.1    105.2       0.8      88.6          0.512
##    gender_unequal_rank arda lifeex_total debt       colony confidence
## 1                  134    1        45.02   NA           UK         NA
## 2                   61    3        77.41 59.3 Soviet Union  49.335926
## 3                   70    4        74.50 25.7       France  52.055735
## 4                   NA    7        38.76 20.3     Portugal         NA
## 5                   60   11        76.95 50.3        Spain   7.299325
## 6                   66   12        73.23   NA Soviet Union  27.132735
## 7                   18   14        81.81 22.4           UK  46.838886
## 8                   19   15        79.78 70.4        Other  49.680190
## 9                   62   16        67.36  4.6 Soviet Union  54.168485
## 10                  55   18        78.15 59.2           UK         NA
##                                             decent08 dem_other dem_other5 democ
## 1                                 No local elections      10.5        10%    No
## 2      Legislature and executive are locally elected      63.0 Approx 60%   Yes
## 3  Legislature is elected but executive is appointed      40.8 Approx 40%    No
## 4                                 No local elections      40.8 Approx 40%    No
## 5                                               <NA>      87.5 Approx 90%   Yes
## 6      Legislature and executive are locally elected      63.0 Approx 60%   Yes
## 7  Legislature is elected but executive is appointed      58.3 Approx 60%   Yes
## 8                                               <NA>     100.0       100%   Yes
## 9  Legislature is elected but executive is appointed      63.0 Approx 60%    No
## 10 Legislature is elected but executive is appointed      10.5        10%    No
##    democ11 democ_regime democ_regime08    district_size3 durable effectiveness
## 1       NA           No             No     single member       4      13.71158
## 2        9          Yes            Yes              <NA>       3      35.46099
## 3        3           No             No 6 or more members       5      32.62411
## 4        2           No             No              <NA>       3      19.14894
## 5        8          Yes            Yes 6 or more members      17      34.98818
## 6        5          Yes            Yes              <NA>       2      36.64303
## 7       10          Yes            Yes     single member      99      90.07092
## 8       10          Yes            Yes 6 or more members      54      88.88889
## 9        0           No             No              <NA>       5      23.87707
## 10       0           No             No     single member      25      65.01182
##     enpp3_democ enpp3_democ08 dnpp_3              eu fhrate04_rev fhrate08_rev
## 1          <NA>          <NA>     NA      Not member          2.5            3
## 2   1-3 parties   1-3 parties      1      Not member          5.0            8
## 3          <NA>          <NA>      3      Not member          2.5            3
## 4          <NA>          <NA>      1      Not member          2.5            3
## 5   1-3 parties   1-3 parties      1      Not member          6.0           10
## 6  6-11 parties  6-11 parties      3      Not member          3.5            4
## 7   1-3 parties   1-3 parties      1      Not member          7.0           12
## 8   4-5 parties   4-5 parties      2 EU Member state          7.0           12
## 9          <NA>          <NA>      1      Not member          2.5            3
## 10         <NA>          <NA>     NA      Not member          3.0            4
##    frac_eth frac_eth2 frac_eth3 free_business free_corrupt free_finance
## 1    0.7693      High      High            NA           NA           NA
## 2    0.2204       Low       Low          68.0           34           70
## 3    0.3394       Low    Medium          71.2           32           30
## 4    0.7867      High      High          43.4           19           40
## 5    0.2550       Low       Low          62.1           29           30
## 6    0.1272       Low       Low          83.4           29           70
## 7    0.0929       Low       Low          90.3           87           90
## 8    0.1068       Low       Low          73.6           81           70
## 9    0.2047       Low       Low          74.6           19           40
## 10   0.5021      High    Medium          77.8           54           80
##    free_fiscal free_govspend free_invest free_labor free_monetary free_property
## 1           NA            NA          NA         NA            NA            NA
## 2         92.6          74.2          70       52.1          78.7            35
## 3         83.5          73.4          45       56.4          77.2            30
## 4         85.1          62.8          35       45.2          62.6            20
## 5         69.5          75.6          45       50.1          61.2            20
## 6         89.3          90.9          75       70.6          72.9            30
## 7         61.4          64.9          80       94.9          82.7            90
## 8         51.2          28.8          75       79.1          79.3            90
## 9         79.5          77.5          55       82.5          62.7            20
## 10        99.9          80.8          65       89.4          73.4            60
##    free_trade free_overall free_overall_4 gdp08 gdp_10_thou gdp_cap2 gdp_cap3
## 1          NA           NA           <NA>  30.6          NA     <NA>     <NA>
## 2        85.8         66.0          MidHi  24.3      0.1535      Low   Middle
## 3        70.7         56.9         MidLow 276.0      0.1785      Low   Middle
## 4        70.4         48.4            Low 106.3      0.0857      Low   Middle
## 5        69.5         51.2            Low 571.5      0.2797     High   Middle
## 6        80.5         69.2           High  18.7      0.0771      Low      Low
## 7        85.1         82.6           High 762.6      2.0822     High     High
## 8        87.5         71.6           High 318.4      2.5356     High     High
## 9        77.1         58.8         MidLow  76.1      0.0745      Low      Low
## 10       82.9         76.3           High  26.9      1.1007     High     High
##    gdpcap2_08 gdpcap3_08 gdpcap08_2 gdppcap08 gdppcap08_3 gender_equal3 gini04
## 1         Low        Low        Low        NA          NA          <NA>     NA
## 2         Low        Mid        Low      7715           2          <NA>   28.2
## 3        High        Mid       High      8033           2          <NA>   35.3
## 4        High        Mid       High      5899           2          <NA>     NA
## 5        High       High       High     14333           3          High   52.2
## 6         Low        Mid        Low      6070           2          <NA>   37.9
## 7        High       High       High     35677           3          High   35.2
## 8        High       High       High     38152           3          High   30.0
## 9        High        Mid       High      8765           2          <NA>   36.5
## 10       High       High       High     34605           3           Low     NA
##    gini08   hi_gdp indy muslim     natcode              oecd      pmat12_3
## 1      NA     <NA> 1919    Yes afghanistan        Not member          <NA>
## 2    31.1  Low GDP 1991    Yes     albania        Not member  Low post-mat
## 3    35.3  Low GDP 1962    Yes     algeria        Not member          <NA>
## 4      NA  Low GDP 1975     No      angola        Not member          <NA>
## 5    51.3 High GDP 1816     No   argentina        Not member High post-mat
## 6    33.8  Low GDP 1991     No     armenia        Not member  Low post-mat
## 7    35.2 High GDP 1901     No   australia OECD Member state High post-mat
## 8    29.1 High GDP 1156     No     austria OECD Member state High post-mat
## 9    36.5  Low GDP 1991    Yes  azerbaijan        Not member  Low post-mat
## 10     NA High GDP 1971    Yes     bahrain        Not member          <NA>
##    polity pr_sys protact3        regime_type3 rich_democ unions unnetgro
## 1      NA     No     <NA>        Dictatorship         NA     NA       NA
## 2       9     No Moderate Parliamentary democ          0     NA    21329
## 3       2    Yes     <NA>        Dictatorship          0     NA     2633
## 4      -2    Yes     <NA>        Dictatorship          0     NA     3567
## 5       8    Yes Moderate  Presidential democ          1   25.4      331
## 6       5     No     High                <NA>          0     NA      378
## 7      10     No     High Parliamentary democ          1   28.6       66
## 8      10    Yes Moderate Parliamentary democ          1   36.6      120
## 9      -7     No      Low        Dictatorship          0   75.4    20206
## 10     -8     No     <NA>        Dictatorship          0     NA      907
##    unnetuse unpovnpl unremitp unremitt vi_rel3 votevap00s votevap90s women05
## 1       1.7     42.0       NA       NA    <NA>         NA         NA      NA
## 2      23.9     18.5      476     12.2  20-50%      59.56   85.25755     6.4
## 3      11.9       NA       64      1.3    >50%         NA   71.43356      NA
## 4       3.1       NA        5      0.1    <NA>         NA   88.28227      NA
## 5      28.1       NA       17      0.2  20-50%      70.88   79.68567    33.7
## 6       6.2     50.9      345      8.9  20-50%         NA   53.32164     5.3
## 7      70.8       NA      220      0.5  20-50%      82.74   81.36468    24.7
## 8      71.2       NA      389      0.8  20-50%      75.61   75.48064    33.9
## 9      28.2     49.6      179      3.4  20-50%         NA   79.18028      NA
## 10     51.9       NA       NA       NA    <NA>         NA         NA      NA
##    women09 women13 ipu_wom13_all womyear       womyear2 dem_economist democ.yes
## 1       NA      NA          27.7      NA           <NA>             0         0
## 2     16.4    15.7          15.7    1920 1944 or before             0       100
## 3       NA      NA          31.6    1962     After 1944             0         0
## 4       NA      NA          34.1    1975     After 1944             0         0
## 5     41.6    37.4          37.4    1947     After 1944             1       100
## 6      8.4    10.7          10.7    1921 1944 or before             0       100
## 7     26.7    24.7          24.7    1902 1944 or before             1       100
## 8     27.9    27.9          27.9    1918 1944 or before             1       100
## 9       NA      NA          16.0    1921 1944 or before             0         0
## 10      NA      NA          10.0    1973     After 1944             0         0
##       country1
## 1  Afghanistan
## 2      Albania
## 3      Algeria
## 4       Angola
## 5    Argentina
## 6      Armenia
## 7    Australia
## 8      Austria
## 9   Azerbaijan
## 10     Bahrain

Q1, Part G

iplotC(~democ.yes, ~frac_eth3+gdp_cap2, worldD, 
        democ.yes~gdp_cap2+frac_eth3,
        xlab="Fractionalization",
        ylab="Percentage of Democracies",
        main="Percentage of Democracies by \n Fractionalization and GDP")
 legend("topright", legend=c("Low GDP Countries", "High GDP Countries"), 
        lty=c(1,2), bty="n")

Q1, Part H

Interaction

Q1, Part I

Based on the controlled cross-tabulation and the multiple line chart, the effect of ethnic fractionalization on the likelihood a county is democratic depends on economic development.  It is only among high GDP countries that ethnic fractionalization decreases the percentages of democracies.

Q2

(Datasets: nesD, nes. Variables: polknow3, dhs_threat3, ftgr_tea.) Given the tea party movement?s deep 
skepticism of government activism, it seems plausible to hypothesize that individuals who regard the 
government as a threat would have warmer feelings toward the tea party than would those who do not think 
the government poses a threat. Of course, people would need to be reasonably well informed about politics 
to make the connection between their assessment of government threat and their evaluation of the tea party. 
When we control for political knowledge (control variable), we may find that the relationship between tea 
party ratings (dependent variable) and perceptions of government threat (independent variable) gets stronger 
as knowledge increases. In other words, interaction could be occurring in this set of relationships. Consider 
two propositions and an ancillary hypothesis.
    Proposition 1: At all levels of political knowledge (nesD variable, polknow3), individuals who perceive 
    the government as a threat (dhs_threat3) will give the tea party higher ratings (ftgr_tea) than will people 
    who do not regard the government as a threat.

    Proposition 2: The relationship between perceived threat and tea party ratings will be weaker for lower-
    knowledge respondents than for higher-knowledge respondents.

Ancillary Hypothesis: In a comparison of individuals, those with higher levels of political knowledge are less likely 
to regard the government as a threat than are those with lower levels of political knowledge.
The dependent variable: the tea party feeling thermometer (ftgr_tea), which runs from 0 (cold or negative feelings) 
to 100 (warm or positive feelings). The independent variable dhs_threat3, which captures assessments of government?s 
threat with three ordinal levels?government represents no threat ("None"), a moderate threat ("Mod"), or 
an extreme threat ("Extrm"). Political knowledge is also a three-level ordinal: low ("Low know"), moderate 
("Mid know"), and high knowledge ("High know").

Q2, Part A

imeansC(~ftgr_tea, ~ dhs_threat3+polknow3 , nesD)
##                             polknow3 Low know Mid know High know
## dhs_threat3                                                     
## None        survey::svymean             39.02    34.96     24.34
## Mod         survey::svymean             42.40    45.64     41.84
## Extrm       survey::svymean             44.16    55.32     63.92

Q2, Part B

Proposition 1 is supported

Q2, Part C

At all levels of political knowledge, as measured by the dhs_threat3 variable, individuals who perceive the government as a threat tend to give the tea party higher ratings than people who do not regard the government as a threat.  Among respondents with low political knowledge, those who perceive the government as no threat give the tea party a 39.02 average rating on a feeling thermometer; those who perceive the government as a moderate threat give the tea party an average 42.90 rating, while those who see the government as an extreme threat rate the tea party 44.16 on average.  We observe a similar relationship between perceived threat and tea party ratings among those with medium and high political knowledge.

Q2, Part D

Proposition 2 is supported 

Q2, Part E

Although there is a positive relationship between perceived threat of government and tea party ratings for respondents with all levels of political knowledge, the strength of this relationship varies with political knowledge.  The difference in average tea party ratings between those who perceive the government as an extreme threat and no threat (44.16 – 39.02) in the low political knowledge category is 5.14.  In the medium knowledge group, there’s a greater difference, 20.36.  Among those with high political knowledge, the difference is still greater, 39.58.

Q2, Part F

xtp(nes, dhs_threat3, polknow3, wt)

##    Cell Contents 
## |-------------------------|
## |                   Count | 
## |          Column Percent | 
## |-------------------------|
## 
## ======================================================
##                polknow3
## dhs_threat3    Low know   Mid know   High know   Total
## ------------------------------------------------------
## None               388        673         670    1731 
##                  47.84%     45.47%      43.93%        
## ------------------------------------------------------
## Mod                255        486         484    1225 
##                  31.44%     32.84%      31.74%        
## ------------------------------------------------------
## Extrm              168        321         371     860 
##                  20.72%     21.69%      24.33%        
## ------------------------------------------------------
## Total              811       1480        1525    3816 
##                  21.25%     38.78%      39.96%        
## ======================================================

Q2, Part G

The hypothesis is not supported.  Those with a higher political knowledge are more likely to not see government as a threat. 47.84% for low knowledge vs. 43.93 with high knowledge.

Q2, Part H

iplotC(~ftgr_tea, ~dhs_threat3+polknow3, nesD,
        ftgr_tea~polknow3+dhs_threat3,
        xlab="Perception of Government Threat",
        ylab="Average Tea Party Rating",
        main="")
 legend("topleft", legend=c("Low", "Medium", "High"), 
        title="Political Knowledge", lty=c(1,2,3), bty="n")