Andrew Heiss — Apr 30, 2013, 12:54 PM
# All files required for full replication are available at https://github.com/andrewheiss/Attitudes-in-the-Arab-World
#--------------------------
# Load data and libraries
#--------------------------
library(car)
Loading required package: MASS
Loading required package: nnet
library(ggplot2)
library(reshape2)
library(plyr)
library(xtable)
setwd("~/Documents/Duke 2012-2013/Spring 2013/Polsci 733/Attitudes in the Arab World Replication")
load("Barometer.RData")
set.seed(1234)
#---------------
# Build models
#---------------
# Save the formulas so they can be reused more easily
form.logit <- formula(autocracy.bad ~ quran + prime.minister +
citizen.influence + maintain.order +
education + age + family.econ)
form.ologit <- formula(autocracy.bad.ordinal ~ quran + prime.minister +
citizen.influence + maintain.order +
education + age + family.econ)
# Corresponding human-readable names for nicer output
nice.names <- c("Read Qur'an", "Prime minister", "Citizen influence",
"Maintain order", "Education", "Age", "Family economic status")
# logit models for all countries combined
all.countries.logit <- glm(form.logit, data=barometer,
subset=(dem.best==1), family=binomial(link="logit"))
original4.logit <- glm(form.logit, data=barometer.original4,
subset=(dem.best==1), family=binomial(link="logit"))
# ologit models for all countries combined
all.countries <- polr(form.ologit, data=barometer,
subset=(dem.best==1), method="logistic", Hess=TRUE)
original4 <- polr(form.ologit, data=barometer.original4,
subset=(dem.best==1), method="logistic", Hess=TRUE)
# Function to create a list of individual country models
# bquote() + .() passes the actual names of the arguments into the model call; eval() actually runs the model
run.country.models.logit <- function(country, form) {
model <- bquote(glm(.(form), data=barometer,
subset=(dem.best==1 & country.name==.(country)),
family=binomial(link="logit")))
eval(model)
}
run.country.models <- function(country, form) {
model <- bquote(polr(.(form), data=barometer,
subset=(dem.best==1 & country.name==.(country)),
method="logistic", Hess=TRUE))
eval(model)
}
# Create a list of models for all countries, given a model formula
country.models.logit <- lapply(levels(barometer$country.name), FUN=run.country.models.logit, form=form.logit)
names(country.models.logit) <- levels(barometer$country.name) # Name the list for convenience
country.models <- lapply(levels(barometer$country.name), FUN=run.country.models, form=form.ologit)
names(country.models) <- levels(barometer$country.name) # Name the list for convenience
#-----------------------
# Summarize all models
#-----------------------
summary(all.countries.logit)
Call:
glm(formula = form.logit, family = binomial(link = "logit"),
data = barometer, subset = (dem.best == 1))
Deviance Residuals:
Min 1Q Median 3Q Max
-2.709 0.353 0.449 0.552 1.125
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.2777 0.3141 -4.07 4.7e-05 ***
quran 0.0324 0.0374 0.87 0.3864
prime.minister 0.1148 0.0424 2.71 0.0068 **
citizen.influence 0.1174 0.0510 2.30 0.0214 *
maintain.order 0.5225 0.0543 9.63 < 2e-16 ***
education 0.2217 0.0322 6.89 5.4e-12 ***
age 0.0336 0.0362 0.93 0.3545
family.econ 0.0922 0.0634 1.45 0.1459
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 3271.9 on 4352 degrees of freedom
Residual deviance: 3102.4 on 4345 degrees of freedom
(1710 observations deleted due to missingness)
AIC: 3118
Number of Fisher Scoring iterations: 5
summary(original4.logit)
Call:
glm(formula = form.logit, family = binomial(link = "logit"),
data = barometer.original4, subset = (dem.best == 1))
Deviance Residuals:
Min 1Q Median 3Q Max
-2.584 0.412 0.520 0.618 1.147
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.0491 0.3516 -2.98 0.0028 **
quran 0.0477 0.0410 1.16 0.2445
prime.minister 0.0487 0.0475 1.03 0.3044
citizen.influence 0.2281 0.0568 4.02 5.9e-05 ***
maintain.order 0.4325 0.0586 7.38 1.6e-13 ***
education 0.1919 0.0351 5.46 4.8e-08 ***
age 0.0135 0.0392 0.34 0.7304
family.econ 0.0180 0.0680 0.27 0.7908
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 2676.5 on 3062 degrees of freedom
Residual deviance: 2565.8 on 3055 degrees of freedom
(1294 observations deleted due to missingness)
AIC: 2582
Number of Fisher Scoring iterations: 4
summary(all.countries)
Call:
polr(formula = form.ologit, data = barometer, subset = (dem.best ==
1), Hess = TRUE, method = "logistic")
Coefficients:
Value Std. Error t value
quran 0.05984 0.0241 2.487
prime.minister 0.14896 0.0268 5.558
citizen.influence -0.00763 0.0320 -0.238
maintain.order 0.46795 0.0377 12.421
education 0.16600 0.0195 8.528
age 0.04498 0.0231 1.950
family.econ 0.11129 0.0403 2.763
Intercepts:
Value Std. Error t value
Very good|Good -0.396 0.216 -1.830
Good|Bad 0.895 0.209 4.282
Bad|Very bad 2.904 0.212 13.669
Residual Deviance: 8831.73
AIC: 8851.73
(1710 observations deleted due to missingness)
summary(original4)
Call:
polr(formula = form.ologit, data = barometer.original4, subset = (dem.best ==
1), Hess = TRUE, method = "logistic")
Coefficients:
Value Std. Error t value
quran 0.04441 0.0283 1.567
prime.minister 0.09886 0.0324 3.050
citizen.influence 0.11350 0.0386 2.942
maintain.order 0.43344 0.0437 9.914
education 0.12212 0.0227 5.368
age -0.01345 0.0269 -0.500
family.econ -0.00591 0.0469 -0.126
Intercepts:
Value Std. Error t value
Very good|Good -0.733 0.256 -2.867
Good|Bad 0.539 0.250 2.155
Bad|Very bad 2.542 0.254 10.004
Residual Deviance: 6697.91
AIC: 6717.91
(1294 observations deleted due to missingness)
lapply(country.models.logit, summary)
$Jordan
Call:
glm(formula = autocracy.bad ~ quran + prime.minister + citizen.influence +
maintain.order + education + age + family.econ, family = binomial(link = "logit"),
data = barometer, subset = (dem.best == 1 & country.name ==
"Jordan"))
Deviance Residuals:
Min 1Q Median 3Q Max
-2.791 -0.671 0.518 0.699 1.697
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.8477 0.6454 -4.41 1.0e-05 ***
quran 0.0427 0.0850 0.50 0.615
prime.minister 0.0812 0.1029 0.79 0.430
citizen.influence 0.4678 0.1121 4.17 3.0e-05 ***
maintain.order 0.9720 0.1225 7.93 2.1e-15 ***
education 0.1073 0.0725 1.48 0.139
age 0.0844 0.0780 1.08 0.279
family.econ -0.2292 0.1354 -1.69 0.091 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 781.04 on 692 degrees of freedom
Residual deviance: 664.21 on 685 degrees of freedom
(309 observations deleted due to missingness)
AIC: 680.2
Number of Fisher Scoring iterations: 4
$Palestine
Call:
glm(formula = autocracy.bad ~ quran + prime.minister + citizen.influence +
maintain.order + education + age + family.econ, family = binomial(link = "logit"),
data = barometer, subset = (dem.best == 1 & country.name ==
"Palestine"))
Deviance Residuals:
Min 1Q Median 3Q Max
-2.313 0.442 0.512 0.596 0.890
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.4943 0.6755 0.73 0.46432
quran 0.1191 0.0905 1.32 0.18808
prime.minister 0.0605 0.0926 0.65 0.51339
citizen.influence -0.0719 0.1205 -0.60 0.55078
maintain.order 0.4059 0.1215 3.34 0.00084 ***
education 0.0680 0.0755 0.90 0.36772
age -0.0325 0.0742 -0.44 0.66161
family.econ -0.0542 0.1216 -0.45 0.65569
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 732.45 on 887 degrees of freedom
Residual deviance: 716.40 on 880 degrees of freedom
(172 observations deleted due to missingness)
AIC: 732.4
Number of Fisher Scoring iterations: 4
$Algeria
Call:
glm(formula = autocracy.bad ~ quran + prime.minister + citizen.influence +
maintain.order + education + age + family.econ, family = binomial(link = "logit"),
data = barometer, subset = (dem.best == 1 & country.name ==
"Algeria"))
Deviance Residuals:
Min 1Q Median 3Q Max
-2.756 0.286 0.348 0.426 0.907
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.07295 1.13307 0.95 0.344
quran -0.00424 0.13801 -0.03 0.975
prime.minister 0.11096 0.15662 0.71 0.479
citizen.influence -0.05787 0.15613 -0.37 0.711
maintain.order 0.58420 0.17806 3.28 0.001 **
education 0.14684 0.11064 1.33 0.184
age 0.03402 0.13582 0.25 0.802
family.econ -0.39173 0.23758 -1.65 0.099 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 332.19 on 615 degrees of freedom
Residual deviance: 316.13 on 608 degrees of freedom
(499 observations deleted due to missingness)
AIC: 332.1
Number of Fisher Scoring iterations: 5
$Morocco
Call:
glm(formula = autocracy.bad ~ quran + prime.minister + citizen.influence +
maintain.order + education + age + family.econ, family = binomial(link = "logit"),
data = barometer, subset = (dem.best == 1 & country.name ==
"Morocco"))
Deviance Residuals:
Min 1Q Median 3Q Max
-2.510 0.393 0.507 0.623 0.983
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.3983 0.7836 0.51 0.611
quran -0.0409 0.0759 -0.54 0.590
prime.minister -0.0092 0.0890 -0.10 0.918
citizen.influence 0.5210 0.1057 4.93 8.3e-07 ***
maintain.order -0.1546 0.1306 -1.18 0.237
education 0.1565 0.0791 1.98 0.048 *
age 0.0242 0.0716 0.34 0.736
family.econ 0.0962 0.1464 0.66 0.511
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 752.96 on 865 degrees of freedom
Residual deviance: 717.62 on 858 degrees of freedom
(314 observations deleted due to missingness)
AIC: 733.6
Number of Fisher Scoring iterations: 5
$Lebanon
Call:
glm(formula = autocracy.bad ~ quran + prime.minister + citizen.influence +
maintain.order + education + age + family.econ, family = binomial(link = "logit"),
data = barometer, subset = (dem.best == 1 & country.name ==
"Lebanon"))
Deviance Residuals:
Min 1Q Median 3Q Max
-3.019 0.141 0.193 0.268 0.990
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.6238 1.3701 1.19 0.2359
quran -0.4542 0.1558 -2.92 0.0035 **
prime.minister -0.0134 0.1623 -0.08 0.9343
citizen.influence -0.0273 0.1808 -0.15 0.8800
maintain.order 0.8698 0.2105 4.13 3.6e-05 ***
education 0.1235 0.1363 0.91 0.3647
age -0.0636 0.1385 -0.46 0.6462
family.econ 0.2391 0.2543 0.94 0.3470
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 280.39 on 956 degrees of freedom
Residual deviance: 247.07 on 949 degrees of freedom
(144 observations deleted due to missingness)
AIC: 263.1
Number of Fisher Scoring iterations: 7
$Yemen
Call:
glm(formula = autocracy.bad ~ quran + prime.minister + citizen.influence +
maintain.order + education + age + family.econ, family = binomial(link = "logit"),
data = barometer, subset = (dem.best == 1 & country.name ==
"Yemen"))
Deviance Residuals:
Min 1Q Median 3Q Max
-3.017 0.248 0.320 0.416 0.882
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.5283 1.5541 1.63 0.1038
quran 0.1593 0.2209 0.72 0.4710
prime.minister 0.1103 0.2122 0.52 0.6033
citizen.influence -0.6709 0.2403 -2.79 0.0052 **
maintain.order 0.5400 0.2642 2.04 0.0410 *
education -0.1097 0.1577 -0.70 0.4865
age 0.0696 0.2412 0.29 0.7729
family.econ -0.0211 0.3355 -0.06 0.9499
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 177.54 on 332 degrees of freedom
Residual deviance: 163.79 on 325 degrees of freedom
(272 observations deleted due to missingness)
AIC: 179.8
Number of Fisher Scoring iterations: 6
lapply(country.models, summary)
$Jordan
Call:
polr(formula = autocracy.bad.ordinal ~ quran + prime.minister +
citizen.influence + maintain.order + education + age + family.econ,
data = barometer, subset = (dem.best == 1 & country.name ==
"Jordan"), Hess = TRUE, method = "logistic")
Coefficients:
Value Std. Error t value
quran 0.03335 0.0649 0.5142
prime.minister 0.04400 0.0763 0.5770
citizen.influence 0.46066 0.0859 5.3643
maintain.order 0.74877 0.0977 7.6674
education 0.15915 0.0532 2.9910
age -0.00135 0.0575 -0.0235
family.econ -0.16199 0.1030 -1.5727
Intercepts:
Value Std. Error t value
Very good|Good 0.716 0.501 1.428
Good|Bad 2.387 0.504 4.735
Bad|Very bad 4.822 0.530 9.090
Residual Deviance: 1534.25
AIC: 1554.25
(309 observations deleted due to missingness)
$Palestine
Call:
polr(formula = autocracy.bad.ordinal ~ quran + prime.minister +
citizen.influence + maintain.order + education + age + family.econ,
data = barometer, subset = (dem.best == 1 & country.name ==
"Palestine"), Hess = TRUE, method = "logistic")
Coefficients:
Value Std. Error t value
quran 0.016483 0.0588 0.28020
prime.minister -0.002052 0.0605 -0.03394
citizen.influence -0.150830 0.0835 -1.80680
maintain.order 0.280937 0.0852 3.29762
education 0.096911 0.0506 1.91592
age 0.000443 0.0502 0.00882
family.econ -0.021817 0.0821 -0.26585
Intercepts:
Value Std. Error t value
Very good|Good -2.702 0.495 -5.461
Good|Bad -1.047 0.468 -2.239
Bad|Very bad 1.263 0.467 2.704
Residual Deviance: 1889.77
AIC: 1909.77
(172 observations deleted due to missingness)
$Algeria
Call:
polr(formula = autocracy.bad.ordinal ~ quran + prime.minister +
citizen.influence + maintain.order + education + age + family.econ,
data = barometer, subset = (dem.best == 1 & country.name ==
"Algeria"), Hess = TRUE, method = "logistic")
Coefficients:
Value Std. Error t value
quran -0.0480 0.0735 -0.654
prime.minister 0.1229 0.0834 1.474
citizen.influence -0.1027 0.0846 -1.214
maintain.order 0.4374 0.0998 4.382
education 0.1085 0.0590 1.837
age -0.0503 0.0722 -0.697
family.econ -0.0791 0.1318 -0.600
Intercepts:
Value Std. Error t value
Very good|Good -2.336 0.665 -3.514
Good|Bad -1.191 0.634 -1.879
Bad|Very bad 1.007 0.628 1.605
Residual Deviance: 1106.14
AIC: 1126.14
(499 observations deleted due to missingness)
$Morocco
Call:
polr(formula = autocracy.bad.ordinal ~ quran + prime.minister +
citizen.influence + maintain.order + education + age + family.econ,
data = barometer, subset = (dem.best == 1 & country.name ==
"Morocco"), Hess = TRUE, method = "logistic")
Coefficients:
Value Std. Error t value
quran -0.06749 0.0515 -1.309
prime.minister 0.01467 0.0613 0.239
citizen.influence 0.32623 0.0738 4.418
maintain.order 0.19096 0.0931 2.050
education 0.01473 0.0475 0.310
age 0.00952 0.0498 0.191
family.econ 0.01084 0.0968 0.112
Intercepts:
Value Std. Error t value
Very good|Good -1.187 0.544 -2.180
Good|Bad -0.324 0.538 -0.602
Bad|Very bad 1.286 0.540 2.383
Residual Deviance: 1879.08
AIC: 1899.08
(314 observations deleted due to missingness)
$Lebanon
Call:
polr(formula = autocracy.bad.ordinal ~ quran + prime.minister +
citizen.influence + maintain.order + education + age + family.econ,
data = barometer, subset = (dem.best == 1 & country.name ==
"Lebanon"), Hess = TRUE, method = "logistic")
Coefficients:
Value Std. Error t value
quran -0.1148 0.0620 -1.853
prime.minister -0.0311 0.0675 -0.461
citizen.influence -0.2269 0.0755 -3.005
maintain.order 0.3040 0.1008 3.014
education 0.1478 0.0569 2.596
age 0.1080 0.0592 1.823
family.econ 0.1347 0.1064 1.267
Intercepts:
Value Std. Error t value
Very good|Good -3.710 0.683 -5.430
Good|Bad -2.152 0.597 -3.607
Bad|Very bad 0.100 0.577 0.173
Residual Deviance: 1236.47
AIC: 1256.47
(144 observations deleted due to missingness)
$Yemen
Call:
polr(formula = autocracy.bad.ordinal ~ quran + prime.minister +
citizen.influence + maintain.order + education + age + family.econ,
data = barometer, subset = (dem.best == 1 & country.name ==
"Yemen"), Hess = TRUE, method = "logistic")
Coefficients:
Value Std. Error t value
quran -0.0413 0.1096 -0.377
prime.minister 0.1704 0.1075 1.585
citizen.influence -0.2305 0.1194 -1.931
maintain.order 0.2755 0.1472 1.872
education 0.1107 0.0759 1.458
age -0.0360 0.1147 -0.314
family.econ 0.1764 0.1732 1.018
Intercepts:
Value Std. Error t value
Very good|Good -3.037 0.926 -3.279
Good|Bad -1.121 0.807 -1.390
Bad|Very bad 1.670 0.804 2.077
Residual Deviance: 612.22
AIC: 632.22
(272 observations deleted due to missingness)