For this project, I aim to replicate “The political consequences of external economic shocks: evidence from Poland” by John Ahlquist, Mark Copelovitch, and Stefanie Walter. The authors hope to find the effect of the loans of mortgage exposure on vote choice in Poland. The multinomial logit model in table 2 for mode 3 is the one I’m looking at is estimating how past and present exposure to FX loans can influence who they vote for in Poland.
In the model I replicated, the unit of analysis is a person from Poland who will be voting in the parliament election. They sampled respondents by using stratified random sampling with some probability-based methods to make sure there was a diverse number of people from Poland. Random sampling is based on how the data was gathered through these methods rather than having someone choose a particular person or just choose individuals based on convenience. The study says that respondents were randomly chosen from a national identification database in Poland. Since the data was collected a survey that used a CAPI known as a computer-assisted personal interview showed growth in how trustworthy the data on how standardized the questions were. The data is stratified because of how they give questions to respondents to answer what demographics they belong to for example their ages. For the data availability, the data is found in the American Journal of Political Science Dataverse so it is widely available to the general public.
Data sampled
The data set is made up of over 2,044 observations which come from the people who responded in the following survey. This is a good enough number of people to look at the way they are exposed to economics and the way they vote so we could evaluate the relationship between these two factors. The author got the data by using statistical probability-based methods and utilizing a software known as CAPI(computer-assisted personal -interview). This is a survey that was done by CBOS (Centrum Badania Opinii Społecznej) which is a company in Poland known for having satisfying interviewing results.
Dependent Variable
The dependent variable for replication is the voting intention for the election in Poland for parliament in 2015. This means it falls into the category of being discrete since there are examples of third parties, abstaining, and voting. Due to the examples, it would be a nominal (unordered categorical) variable. I am replicating a multinomial logistic regression model since the author used to look at whether or not the loan Swiss franc shock would affect who people vote for. I did see how some people’s votes were a lot higher than others which I found specifically in a big increase for the variable PiS.
Unit of Analysis and Observational Independence
The unit of analysis would be the people from Poland who voted in an election. Our observations come from a Polish person responding to a survey that was done a little before the Polish election in October 2015 for parliament. This survey was made to find how people felt politically at the time and who they voted for in the election regarding a critical event the 2015 Swiss Franc loan shock at the time. I have a concern about observational independence since people in the survey come from similar geographic regions or income groups therefore they might think the same way politically. This can come from the idea of conversing with one another by living nearby and what they consume media-wise as well as being similar. The author does try to lower this by using a more diverse group of people and putting it in a random sample. However, a remainder is that residual clustering effects might still be there as well.
What statistical model
The reason the author used the statistical model was to find causal inference in the situation of how the situation of Swiss Franc shock would make people vote differently or choose different policies during an election in Poland. The model also looked at how effective the way certain words or media in the election were used and how much political parties were willing to double down on economic issues. Missing data was handled by the author using statistical methods which created over 20 datasets. The use of this approach kept how accurate the stats were by double checking for values that were missing and keeping how representative the sample was. An example would be the variable of income since it had a lot of missingness imputed to make sure there was a lot less bias. The author lowers the chance of bias because of data that is missing in statistical methods like multiple imputation which keeps a big and more diverse group of people. The data that is not found is found in the 26 percent of people who did not say how much money they made for the FX loan variable in the survey.
The author hopes to find causal inference with Table 2 Model 3 by looking towards how people are affected by FX exposure on the way they vote, comparing people who were exposed and not exposed voters, and looking at how people’s interests in economics affect their voting outcome. This goal is to find whether people exposed to the loans of Swiss Franc shock in the form of FX-denominated mortgages had a higher chance of voting for the opposition PiS political party rather than the previous winner party of the PO/PSL coalition. The following model adds important covariates for example how people voted in the past, religion, education, and income to control for factors that might explain why people voted in a certain way. For the comparison with people who had exposure to mortgage loans, the authors work to have a connection of exposure to an economic shock with the way people end up voting. For people interested in economics in how they vote, this tests whether those who were affected by the loans decided to change their votes to a party who said they would bail out people in those circumstances. The reason or looking at the way people voted in the past here helps us see if certain groups voted differently due to the economic loan shock rather than for what they believe in.
Other code loading to work for other codes below. This code represents the figures for first two figures in the paper.
used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
Ncells 589164 31.5 1335175 71.4 NA 714202 38.2
Vcells 1093437 8.4 8388608 64.0 16384 1851829 14.2
library(MASS)library(foreign)
Warning: package 'foreign' was built under R version 4.3.3
library(MultinomialCI)library(weights)
Loading required package: Hmisc
Warning: package 'Hmisc' was built under R version 4.3.3
Attaching package: 'Hmisc'
The following objects are masked from 'package:base':
format.pval, units
Warning in check_dep_version(): ABI version mismatch:
lme4 was built with Matrix ABI version 1
Current Matrix ABI version is 0
Please re-install lme4 from source or restore original 'Matrix' package
#library(cem)library(nnet)
Warning: package 'nnet' was built under R version 4.3.3
library(RColorBrewer)library(stargazer)
Please cite as:
Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(texreg)
Warning: package 'texreg' was built under R version 4.3.3
Version: 1.39.4
Date: 2024-07-23
Author: Philip Leifeld (University of Manchester)
Consider submitting praise using the praise or praise_interactive functions.
Please cite the JSS article in your publications -- see citation("texreg").
library(xtable)
Attaching package: 'xtable'
The following objects are masked from 'package:Hmisc':
label, label<-
library(lubridate)
Warning: package 'lubridate' was built under R version 4.3.3
Attaching package: 'lubridate'
The following objects are masked from 'package:base':
date, intersect, setdiff, union
library(zoo)
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
library(Amelia)
Warning: package 'Amelia' was built under R version 4.3.3
Loading required package: Rcpp
Warning: package 'Rcpp' was built under R version 4.3.3
##
## Amelia II: Multiple Imputation
## (Version 1.8.3, built: 2024-11-07)
## Copyright (C) 2005-2025 James Honaker, Gary King and Matthew Blackwell
## Refer to http://gking.harvard.edu/amelia/ for more information
##
library(readstata13)library(lattice)
Warning: package 'lattice' was built under R version 4.3.2
library(mlogit)
Loading required package: dfidx
Warning: package 'dfidx' was built under R version 4.3.3
Attaching package: 'dfidx'
The following object is masked from 'package:MASS':
select
The following object is masked from 'package:stats':
filter
library(Hmisc)library(vioplot)
Warning: package 'vioplot' was built under R version 4.3.3
Loading required package: sm
Warning: package 'sm' was built under R version 4.3.2
Package 'sm', version 2.2-6.0: type help(sm) for summary information
Attaching package: 'sm'
The following object is masked from 'package:MASS':
muscle
#setwd() #set to your wddir.create("./tables_figs") #subdirectory for main text output
Warning in dir.create("./tables_figs"): './tables_figs' already exists
dir.create("./tables_figs/SM") #subdirectory for supplemental materials output
Warning in dir.create("./tables_figs/SM"): './tables_figs/SM' already exists
rng<-5879521set.seed(rng)inv.logit<-function(x){exp(x)/(exp(x)+1)}load("AJPSimputations.RData")# creating variables for analysis## simplified vote choice variable that lumps those unsure about voting with abstainersfor(i in1:imp.out$m){ imp.out$imputations[[i]]$vote.intent.rev2<-imp.out$imputations[[i]]$vote.intent.rev imp.out$imputations[[i]]$vote.intent.rev2[imp.out$imputations[[i]]$turnout.intent.ord<2]<-"NoVote" imp.out$imputations[[i]]$vote.intent.rev2<-relevel(imp.out$imputations[[i]]$vote.intent.rev2, ref="PO/PSL")}## simplified vote choice variable that lumps those unsure about voting or unsure about party with abstainersfor(i in1:imp.out$m){ imp.out$imputations[[i]]$vote.intent.rev3<-"NoVote" imp.out$imputations[[i]]$vote.intent.rev3[imp.out$imputations[[i]]$vote.intent.rev2=="PO/PSL"]<-"PO/PSL" imp.out$imputations[[i]]$vote.intent.rev3[imp.out$imputations[[i]]$vote.intent.rev2=="other"]<-"other" imp.out$imputations[[i]]$vote.intent.rev3[imp.out$imputations[[i]]$vote.intent.rev2=="PiS"]<-"PiS" imp.out$imputations[[i]]$vote.intent.rev3<-relevel(as.factor(imp.out$imputations[[i]]$vote.intent.rev3), ref="PO/PSL")}##single FX variablefor(i in1:imp.out$m){ imp.out$imputations[[i]]$FXstatus<-"none" imp.out$imputations[[i]]$FXstatus[imp.out$imputations[[i]]$currentFXloan==1]<-"exposed" imp.out$imputations[[i]]$FXstatus[imp.out$imputations[[i]]$pastFXloan==1]<-"past" imp.out$imputations[[i]]$FXstatus<-factor(imp.out$imputations[[i]]$FXstatus,levels=c("none","exposed", "past")) imp.out$imputations[[i]]$FXstatus<-relevel(imp.out$imputations[[i]]$FXstatus, ref ="none")}## current borrowers are exposed for(i in1:imp.out$m){ imp.out$imputations[[i]]$exposed<-as.numeric(imp.out$imputations[[i]]$FXstatus=="exposed")}## reordering treatment levels & PS for(i in1:imp.out$m){ imp.out$imputations[[i]]$treat<-factor(imp.out$imputations[[i]]$treat, levels=c("cntrl", "info", "history", "Hungary")) imp.out$imputations[[i]]$ps<-factor(imp.out$imputations[[i]]$ps, levels=c("DK", "none", "some", "50/50", "90/10")) imp.out$imputations[[i]]$ps<-relevel(imp.out$imputations[[i]]$ps, ref="none") imp.out$imputations[[i]]$gi<-relevel(imp.out$imputations[[i]]$gi, ref="DK")}## reversing religiousity scale; bigger is more religious for(i in1:imp.out$m){ imp.out$imputations[[i]]$religion<-6-1*imp.out$imputations[[i]]$religious_participation}##observed data, no imputationsobs.dat<-imp.out$imputations[[1]][,1:ncol(imp.out$missMatrix)]obs.dat[imp.out$missMatrix==1]<-NAobs.dat$FXstatus<-"none"obs.dat$FXstatus[obs.dat$currentFXloan==1]<-"exposed"obs.dat$FXstatus[obs.dat$pastFXloan==1]<-"past"obs.dat$FXstatus<-factor(obs.dat$FXstatus, levels=c("none","exposed","past"))obs.dat$exposed<-obs.dat$FXstatus=="exposed"obs.dat$gi<-factor(obs.dat$gi, levels=c("DK","none","some","big"))obs.dat$gi<-relevel(obs.dat$gi, ref="DK")obs.dat$ps<-factor(obs.dat$ps, levels=c("DK","none","some","50/50","90/10"))obs.dat$ps<-relevel(obs.dat$ps, ref="none")obs.dat$vote.intent.rev2<-obs.dat$vote.intent.revobs.dat$vote.intent.rev2[obs.dat$turnout.intent.ord<2]<-"NoVote"obs.dat$vote.intent.rev3<-obs.dat$vote.intent.rev2obs.dat$vote.intent.rev3[obs.dat$vote.intent.rev2=="DK"]<-"NoVote"obs.dat$vote.intent.rev3<-droplevels(obs.dat$vote.intent.rev3)obs.dat$gi.bin<-as.numeric(obs.dat$gi %in%c("some", "big"))obs.dat$age.expand <-as.factor(cut2(obs.dat$age, g=5))obs.dat$age.expand<-relevel(obs.dat$age.expand, ref="[32,44)")obs.dat$LRp1<-1+obs.dat$LeftRight #shifting the scale up 1 for plotting laterobs.dat$LeftRightCat<-"center"obs.dat$LeftRightCat[obs.dat$LeftRight<0]<-"left"obs.dat$LeftRightCat[obs.dat$LeftRight>0]<-"right"obs.dat$LeftRightCat<-as.factor(obs.dat$LeftRightCat)obs.dat$religion<-6-1*obs.dat$religious_participationobs.dat$treat<-factor(obs.dat$treat, levels=c("cntrl", "info", "history", "Hungary")) ### merging immigration questions; not part of imputation or analysisload("AJPScleanedData.Rdata")obs.dat$immigration.summary<- octdat$immigration.summaryobs.dat$antimigrant.summary<- octdat$antimigrant.summaryrm(octdat)## Vote Choice & turnout modelsvc.simp<-vote.intent.rev3 ~ FXstatus + past.turnout+ age.expand + female + married + income.quint + ed_level + urban_rural + employed + religion + hh_size + LeftRightCat + provincevc.int<-vote.intent.rev3 ~ FXstatus*POPSL2011 + past.turnout+ age.expand + female + married + income.quint + ed_level + urban_rural + employed + religion + hh_size + LeftRightCat + provincevc.out<-b.vc.out<-se.vc.out<-vc.ni<-b.vc.ni<-se.vc.ni<-pp.out<-pp.ni<-NULLfor(i in1:imp.out$m){ vc.ni[[i]]<-multinom(vc.simp, data = imp.out$imputations[[i]],weights=weight, Hess =TRUE, maxit =200, model=TRUE) vc.out[[i]]<-multinom(vc.int, data = imp.out$imputations[[i]],weights=weight, Hess =TRUE, maxit =200, model=TRUE) b.vc.out<-rbind(b.vc.out,as.vector(summary(vc.out[[i]])$coefficients)) se.vc.out<-rbind(se.vc.out,as.vector(summary(vc.out[[i]])$standard.errors)) pp.out<-cbind(pp.out, fitted(vc.out[[i]])[,4]) b.vc.ni<-rbind(b.vc.ni,as.vector(summary(vc.ni[[i]])$coefficients)) se.vc.ni<-rbind(se.vc.ni,as.vector(summary(vc.ni[[i]])$standard.errors)) pp.ni<-cbind(pp.ni, fitted(vc.ni[[i]])[,4])}
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2335.139422
iter 20 value 2244.665887
iter 30 value 2205.462158
iter 40 value 2188.963395
iter 50 value 2188.486416
iter 60 value 2188.460981
final value 2188.459489
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2179.885651
iter 20 value 2044.346251
iter 30 value 1991.123838
iter 40 value 1977.466459
iter 50 value 1976.478463
iter 60 value 1976.370022
iter 70 value 1976.363524
final value 1976.363093
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2347.909699
iter 20 value 2252.685678
iter 30 value 2211.116551
iter 40 value 2197.615114
iter 50 value 2197.159375
iter 60 value 2197.137875
iter 70 value 2197.135885
final value 2197.135767
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2188.413777
iter 20 value 2037.353678
iter 30 value 1983.642137
iter 40 value 1972.307837
iter 50 value 1971.208865
iter 60 value 1971.117540
iter 70 value 1971.111154
final value 1971.110779
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2347.739058
iter 20 value 2251.777865
iter 30 value 2210.630350
iter 40 value 2198.122205
iter 50 value 2197.751142
iter 60 value 2197.729747
iter 70 value 2197.728438
final value 2197.728403
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2187.224288
iter 20 value 2035.654965
iter 30 value 1985.011301
iter 40 value 1973.855896
iter 50 value 1972.832679
iter 60 value 1972.727622
final value 1972.722598
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2357.603771
iter 20 value 2262.183449
iter 30 value 2218.255076
iter 40 value 2203.178385
iter 50 value 2202.660637
iter 60 value 2202.636984
iter 70 value 2202.635264
iter 70 value 2202.635257
iter 70 value 2202.635257
final value 2202.635257
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2203.361489
iter 20 value 2047.056342
iter 30 value 1991.886379
iter 40 value 1980.809826
iter 50 value 1979.749740
iter 60 value 1979.644153
iter 70 value 1979.637658
final value 1979.637129
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2358.866098
iter 20 value 2267.315085
iter 30 value 2227.285558
iter 40 value 2210.444503
iter 50 value 2209.862191
iter 60 value 2209.835325
final value 2209.833847
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2189.127508
iter 20 value 2031.910734
iter 30 value 1976.767754
iter 40 value 1964.201206
iter 50 value 1962.983319
iter 60 value 1962.815217
iter 70 value 1962.807254
final value 1962.806676
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2367.570633
iter 20 value 2273.128506
iter 30 value 2234.445230
iter 40 value 2219.980369
iter 50 value 2219.481931
iter 60 value 2219.461154
final value 2219.460164
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2207.531477
iter 20 value 2053.639355
iter 30 value 2003.367569
iter 40 value 1990.407434
iter 50 value 1989.345811
iter 60 value 1989.250414
iter 70 value 1989.245098
final value 1989.244532
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2357.132102
iter 20 value 2260.139936
iter 30 value 2218.832648
iter 40 value 2202.431632
iter 50 value 2201.980218
iter 60 value 2201.960163
final value 2201.958837
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2187.599298
iter 20 value 2031.237971
iter 30 value 1976.537592
iter 40 value 1964.770941
iter 50 value 1963.502056
iter 60 value 1963.385960
iter 70 value 1963.380656
final value 1963.380339
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2347.174100
iter 20 value 2249.914720
iter 30 value 2207.024097
iter 40 value 2193.617786
iter 50 value 2193.187470
iter 60 value 2193.159051
iter 70 value 2193.157256
final value 2193.157192
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2182.772546
iter 20 value 2032.373812
iter 30 value 1976.284985
iter 40 value 1963.383826
iter 50 value 1962.194476
iter 60 value 1962.088522
iter 70 value 1962.080727
final value 1962.080161
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2355.386128
iter 20 value 2266.032713
iter 30 value 2226.738620
iter 40 value 2211.323245
iter 50 value 2210.826043
iter 60 value 2210.802908
final value 2210.801910
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2190.893225
iter 20 value 2038.279018
iter 30 value 1985.561672
iter 40 value 1973.622654
iter 50 value 1972.535244
iter 60 value 1972.385699
iter 70 value 1972.378146
final value 1972.376934
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2346.366983
iter 20 value 2258.115734
iter 30 value 2219.987539
iter 40 value 2199.879608
iter 50 value 2199.263704
iter 60 value 2199.235617
iter 70 value 2199.233462
iter 70 value 2199.233457
iter 70 value 2199.233457
final value 2199.233457
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2170.804395
iter 20 value 2019.041077
iter 30 value 1964.178516
iter 40 value 1948.657902
iter 50 value 1947.307695
iter 60 value 1947.140268
iter 70 value 1947.132024
final value 1947.131570
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2347.421022
iter 20 value 2261.879543
iter 30 value 2217.969154
iter 40 value 2205.044902
iter 50 value 2204.507172
iter 60 value 2204.487586
final value 2204.486415
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2196.456932
iter 20 value 2054.293406
iter 30 value 2002.688031
iter 40 value 1991.673805
iter 50 value 1990.775299
iter 60 value 1990.689269
iter 70 value 1990.681001
final value 1990.680208
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2364.782655
iter 20 value 2270.353519
iter 30 value 2230.404727
iter 40 value 2215.746614
iter 50 value 2215.312862
iter 60 value 2215.288775
final value 2215.287497
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2201.864253
iter 20 value 2043.942634
iter 30 value 1989.464802
iter 40 value 1977.016517
iter 50 value 1975.773986
iter 60 value 1975.656720
iter 70 value 1975.648719
final value 1975.648244
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2360.141156
iter 20 value 2266.333155
iter 30 value 2228.480640
iter 40 value 2212.024245
iter 50 value 2211.502318
iter 60 value 2211.477053
final value 2211.475926
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2208.004144
iter 20 value 2059.611559
iter 30 value 2005.065827
iter 40 value 1992.621543
iter 50 value 1991.548289
iter 60 value 1991.449395
final value 1991.448167
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2349.078886
iter 20 value 2254.103405
iter 30 value 2211.024047
iter 40 value 2198.206632
iter 50 value 2197.666685
iter 60 value 2197.642005
iter 70 value 2197.640204
iter 70 value 2197.640189
iter 70 value 2197.640186
final value 2197.640186
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2185.604661
iter 20 value 2027.952883
iter 30 value 1972.336670
iter 40 value 1960.799592
iter 50 value 1959.519487
iter 60 value 1959.401681
iter 70 value 1959.394473
final value 1959.394154
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2362.775606
iter 20 value 2266.364854
iter 30 value 2228.037286
iter 40 value 2211.292705
iter 50 value 2210.813342
iter 60 value 2210.790430
iter 70 value 2210.789196
iter 70 value 2210.789190
iter 70 value 2210.789190
final value 2210.789190
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2205.325347
iter 20 value 2053.133164
iter 30 value 1999.657561
iter 40 value 1986.145059
iter 50 value 1985.070043
iter 60 value 1984.946356
final value 1984.936707
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2355.542929
iter 20 value 2270.253427
iter 30 value 2231.249888
iter 40 value 2213.521312
iter 50 value 2212.994590
iter 60 value 2212.974030
final value 2212.972924
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2191.177270
iter 20 value 2046.324012
iter 30 value 1991.853785
iter 40 value 1977.516516
iter 50 value 1976.362681
iter 60 value 1976.265362
iter 70 value 1976.258317
final value 1976.257485
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2362.972008
iter 20 value 2274.502897
iter 30 value 2232.601017
iter 40 value 2216.170520
iter 50 value 2215.683929
iter 60 value 2215.662779
final value 2215.661819
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2198.999840
iter 20 value 2043.206529
iter 30 value 1990.718350
iter 40 value 1974.354589
iter 50 value 1973.192269
iter 60 value 1973.063649
iter 70 value 1973.054516
final value 1973.053806
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2349.537802
iter 20 value 2261.586325
iter 30 value 2217.114357
iter 40 value 2203.142918
iter 50 value 2202.623368
iter 60 value 2202.596025
final value 2202.595146
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2190.166062
iter 20 value 2041.245054
iter 30 value 1987.469878
iter 40 value 1974.760338
iter 50 value 1973.670932
iter 60 value 1973.563605
iter 70 value 1973.554124
final value 1973.553551
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2349.934918
iter 20 value 2260.174995
iter 30 value 2219.548755
iter 40 value 2204.693952
iter 50 value 2204.309696
iter 60 value 2204.283941
final value 2204.282282
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2187.235097
iter 20 value 2037.419507
iter 30 value 1984.335486
iter 40 value 1972.211717
iter 50 value 1971.041816
iter 60 value 1970.924632
final value 1970.920630
converged
# weights: 136 (99 variable)
initial value 2833.585674
iter 10 value 2356.413693
iter 20 value 2267.799350
iter 30 value 2228.647822
iter 40 value 2213.590506
iter 50 value 2213.126547
iter 60 value 2213.100898
final value 2213.099146
converged
# weights: 148 (108 variable)
initial value 2833.585674
iter 10 value 2190.303536
iter 20 value 2041.136797
iter 30 value 1989.631838
iter 40 value 1976.198197
iter 50 value 1975.009183
iter 60 value 1974.885116
iter 70 value 1974.876392
final value 1974.875985
converged
#p.values for table 2/A-8 model 3p.vals.t2.m3<-t(matrix(round(2*pnorm(abs(vc.meld.ni$q.mi/vc.meld.ni$se.mi), lower=F),2), nrow=3))colnames(p.vals.t2.m3)<-c("abstain", "other", "PiS")rownames(p.vals.t2.m3)<-vc.ni[[1]]$coefnames#p.values for table 2/A-8 model 4p.vals.t2.m4<-t(matrix(round(2*pnorm(abs(vc.meld$q.mi/vc.meld$se.mi), lower=F),2), nrow=3))colnames(p.vals.t2.m4)<-c("abstain", "other", "PiS")rownames(p.vals.t2.m4)<-vc.out[[1]]$coefnames
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2334.421630
iter 20 value 2246.909009
iter 30 value 2208.885134
iter 40 value 2203.012990
iter 50 value 2202.790345
iter 60 value 2202.775382
iter 70 value 2202.773380
final value 2202.773291
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2168.720865
iter 20 value 2045.727281
iter 30 value 1999.804824
iter 40 value 1990.117808
iter 50 value 1989.399713
iter 60 value 1989.341329
iter 70 value 1989.336306
final value 1989.336041
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2347.727931
iter 20 value 2262.423304
iter 30 value 2219.493889
iter 40 value 2211.886471
iter 50 value 2211.659050
iter 60 value 2211.646322
final value 2211.644768
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2177.397145
iter 20 value 2046.917494
iter 30 value 1996.292046
iter 40 value 1986.588618
iter 50 value 1985.678850
iter 60 value 1985.611721
iter 70 value 1985.603085
final value 1985.602530
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2349.220508
iter 20 value 2262.977865
iter 30 value 2217.930617
iter 40 value 2212.835839
iter 50 value 2212.557852
iter 60 value 2212.542986
iter 70 value 2212.541566
final value 2212.541510
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2180.098443
iter 20 value 2038.984154
iter 30 value 1995.741432
iter 40 value 1988.219049
iter 50 value 1987.570696
iter 60 value 1987.519557
iter 70 value 1987.516741
final value 1987.516575
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2357.331425
iter 20 value 2267.262203
iter 30 value 2223.716348
iter 40 value 2216.788441
iter 50 value 2216.563112
iter 60 value 2216.548384
iter 70 value 2216.546897
final value 2216.546859
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2192.210738
iter 20 value 2048.864455
iter 30 value 2001.368913
iter 40 value 1993.760651
iter 50 value 1992.953464
iter 60 value 1992.898039
final value 1992.893401
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2360.292781
iter 20 value 2275.371915
iter 30 value 2233.363725
iter 40 value 2225.074721
iter 50 value 2224.813922
iter 60 value 2224.798043
iter 70 value 2224.796364
final value 2224.796330
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2180.429275
iter 20 value 2045.830012
iter 30 value 1989.082227
iter 40 value 1978.113106
iter 50 value 1977.162440
iter 60 value 1977.081884
iter 70 value 1977.076478
iter 70 value 1977.076476
iter 70 value 1977.076475
final value 1977.076475
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2370.627905
iter 20 value 2283.422552
iter 30 value 2243.583907
iter 40 value 2235.019291
iter 50 value 2234.775587
iter 60 value 2234.762685
final value 2234.761745
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2201.855942
iter 20 value 2069.193623
iter 30 value 2016.837610
iter 40 value 2004.889957
iter 50 value 2004.058792
iter 60 value 2003.989499
iter 70 value 2003.984420
final value 2003.984190
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2356.338823
iter 20 value 2267.479386
iter 30 value 2225.707809
iter 40 value 2217.068616
iter 50 value 2216.797636
iter 60 value 2216.783213
final value 2216.781788
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2174.424794
iter 20 value 2040.870968
iter 30 value 1988.304030
iter 40 value 1978.324201
iter 50 value 1977.386770
iter 60 value 1977.304024
iter 70 value 1977.299203
final value 1977.298907
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2345.267825
iter 20 value 2259.224925
iter 30 value 2215.369036
iter 40 value 2206.704054
iter 50 value 2206.380688
iter 60 value 2206.366033
final value 2206.365452
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2169.818624
iter 20 value 2042.400219
iter 30 value 1987.665920
iter 40 value 1975.986827
iter 50 value 1975.066258
iter 60 value 1974.989433
iter 70 value 1974.981445
final value 1974.980930
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2355.708171
iter 20 value 2271.777776
iter 30 value 2231.884247
iter 40 value 2224.973190
iter 50 value 2224.764465
iter 60 value 2224.752054
final value 2224.751077
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2182.823912
iter 20 value 2049.496198
iter 30 value 1997.102057
iter 40 value 1986.637633
iter 50 value 1985.763391
iter 60 value 1985.689394
iter 70 value 1985.684078
final value 1985.683653
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2347.392079
iter 20 value 2270.032965
iter 30 value 2223.616040
iter 40 value 2213.459192
iter 50 value 2213.163016
iter 60 value 2213.150172
iter 70 value 2213.149439
iter 70 value 2213.149417
iter 70 value 2213.149417
final value 2213.149417
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2162.610582
iter 20 value 2020.555436
iter 30 value 1972.331507
iter 40 value 1961.844370
iter 50 value 1960.877907
iter 60 value 1960.802740
iter 70 value 1960.798740
iter 70 value 1960.798727
iter 70 value 1960.798727
final value 1960.798727
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2349.673129
iter 20 value 2268.063067
iter 30 value 2226.733204
iter 40 value 2220.130167
iter 50 value 2219.918748
final value 2219.909035
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2191.401386
iter 20 value 2059.923064
iter 30 value 2013.767047
iter 40 value 2005.759878
iter 50 value 2005.082516
iter 60 value 2005.026513
iter 70 value 2005.021611
final value 2005.021420
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2365.119708
iter 20 value 2280.954075
iter 30 value 2237.302576
iter 40 value 2229.214889
iter 50 value 2228.938392
iter 60 value 2228.923251
final value 2228.922057
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2192.588321
iter 20 value 2046.714794
iter 30 value 1998.526823
iter 40 value 1989.315660
iter 50 value 1988.592979
iter 60 value 1988.532693
iter 70 value 1988.527482
final value 1988.527147
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2362.632171
iter 20 value 2274.351711
iter 30 value 2233.030694
iter 40 value 2225.851124
iter 50 value 2225.625273
iter 60 value 2225.613309
final value 2225.612621
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2202.651403
iter 20 value 2060.741875
iter 30 value 2014.150088
iter 40 value 2005.821164
iter 50 value 2005.063654
iter 60 value 2005.004895
iter 70 value 2004.997668
final value 2004.997260
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2351.453883
iter 20 value 2263.190480
iter 30 value 2219.308669
iter 40 value 2211.954330
iter 50 value 2211.658105
iter 60 value 2211.641536
final value 2211.639777
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2178.364709
iter 20 value 2039.524249
iter 30 value 1984.269780
iter 40 value 1974.424019
iter 50 value 1973.459974
iter 60 value 1973.381438
iter 70 value 1973.372141
final value 1973.371476
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2363.744569
iter 20 value 2274.058624
iter 30 value 2232.272871
iter 40 value 2225.442246
iter 50 value 2225.202202
iter 60 value 2225.191745
final value 2225.190152
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2197.078165
iter 20 value 2055.768343
iter 30 value 2009.489941
iter 40 value 1999.306628
iter 50 value 1998.537246
iter 60 value 1998.470965
iter 70 value 1998.464509
final value 1998.464086
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2354.198515
iter 20 value 2276.252810
iter 30 value 2234.502283
iter 40 value 2227.430376
iter 50 value 2227.245277
iter 60 value 2227.235073
final value 2227.234685
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2178.461849
iter 20 value 2044.435250
iter 30 value 2000.267991
iter 40 value 1991.227054
iter 50 value 1990.429505
iter 60 value 1990.367926
iter 70 value 1990.361556
final value 1990.361030
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2365.433740
iter 20 value 2281.993230
iter 30 value 2240.088856
iter 40 value 2231.617615
iter 50 value 2231.378821
iter 60 value 2231.367126
final value 2231.366066
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2193.337124
iter 20 value 2055.242158
iter 30 value 2000.573041
iter 40 value 1989.678948
iter 50 value 1988.759295
iter 60 value 1988.682470
iter 70 value 1988.677225
final value 1988.677079
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2351.268238
iter 20 value 2266.752442
iter 30 value 2224.249153
iter 40 value 2217.003046
iter 50 value 2216.757490
iter 60 value 2216.740702
iter 70 value 2216.739218
final value 2216.739098
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2183.316160
iter 20 value 2057.177506
iter 30 value 2000.004208
iter 40 value 1988.545567
iter 50 value 1987.653038
iter 60 value 1987.577812
final value 1987.570485
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2348.595940
iter 20 value 2263.646605
iter 30 value 2224.628220
iter 40 value 2218.071710
iter 50 value 2217.841059
iter 60 value 2217.827612
final value 2217.827078
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2175.214954
iter 20 value 2044.907985
iter 30 value 1996.009622
iter 40 value 1984.901123
iter 50 value 1984.071682
iter 60 value 1983.991882
iter 70 value 1983.987967
final value 1983.987814
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2356.971315
iter 20 value 2277.022664
iter 30 value 2235.808701
iter 40 value 2228.047624
iter 50 value 2227.805700
iter 60 value 2227.793905
final value 2227.793414
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2182.424608
iter 20 value 2049.871407
iter 30 value 2000.047057
iter 40 value 1989.904845
iter 50 value 1989.011680
iter 60 value 1988.943935
iter 70 value 1988.937205
final value 1988.936942
converged
I am focusing on the first 3 columns in the model with 1 being Abstain, 2 being other, and 3 being PiS on the row with this being part of the model while the other side is model 4.
Type of Model analyzed comparison
The authors hope to find the effect of the loans of mortgage exposure on vote choice in Poland. The multinomial logit model in Table 2 for model 3 is the one I’m looking at estimating how past and present exposure to FX loans can influence who they vote for in Poland. This is based on several political attributes used like income, urban, location, education, self-placement on a left-right scale, level of religious observance, and anti-immigrant sentiment. The authors hope to find the effect of the loans of mortgage exposure on vote choice in Poland. The multinomial logit models in Table 2 for Model 3 are the ones I’m looking at is estimate how past and present exposure to FX loans can influence who they vote for in Poland. This is based on several political attributes used like income, urban, location, education, self-placement on a left-right scale, level of religious observance, and anti-immigrant sentiment.
This was originally tab2.html but now a file called table_output3.png
I did an additional model that got rid of the variable urban and rural because of how I believe this would affect the model based on their location affecting what people think or perceive about politics economically. The variable is called urban_rural and the description describes it as the indicator for the size of the settlement. The values of urban_rural are 1 = rural, 2 = small urban, and 3 = big urban which measures the location of the respondents based on these values. The models are using multinomial logistic regression meaning to find the model fit we should compare what log likelihoods are found.
This was originally tab2.html but now a file called table_output4.png
Log-likelihood, AIC and BIC Comparison
My model which gets rid of urban and rural compared to the original model shows that the original model performs better because of how it has a log-likelihood of -1976.3630933. This log-likelihood is better than my model of -1989.3360409 because of how the model that is found to have the biggest log-likelihood meaning this which is the least negative is the best for the data. The metric of the original model is found in the lower aic of 4168.726186 and lower bic being 4775.973893 while my model has a higher aic of 4188.67208 and lower bic of 4779.05179. This signifies a better model for the original for having both a lower aic and bic because of how it shows a balance from how the model is well fitting for the data while also indicating that there is a lower number of unnecessary parameters.
#Out of sample part# Load necessary packageslibrary(nnet) # For multinomial logistic regressionlibrary(caret) # For cross-validation
Warning: package 'caret' was built under R version 4.3.3
Loading required package: ggplot2
Warning: package 'ggplot2' was built under R version 4.3.2
library(MASS) # For stepAIClibrary(mlogit) # Alternative multinomial regressionlibrary(pscl) # For McFadden's R²
Warning: package 'pscl' was built under R version 4.3.2
Classes and Methods for R originally developed in the
Political Science Computational Laboratory
Department of Political Science
Stanford University (2002-2015),
by and under the direction of Simon Jackman.
hurdle and zeroinfl functions by Achim Zeileis.
library(mice)
Warning: package 'mice' was built under R version 4.3.3
Attaching package: 'mice'
The following object is masked from 'package:stats':
filter
The following objects are masked from 'package:base':
cbind, rbind
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2334.421630
iter 20 value 2246.909009
iter 30 value 2208.885134
iter 40 value 2203.012990
iter 50 value 2202.790345
iter 60 value 2202.775382
iter 70 value 2202.773380
final value 2202.773291
converged
summary(test_model)
Call:
multinom(formula = vc.simp.no_urban, data = imp.out$imputations[[1]],
weights = imp.out$imputations[[1]]$weight, Hess = TRUE, model = TRUE,
maxit = 200)
Coefficients:
(Intercept) FXstatusexposed FXstatuspast past.turnout age.expand[18,32)
NoVote 1.7589596 -0.5406519 -0.6491452 -2.0967228 0.23268810
other -0.2546955 0.6292141 -0.0376803 -0.1800409 1.00967324
PiS -2.2040128 0.5904978 -0.4817651 -0.5867860 -0.01327318
age.expand[44,57) age.expand[57,66) age.expand[66,85] female
NoVote 0.2005665 -0.1393966 0.09664516 0.006310245
other 0.4398816 0.1885114 -0.49335151 -0.501638971
PiS 0.5971029 0.4683614 0.35165070 -0.199658629
married income.quint ed_level employed religion hh_size
NoVote -0.001051038 -0.25165831 -0.1560899 0.2587101 0.12299955 -0.05224398
other -0.283516271 -0.06167277 0.2059994 -0.1316579 0.03684094 -0.03547292
PiS -0.249313424 -0.04421569 -0.1211545 0.2877811 0.55617557 0.04635858
LeftRightCatleft LeftRightCatright provinceKujawsko-pomorskie
NoVote 0.6258795 0.23902348 0.24234800
other 0.7163447 -0.06495051 0.01225782
PiS -0.4970988 1.16588690 0.53624066
provinceLubelskie provinceLubuskie provinceLódzkie provinceMalopolskie
NoVote 0.64559170 0.457740202 0.9532113 0.54907444
other 0.00118285 0.005458531 0.1605634 0.09620343
PiS 0.52814911 -0.836089449 0.6569855 0.22612836
provinceMazowieckie provinceOpolskie provincePodkarpackie
NoVote 0.35190050 0.6379348 0.9629839
other 0.09692822 -0.4891465 0.4265501
PiS 0.30438217 -0.3490872 1.3929833
provincePodlaskie provincePomorskie provinceSlaskie
NoVote 0.5738764 0.7574006 1.07070877
other -0.3220043 -0.4892516 0.03525783
PiS 0.4113845 -0.2645657 0.49279672
provinceSwietokrzyskie provinceWarminsko-mazurskie provinceWielkopolskie
NoVote 0.02839356 0.02691132 0.5903242
other -0.30174629 -0.48615384 -0.4014072
PiS 0.15192177 -0.25584004 0.3934525
provinceZachodniopomorskie
NoVote 0.4576481
other 0.1883591
PiS -0.2978518
Std. Errors:
(Intercept) FXstatusexposed FXstatuspast past.turnout age.expand[18,32)
NoVote 0.5336924 0.4379057 0.4237259 0.1833042 0.2169355
other 0.6138519 0.3695022 0.3973951 0.2264494 0.2421403
PiS 0.6114411 0.3822360 0.4407018 0.2157253 0.2569360
age.expand[44,57) age.expand[57,66) age.expand[66,85] female
NoVote 0.2136325 0.2378091 0.2602544 0.1399218
other 0.2487222 0.2747951 0.3233776 0.1612182
PiS 0.2334550 0.2554131 0.2898456 0.1543374
married income.quint ed_level employed religion hh_size
NoVote 0.1547594 0.06088267 0.07461793 0.1778289 0.06210032 0.05347245
other 0.1781712 0.07010577 0.08638166 0.2031657 0.07076182 0.06331141
PiS 0.1723867 0.06764028 0.08309158 0.1984592 0.07425331 0.05846642
LeftRightCatleft LeftRightCatright provinceKujawsko-pomorskie
NoVote 0.1732969 0.1601801 0.3823199
other 0.1928707 0.1893560 0.4275342
PiS 0.2459692 0.1699955 0.4162232
provinceLubelskie provinceLubuskie provinceLódzkie provinceMalopolskie
NoVote 0.3782921 0.4533459 0.3592866 0.3320473
other 0.4297833 0.4911643 0.3982521 0.3615894
PiS 0.4109532 0.6208191 0.4018109 0.3624181
provinceMazowieckie provinceOpolskie provincePodkarpackie
NoVote 0.2959979 0.4626434 0.4357123
other 0.3148510 0.5903459 0.4816227
PiS 0.3237478 0.5572182 0.4467842
provincePodlaskie provincePomorskie provinceSlaskie
NoVote 0.4580448 0.3478768 0.3095192
other 0.5576014 0.4155560 0.3501867
PiS 0.4609185 0.4178544 0.3476933
provinceSwietokrzyskie provinceWarminsko-mazurskie provinceWielkopolskie
NoVote 0.4245246 0.3969769 0.3205553
other 0.4683308 0.4635300 0.3784595
PiS 0.4444394 0.4495939 0.3520096
provinceZachodniopomorskie
NoVote 0.3842068
other 0.4160126
PiS 0.4621943
Residual Deviance: 4405.547
AIC: 4597.547
vc.out.no_urban <-vector("list", imp.out$m) # Create empty list with length mvc.ni.no_urban <-vector("list", imp.out$m)for(i in1:imp.out$m) { vc.ni.no_urban[[i]] <-multinom(vc.simp.no_urban, data = imp.out$imputations[[i]],weights = imp.out$imputations[[i]]$weight,Hess =TRUE, maxit =200, model =TRUE) vc.out.no_urban[[i]] <-multinom(vc.int.no_urban, data = imp.out$imputations[[i]],weights = imp.out$imputations[[i]]$weight,Hess =TRUE, maxit =200, model =TRUE)}
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2334.421630
iter 20 value 2246.909009
iter 30 value 2208.885134
iter 40 value 2203.012990
iter 50 value 2202.790345
iter 60 value 2202.775382
iter 70 value 2202.773380
final value 2202.773291
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2168.720865
iter 20 value 2045.727281
iter 30 value 1999.804824
iter 40 value 1990.117808
iter 50 value 1989.399713
iter 60 value 1989.341329
iter 70 value 1989.336306
final value 1989.336041
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2347.727931
iter 20 value 2262.423304
iter 30 value 2219.493889
iter 40 value 2211.886471
iter 50 value 2211.659050
iter 60 value 2211.646322
final value 2211.644768
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2177.397145
iter 20 value 2046.917494
iter 30 value 1996.292046
iter 40 value 1986.588618
iter 50 value 1985.678850
iter 60 value 1985.611721
iter 70 value 1985.603085
final value 1985.602530
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2349.220508
iter 20 value 2262.977865
iter 30 value 2217.930617
iter 40 value 2212.835839
iter 50 value 2212.557852
iter 60 value 2212.542986
iter 70 value 2212.541566
final value 2212.541510
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2180.098443
iter 20 value 2038.984154
iter 30 value 1995.741432
iter 40 value 1988.219049
iter 50 value 1987.570696
iter 60 value 1987.519557
iter 70 value 1987.516741
final value 1987.516575
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2357.331425
iter 20 value 2267.262203
iter 30 value 2223.716348
iter 40 value 2216.788441
iter 50 value 2216.563112
iter 60 value 2216.548384
iter 70 value 2216.546897
final value 2216.546859
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2192.210738
iter 20 value 2048.864455
iter 30 value 2001.368913
iter 40 value 1993.760651
iter 50 value 1992.953464
iter 60 value 1992.898039
final value 1992.893401
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2360.292781
iter 20 value 2275.371915
iter 30 value 2233.363725
iter 40 value 2225.074721
iter 50 value 2224.813922
iter 60 value 2224.798043
iter 70 value 2224.796364
final value 2224.796330
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2180.429275
iter 20 value 2045.830012
iter 30 value 1989.082227
iter 40 value 1978.113106
iter 50 value 1977.162440
iter 60 value 1977.081884
iter 70 value 1977.076478
iter 70 value 1977.076476
iter 70 value 1977.076475
final value 1977.076475
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2370.627905
iter 20 value 2283.422552
iter 30 value 2243.583907
iter 40 value 2235.019291
iter 50 value 2234.775587
iter 60 value 2234.762685
final value 2234.761745
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2201.855942
iter 20 value 2069.193623
iter 30 value 2016.837610
iter 40 value 2004.889957
iter 50 value 2004.058792
iter 60 value 2003.989499
iter 70 value 2003.984420
final value 2003.984190
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2356.338823
iter 20 value 2267.479386
iter 30 value 2225.707809
iter 40 value 2217.068616
iter 50 value 2216.797636
iter 60 value 2216.783213
final value 2216.781788
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2174.424794
iter 20 value 2040.870968
iter 30 value 1988.304030
iter 40 value 1978.324201
iter 50 value 1977.386770
iter 60 value 1977.304024
iter 70 value 1977.299203
final value 1977.298907
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2345.267825
iter 20 value 2259.224925
iter 30 value 2215.369036
iter 40 value 2206.704054
iter 50 value 2206.380688
iter 60 value 2206.366033
final value 2206.365452
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2169.818624
iter 20 value 2042.400219
iter 30 value 1987.665920
iter 40 value 1975.986827
iter 50 value 1975.066258
iter 60 value 1974.989433
iter 70 value 1974.981445
final value 1974.980930
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2355.708171
iter 20 value 2271.777776
iter 30 value 2231.884247
iter 40 value 2224.973190
iter 50 value 2224.764465
iter 60 value 2224.752054
final value 2224.751077
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2182.823912
iter 20 value 2049.496198
iter 30 value 1997.102057
iter 40 value 1986.637633
iter 50 value 1985.763391
iter 60 value 1985.689394
iter 70 value 1985.684078
final value 1985.683653
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2347.392079
iter 20 value 2270.032965
iter 30 value 2223.616040
iter 40 value 2213.459192
iter 50 value 2213.163016
iter 60 value 2213.150172
iter 70 value 2213.149439
iter 70 value 2213.149417
iter 70 value 2213.149417
final value 2213.149417
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2162.610582
iter 20 value 2020.555436
iter 30 value 1972.331507
iter 40 value 1961.844370
iter 50 value 1960.877907
iter 60 value 1960.802740
iter 70 value 1960.798740
iter 70 value 1960.798727
iter 70 value 1960.798727
final value 1960.798727
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2349.673129
iter 20 value 2268.063067
iter 30 value 2226.733204
iter 40 value 2220.130167
iter 50 value 2219.918748
final value 2219.909035
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2191.401386
iter 20 value 2059.923064
iter 30 value 2013.767047
iter 40 value 2005.759878
iter 50 value 2005.082516
iter 60 value 2005.026513
iter 70 value 2005.021611
final value 2005.021420
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2365.119708
iter 20 value 2280.954075
iter 30 value 2237.302576
iter 40 value 2229.214889
iter 50 value 2228.938392
iter 60 value 2228.923251
final value 2228.922057
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2192.588321
iter 20 value 2046.714794
iter 30 value 1998.526823
iter 40 value 1989.315660
iter 50 value 1988.592979
iter 60 value 1988.532693
iter 70 value 1988.527482
final value 1988.527147
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2362.632171
iter 20 value 2274.351711
iter 30 value 2233.030694
iter 40 value 2225.851124
iter 50 value 2225.625273
iter 60 value 2225.613309
final value 2225.612621
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2202.651403
iter 20 value 2060.741875
iter 30 value 2014.150088
iter 40 value 2005.821164
iter 50 value 2005.063654
iter 60 value 2005.004895
iter 70 value 2004.997668
final value 2004.997260
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2351.453883
iter 20 value 2263.190480
iter 30 value 2219.308669
iter 40 value 2211.954330
iter 50 value 2211.658105
iter 60 value 2211.641536
final value 2211.639777
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2178.364709
iter 20 value 2039.524249
iter 30 value 1984.269780
iter 40 value 1974.424019
iter 50 value 1973.459974
iter 60 value 1973.381438
iter 70 value 1973.372141
final value 1973.371476
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2363.744569
iter 20 value 2274.058624
iter 30 value 2232.272871
iter 40 value 2225.442246
iter 50 value 2225.202202
iter 60 value 2225.191745
final value 2225.190152
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2197.078165
iter 20 value 2055.768343
iter 30 value 2009.489941
iter 40 value 1999.306628
iter 50 value 1998.537246
iter 60 value 1998.470965
iter 70 value 1998.464509
final value 1998.464086
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2354.198515
iter 20 value 2276.252810
iter 30 value 2234.502283
iter 40 value 2227.430376
iter 50 value 2227.245277
iter 60 value 2227.235073
final value 2227.234685
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2178.461849
iter 20 value 2044.435250
iter 30 value 2000.267991
iter 40 value 1991.227054
iter 50 value 1990.429505
iter 60 value 1990.367926
iter 70 value 1990.361556
final value 1990.361030
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2365.433740
iter 20 value 2281.993230
iter 30 value 2240.088856
iter 40 value 2231.617615
iter 50 value 2231.378821
iter 60 value 2231.367126
final value 2231.366066
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2193.337124
iter 20 value 2055.242158
iter 30 value 2000.573041
iter 40 value 1989.678948
iter 50 value 1988.759295
iter 60 value 1988.682470
iter 70 value 1988.677225
final value 1988.677079
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2351.268238
iter 20 value 2266.752442
iter 30 value 2224.249153
iter 40 value 2217.003046
iter 50 value 2216.757490
iter 60 value 2216.740702
iter 70 value 2216.739218
final value 2216.739098
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2183.316160
iter 20 value 2057.177506
iter 30 value 2000.004208
iter 40 value 1988.545567
iter 50 value 1987.653038
iter 60 value 1987.577812
final value 1987.570485
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2348.595940
iter 20 value 2263.646605
iter 30 value 2224.628220
iter 40 value 2218.071710
iter 50 value 2217.841059
iter 60 value 2217.827612
final value 2217.827078
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2175.214954
iter 20 value 2044.907985
iter 30 value 1996.009622
iter 40 value 1984.901123
iter 50 value 1984.071682
iter 60 value 1983.991882
iter 70 value 1983.987967
final value 1983.987814
converged
# weights: 132 (96 variable)
initial value 2833.585674
iter 10 value 2356.971315
iter 20 value 2277.022664
iter 30 value 2235.808701
iter 40 value 2228.047624
iter 50 value 2227.805700
iter 60 value 2227.793905
final value 2227.793414
converged
# weights: 144 (105 variable)
initial value 2833.585674
iter 10 value 2182.424608
iter 20 value 2049.871407
iter 30 value 2000.047057
iter 40 value 1989.904845
iter 50 value 1989.011680
iter 60 value 1988.943935
iter 70 value 1988.937205
final value 1988.936942
converged
# Check if models were stored properlyprint(length(vc.out.no_urban))
[1] 20
print(vc.out.no_urban[[1]])
Call:
multinom(formula = vc.int.no_urban, data = imp.out$imputations[[i]],
weights = imp.out$imputations[[i]]$weight, Hess = TRUE, model = TRUE,
maxit = 200)
Coefficients:
(Intercept) FXstatusexposed FXstatuspast POPSL2011 past.turnout
NoVote 1.6210613 -1.2265225 -0.5066831 -2.180056 -0.3904154
other -0.4687432 -0.8309691 0.1499763 -3.053410 2.0287819
PiS -2.2089241 -0.8952013 -0.8182740 -5.116848 2.2397636
age.expand[18,32) age.expand[44,57) age.expand[57,66) age.expand[66,85]
NoVote 0.1948160 0.1875986 -0.1292492 0.09296213
other 0.9393213 0.3613122 0.1358714 -0.56183759
PiS -0.1623657 0.5051207 0.3983716 0.30222920
female married income.quint ed_level employed religion
NoVote -0.01466391 -0.02153486 -0.211382732 -0.09436149 0.27790301 0.11575085
other -0.46396411 -0.31189131 -0.005173372 0.27535240 -0.09918772 0.02427902
PiS -0.16277167 -0.33040381 0.013258090 -0.02635902 0.38440994 0.53585825
hh_size LeftRightCatleft LeftRightCatright
NoVote -0.030238616 0.4053908 0.03761866
other -0.002360448 0.4223199 -0.31318910
PiS 0.083144638 -1.0776051 0.60896082
provinceKujawsko-pomorskie provinceLubelskie provinceLubuskie
NoVote 0.3088133 0.60373436 0.43180302
other 0.1651478 -0.03997579 0.06052799
PiS 0.7188878 0.44346549 -0.69456206
provinceLódzkie provinceMalopolskie provinceMazowieckie provinceOpolskie
NoVote 1.0077956 0.5690899 0.3326938 0.7174540
other 0.2818039 0.1606406 0.1254614 -0.3584057
PiS 0.7230397 0.3241110 0.3377929 -0.1315012
provincePodkarpackie provincePodlaskie provincePomorskie provinceSlaskie
NoVote 0.7680216 0.32617594 0.7031387 1.021936667
other 0.2059169 -0.50442805 -0.5420703 -0.006612491
PiS 1.0425507 -0.04414859 -0.3028555 0.409254598
provinceSwietokrzyskie provinceWarminsko-mazurskie provinceWielkopolskie
NoVote 0.00115575 0.10506403 0.5112409
other -0.29453578 -0.35156986 -0.4550949
PiS 0.25605612 -0.04507782 0.2966077
provinceZachodniopomorskie FXstatusexposed:POPSL2011
NoVote 0.5136484 0.5581463
other 0.2907287 2.0271577
PiS -0.1138510 2.7471494
FXstatuspast:POPSL2011
NoVote -0.2913450
other -0.1912481
PiS 0.4735537
Residual Deviance: 3978.672
AIC: 4188.672
# weights: 8 (3 variable)
initial value 2833.585674
final value 2691.064546
converged
# Out-of-Sample Performance using 10-fold Cross-Validationset.seed(42)cv_folds <-createFolds(obs.dat$vote.intent.rev3, k =10)# Load necessary packageslibrary(nnet) # For multinomial logistic regressionlibrary(caret) # For cross-validation# Ensure the dataset is availableif (!exists("obs.dat")) {stop("Error: obs.dat dataset is missing. Load AJPSimputations.RData first.")}# Define the number of folds for cross-validationset.seed(42)cv_folds <-createFolds(obs.dat$vote.intent.rev3, k =10)# Initialize storage for resultscv_results_with_urban <-matrix(NA, nrow =10, ncol =2) # [log-loss, accuracy]cv_results_without_urban <-matrix(NA, nrow =10, ncol =2)# Load necessary librarieslibrary(nnet) # Multinomial logistic regressionlibrary(caret) # Cross-validation# Ensure dataset existsif (!exists("obs.dat")) {stop("Error: 'obs.dat' dataset is missing. Load 'AJPSimputations.RData' first.")}# Remove any missing values from vote.intent.rev3 (needed for cross-validation)obs.dat <- obs.dat[!is.na(obs.dat$vote.intent.rev3), ]# Define the number of foldsset.seed(42)cv_folds <-createFolds(obs.dat$vote.intent.rev3, k =10)# Initialize storage for cross-validation resultscv_results_with_urban <-matrix(NA, nrow =10, ncol =2) # [log-loss, accuracy]cv_results_without_urban <-matrix(NA, nrow =10, ncol =2)# Run 10-fold Cross-Validationfor (i inseq_along(cv_folds)) {# Define training and test sets train_idx <-unlist(cv_folds[-i]) # Use 9 folds for training test_idx <- cv_folds[[i]] # Use 1 fold for testing train_data <- obs.dat[train_idx, ] test_data <- obs.dat[test_idx, ]# Ensure 'weight' variable exists in the datasetif (!"weight"%in%colnames(train_data)) {stop("Error: 'weight' variable is missing from the dataset.") }# Fit the model with urban predictor model_with_urban <-multinom(vc.int, data = train_data, weights = train_data$weight) preds_with_urban <-predict(model_with_urban, test_data, type ="probs")# Fit the model without urban predictor model_without_urban <-multinom(vc.int.no_urban, data = train_data, weights = train_data$weight) preds_without_urban <-predict(model_without_urban, test_data, type ="probs")# Ensure predicted probability columns match the response variable levels levels_test <-levels(obs.dat$vote.intent.rev3) # Factor levels in original datasetcolnames(preds_with_urban) <- levels_testcolnames(preds_without_urban) <- levels_test# Compute log-loss safely y_true_idx <-match(test_data$vote.intent.rev3, levels_test) # Match factor levels to indices valid_idx <-!is.na(y_true_idx) # Ensure valid indicesif (any(valid_idx)) { cv_results_with_urban[i, 1] <--mean(log(preds_with_urban[cbind(1:nrow(test_data[valid_idx, ]), y_true_idx[valid_idx])])) cv_results_with_urban[i, 2] <-mean(predict(model_with_urban, test_data) == test_data$vote.intent.rev3) cv_results_without_urban[i, 1] <--mean(log(preds_without_urban[cbind(1:nrow(test_data[valid_idx, ]), y_true_idx[valid_idx])])) cv_results_without_urban[i, 2] <-mean(predict(model_without_urban, test_data) == test_data$vote.intent.rev3) }}
# weights: 148 (108 variable)
initial value 1503.933013
iter 10 value 1126.795985
iter 20 value 987.047740
iter 30 value 956.944401
iter 40 value 954.364946
iter 50 value 954.018620
iter 60 value 953.981538
iter 70 value 953.981019
final value 953.980745
converged
# weights: 144 (105 variable)
initial value 1503.933013
iter 10 value 1089.953756
iter 20 value 982.625559
iter 30 value 959.717922
iter 40 value 957.928770
iter 50 value 957.601241
iter 60 value 957.579607
final value 957.579309
converged
# weights: 148 (108 variable)
initial value 1504.022885
iter 10 value 1163.602831
iter 20 value 1016.376585
iter 30 value 970.742084
iter 40 value 968.672108
iter 50 value 968.311236
iter 60 value 968.267737
iter 70 value 968.266236
final value 968.266217
converged
# weights: 144 (105 variable)
initial value 1504.022885
iter 10 value 1123.781044
iter 20 value 1000.605942
iter 30 value 975.183748
iter 40 value 973.712264
iter 50 value 973.499998
iter 60 value 973.486768
final value 973.486249
converged
# weights: 148 (108 variable)
initial value 1495.838405
iter 10 value 1115.057320
iter 20 value 986.739553
iter 30 value 952.959195
iter 40 value 950.637049
iter 50 value 950.169877
iter 60 value 950.137028
final value 950.136469
converged
# weights: 144 (105 variable)
initial value 1495.838405
iter 10 value 1107.863623
iter 20 value 983.369089
iter 30 value 957.686276
iter 40 value 955.919581
iter 50 value 955.428088
iter 60 value 955.400752
final value 955.400502
converged
# weights: 148 (108 variable)
initial value 1498.361624
iter 10 value 1069.756359
iter 20 value 980.277608
iter 30 value 941.520874
iter 40 value 938.265602
iter 50 value 937.718028
iter 60 value 937.527705
iter 70 value 937.331350
iter 80 value 937.294745
iter 90 value 937.290696
final value 937.289976
converged
# weights: 144 (105 variable)
initial value 1498.361624
iter 10 value 1068.741176
iter 20 value 966.566889
iter 30 value 945.837378
iter 40 value 944.730554
iter 50 value 944.394456
iter 60 value 944.107476
iter 70 value 944.005469
iter 80 value 943.996604
iter 90 value 943.995065
final value 943.994926
converged
# weights: 148 (108 variable)
initial value 1500.931969
iter 10 value 1125.670768
iter 20 value 1000.944544
iter 30 value 964.933727
iter 40 value 963.237505
iter 50 value 962.874390
iter 60 value 962.816736
final value 962.816115
converged
# weights: 144 (105 variable)
initial value 1500.931969
iter 10 value 1126.717378
iter 20 value 998.227266
iter 30 value 971.048120
iter 40 value 969.661381
iter 50 value 969.423157
iter 60 value 969.406568
final value 969.406399
converged
# weights: 148 (108 variable)
initial value 1497.094820
iter 10 value 1135.083777
iter 20 value 982.642708
iter 30 value 957.833941
iter 40 value 956.036279
iter 50 value 955.785594
iter 60 value 955.767648
final value 955.767334
converged
# weights: 144 (105 variable)
initial value 1497.094820
iter 10 value 1093.887148
iter 20 value 982.559690
iter 30 value 961.743052
iter 40 value 959.960596
iter 50 value 959.626314
iter 60 value 959.605591
final value 959.605374
converged
# weights: 148 (108 variable)
initial value 1490.824720
iter 10 value 1091.531186
iter 20 value 989.545159
iter 30 value 964.773048
iter 40 value 963.200069
iter 50 value 962.989155
iter 60 value 962.968514
iter 70 value 962.967478
final value 962.967434
converged
# weights: 144 (105 variable)
initial value 1490.824720
iter 10 value 1070.281241
iter 20 value 985.448718
iter 30 value 970.217851
iter 40 value 969.155172
iter 50 value 968.997749
iter 60 value 968.983226
final value 968.982582
converged
# weights: 148 (108 variable)
initial value 1497.241434
iter 10 value 1109.064667
iter 20 value 1011.860817
iter 30 value 975.628551
iter 40 value 972.947603
iter 50 value 972.667832
iter 60 value 972.648888
final value 972.648277
converged
# weights: 144 (105 variable)
initial value 1497.241434
iter 10 value 1100.974272
iter 20 value 1003.974038
iter 30 value 979.348077
iter 40 value 977.575732
iter 50 value 977.369205
iter 60 value 977.336287
final value 977.335818
converged
# weights: 148 (108 variable)
initial value 1491.027262
iter 10 value 1128.978201
iter 20 value 974.014220
iter 30 value 948.225294
iter 40 value 946.137831
iter 50 value 945.791507
iter 60 value 945.758874
final value 945.758212
converged
# weights: 144 (105 variable)
initial value 1491.027262
iter 10 value 1087.391559
iter 20 value 969.255144
iter 30 value 950.600168
iter 40 value 949.007325
iter 50 value 948.719123
iter 60 value 948.703427
final value 948.703251
converged
# weights: 148 (108 variable)
initial value 1502.177627
iter 10 value 1145.300519
iter 20 value 1014.442003
iter 30 value 975.407104
iter 40 value 973.905411
iter 50 value 973.554118
iter 60 value 973.513444
final value 973.511664
converged
# weights: 144 (105 variable)
initial value 1502.177627
iter 10 value 1111.656201
iter 20 value 1001.584183
iter 30 value 979.838262
iter 40 value 977.969689
iter 50 value 977.761924
iter 60 value 977.745308
final value 977.744860
converged
# Compute the average cross-validation scorescv_logloss_with_urban <-mean(cv_results_with_urban[, 1], na.rm =TRUE)cv_logloss_without_urban <-mean(cv_results_without_urban[, 1], na.rm =TRUE)cv_accuracy_with_urban <-mean(cv_results_with_urban[, 2], na.rm =TRUE)cv_accuracy_without_urban <-mean(cv_results_without_urban[, 2], na.rm =TRUE)# Create a results dataframecomparison_df <-data.frame(Metric =c("CV Log-Loss", "CV Accuracy"),With_Urban =c(cv_logloss_with_urban, cv_accuracy_with_urban),Without_Urban =c(cv_logloss_without_urban, cv_accuracy_without_urban))# Print the resultsprint(comparison_df)
Metric With_Urban Without_Urban
1 CV Log-Loss NaN NaN
2 CV Accuracy NaN NaN
# Run 10-fold Cross-Validationfor (i inseq_along(cv_folds)) {# Define training and test sets train_idx <-unlist(cv_folds[-i]) # Use 9 folds for training test_idx <- cv_folds[[i]] # Use 1 fold for testing train_data <- obs.dat[train_idx, ] test_data <- obs.dat[test_idx, ]# Ensure weight variable existsif (!"weight"%in%colnames(train_data)) {stop("Error: 'weight' variable is missing in the dataset.") }# Fit the model with urban predictor model_with_urban <-multinom(vc.int, data = train_data, weights = train_data$weight) preds_with_urban <-predict(model_with_urban, test_data, type ="probs")# Fit the model without urban predictor model_without_urban <-multinom(vc.int.no_urban, data = train_data, weights = train_data$weight) preds_without_urban <-predict(model_without_urban, test_data, type ="probs")# Compute log-loss and accuracy cv_results_with_urban[i, 1] <--mean(log(preds_with_urban[cbind(1:nrow(test_data), match(test_data$vote.intent.rev3, colnames(preds_with_urban)))])) cv_results_with_urban[i, 2] <-mean(predict(model_with_urban, test_data) == test_data$vote.intent.rev3) cv_results_without_urban[i, 1] <--mean(log(preds_without_urban[cbind(1:nrow(test_data), match(test_data$vote.intent.rev3, colnames(preds_without_urban)))])) cv_results_without_urban[i, 2] <-mean(predict(model_without_urban, test_data) == test_data$vote.intent.rev3)}
# weights: 148 (108 variable)
initial value 1503.933013
iter 10 value 1126.795985
iter 20 value 987.047740
iter 30 value 956.944401
iter 40 value 954.364946
iter 50 value 954.018620
iter 60 value 953.981538
iter 70 value 953.981019
final value 953.980745
converged
# weights: 144 (105 variable)
initial value 1503.933013
iter 10 value 1089.953756
iter 20 value 982.625559
iter 30 value 959.717922
iter 40 value 957.928770
iter 50 value 957.601241
iter 60 value 957.579607
final value 957.579309
converged
# weights: 148 (108 variable)
initial value 1504.022885
iter 10 value 1163.602831
iter 20 value 1016.376585
iter 30 value 970.742084
iter 40 value 968.672108
iter 50 value 968.311236
iter 60 value 968.267737
iter 70 value 968.266236
final value 968.266217
converged
# weights: 144 (105 variable)
initial value 1504.022885
iter 10 value 1123.781044
iter 20 value 1000.605942
iter 30 value 975.183748
iter 40 value 973.712264
iter 50 value 973.499998
iter 60 value 973.486768
final value 973.486249
converged
# weights: 148 (108 variable)
initial value 1495.838405
iter 10 value 1115.057320
iter 20 value 986.739553
iter 30 value 952.959195
iter 40 value 950.637049
iter 50 value 950.169877
iter 60 value 950.137028
final value 950.136469
converged
# weights: 144 (105 variable)
initial value 1495.838405
iter 10 value 1107.863623
iter 20 value 983.369089
iter 30 value 957.686276
iter 40 value 955.919581
iter 50 value 955.428088
iter 60 value 955.400752
final value 955.400502
converged
# weights: 148 (108 variable)
initial value 1498.361624
iter 10 value 1069.756359
iter 20 value 980.277608
iter 30 value 941.520874
iter 40 value 938.265602
iter 50 value 937.718028
iter 60 value 937.527705
iter 70 value 937.331350
iter 80 value 937.294745
iter 90 value 937.290696
final value 937.289976
converged
# weights: 144 (105 variable)
initial value 1498.361624
iter 10 value 1068.741176
iter 20 value 966.566889
iter 30 value 945.837378
iter 40 value 944.730554
iter 50 value 944.394456
iter 60 value 944.107476
iter 70 value 944.005469
iter 80 value 943.996604
iter 90 value 943.995065
final value 943.994926
converged
# weights: 148 (108 variable)
initial value 1500.931969
iter 10 value 1125.670768
iter 20 value 1000.944544
iter 30 value 964.933727
iter 40 value 963.237505
iter 50 value 962.874390
iter 60 value 962.816736
final value 962.816115
converged
# weights: 144 (105 variable)
initial value 1500.931969
iter 10 value 1126.717378
iter 20 value 998.227266
iter 30 value 971.048120
iter 40 value 969.661381
iter 50 value 969.423157
iter 60 value 969.406568
final value 969.406399
converged
# weights: 148 (108 variable)
initial value 1497.094820
iter 10 value 1135.083777
iter 20 value 982.642708
iter 30 value 957.833941
iter 40 value 956.036279
iter 50 value 955.785594
iter 60 value 955.767648
final value 955.767334
converged
# weights: 144 (105 variable)
initial value 1497.094820
iter 10 value 1093.887148
iter 20 value 982.559690
iter 30 value 961.743052
iter 40 value 959.960596
iter 50 value 959.626314
iter 60 value 959.605591
final value 959.605374
converged
# weights: 148 (108 variable)
initial value 1490.824720
iter 10 value 1091.531186
iter 20 value 989.545159
iter 30 value 964.773048
iter 40 value 963.200069
iter 50 value 962.989155
iter 60 value 962.968514
iter 70 value 962.967478
final value 962.967434
converged
# weights: 144 (105 variable)
initial value 1490.824720
iter 10 value 1070.281241
iter 20 value 985.448718
iter 30 value 970.217851
iter 40 value 969.155172
iter 50 value 968.997749
iter 60 value 968.983226
final value 968.982582
converged
# weights: 148 (108 variable)
initial value 1497.241434
iter 10 value 1109.064667
iter 20 value 1011.860817
iter 30 value 975.628551
iter 40 value 972.947603
iter 50 value 972.667832
iter 60 value 972.648888
final value 972.648277
converged
# weights: 144 (105 variable)
initial value 1497.241434
iter 10 value 1100.974272
iter 20 value 1003.974038
iter 30 value 979.348077
iter 40 value 977.575732
iter 50 value 977.369205
iter 60 value 977.336287
final value 977.335818
converged
# weights: 148 (108 variable)
initial value 1491.027262
iter 10 value 1128.978201
iter 20 value 974.014220
iter 30 value 948.225294
iter 40 value 946.137831
iter 50 value 945.791507
iter 60 value 945.758874
final value 945.758212
converged
# weights: 144 (105 variable)
initial value 1491.027262
iter 10 value 1087.391559
iter 20 value 969.255144
iter 30 value 950.600168
iter 40 value 949.007325
iter 50 value 948.719123
iter 60 value 948.703427
final value 948.703251
converged
# weights: 148 (108 variable)
initial value 1502.177627
iter 10 value 1145.300519
iter 20 value 1014.442003
iter 30 value 975.407104
iter 40 value 973.905411
iter 50 value 973.554118
iter 60 value 973.513444
final value 973.511664
converged
# weights: 144 (105 variable)
initial value 1502.177627
iter 10 value 1111.656201
iter 20 value 1001.584183
iter 30 value 979.838262
iter 40 value 977.969689
iter 50 value 977.761924
iter 60 value 977.745308
final value 977.744860
converged
# Compute the average cross-validation scorescv_logloss_with_urban <-mean(cv_results_with_urban[, 1], na.rm =TRUE)cv_logloss_without_urban <-mean(cv_results_without_urban[, 1], na.rm =TRUE)cv_accuracy_with_urban <-mean(cv_results_with_urban[, 2], na.rm =TRUE)cv_accuracy_without_urban <-mean(cv_results_without_urban[, 2], na.rm =TRUE)# Create a results dataframecomparison_df <-data.frame(Metric =c("CV Log-Loss", "CV Accuracy"),With_Urban =c(cv_logloss_with_urban, cv_accuracy_with_urban),Without_Urban =c(cv_logloss_without_urban, cv_accuracy_without_urban))# Print the resultsprint(comparison_df)
Metric With_Urban Without_Urban
1 CV Log-Loss NaN NaN
2 CV Accuracy NaN NaN
model <-multinom(vc.int.no_urban, data = train_data, weights = train_data$weight)
# weights: 144 (105 variable)
initial value 1502.177627
iter 10 value 1111.656201
iter 20 value 1001.584183
iter 30 value 979.838262
iter 40 value 977.969689
iter 50 value 977.761924
iter 60 value 977.745308
final value 977.744860
converged
Metric With_Urban Without_Urban
1 Log-Likelihood -1976.3630933 -1989.3360409
2 AIC 4168.7261866 4188.6720819
3 BIC 4775.9738933 4779.0517968
4 McFadden's R² 0.2655832 0.2607624
5 CV Log-Loss NA NA
6 CV Accuracy NA NA
Out of Sample Predictive Peformance
To evaluate the out of sample predictive performance of the models of urban and without urban predictor. We can see how the log loss here with a comparison of urban having 2.7449 and without urban having 2.7409. The model without urban part has a little bit lower of a log loss showing a better probablity prediction overall. With urban in accuracy has with urban being 0.5457 and without urban having 0.5396 meaning the urban variable also ist he bets for having the highest accuracy. The difference found in the log-loss is 0.004 meaning that getting rid of the urban variable does not decrease the model abilities as much. The accuracy difference is also very little with the model with the urban variable doing a little bit better. The conclusion I come to is if we think accuracy is most important then the bset model would be just urban and if we are thinking log -loss is most important than doing it without urban would be best.
library(nnet) library(caret)# Remove rows with NA in the target variableobs.dat <- obs.dat[!is.na(obs.dat$vote.intent.rev3), ]# Ensure there are no NAs in predictorsobs.dat <-na.omit(obs.dat) # Drop rows with any NA values# Check for missing values after cleanupprint(colSums(is.na(obs.dat))) # Should print all zeros
test_model <-multinom(vc.simp.no_urban, data = obs.dat,weights = obs.dat$weight,Hess =TRUE, maxit =200, model =TRUE)
# weights: 132 (96 variable)
initial value 466.202189
iter 10 value 371.914103
iter 20 value 321.084422
iter 30 value 317.765577
iter 40 value 317.293606
iter 50 value 317.256869
iter 60 value 317.228576
iter 70 value 317.221205
iter 80 value 317.220768
final value 317.220730
converged
set.seed(42)cv_folds <-createFolds(obs.dat$vote.intent.rev3, k =10)# Initialize storage for resultscv_results_with_urban <-matrix(NA, nrow =10, ncol =2) cv_results_without_urban <-matrix(NA, nrow =10, ncol =2)for (i inseq_along(cv_folds)) { train_idx <-unlist(cv_folds[-i]) test_idx <- cv_folds[[i]] train_data <- obs.dat[train_idx, ] test_data <- obs.dat[test_idx, ]# Fit the models model_with_urban <-multinom(vc.int, data = train_data, weights = train_data$weight) model_without_urban <-multinom(vc.int.no_urban, data = train_data, weights = train_data$weight)# Get predictions preds_with_urban <-predict(model_with_urban, test_data, type ="probs") preds_without_urban <-predict(model_without_urban, test_data, type ="probs")# Ensure probability matrices have correct column names levels_test <-levels(obs.dat$vote.intent.rev3)colnames(preds_with_urban) <- levels_testcolnames(preds_without_urban) <- levels_test# Get true class indices y_true_idx <-match(test_data$vote.intent.rev3, levels_test) valid_idx <-!is.na(y_true_idx)# Avoid log(0) error in log-loss by setting min probability threshold eps <-1e-15# Smallest allowed probability preds_with_urban <-pmax(preds_with_urban, eps) preds_without_urban <-pmax(preds_without_urban, eps)# Compute log-loss & accuracy safelyif (any(valid_idx)) { cv_results_with_urban[i, 1] <--mean(log(preds_with_urban[cbind(1:nrow(test_data[valid_idx, ]), y_true_idx[valid_idx])])) cv_results_with_urban[i, 2] <-mean(predict(model_with_urban, test_data) == test_data$vote.intent.rev3) cv_results_without_urban[i, 1] <--mean(log(preds_without_urban[cbind(1:nrow(test_data[valid_idx, ]), y_true_idx[valid_idx])])) cv_results_without_urban[i, 2] <-mean(predict(model_without_urban, test_data) == test_data$vote.intent.rev3) }}
# weights: 148 (108 variable)
initial value 422.855955
iter 10 value 297.395713
iter 20 value 239.401338
iter 30 value 228.756724
iter 40 value 227.847351
iter 50 value 227.749956
iter 60 value 227.667571
iter 70 value 227.615488
iter 80 value 227.596198
iter 90 value 227.590999
iter 100 value 227.590600
final value 227.590600
stopped after 100 iterations
# weights: 144 (105 variable)
initial value 422.855955
iter 10 value 294.353437
iter 20 value 241.404011
iter 30 value 234.642986
iter 40 value 234.169852
iter 50 value 234.080168
iter 60 value 233.990126
iter 70 value 233.943111
iter 80 value 233.926829
iter 90 value 233.923299
final value 233.923199
converged
# weights: 148 (108 variable)
initial value 418.338956
iter 10 value 276.297966
iter 20 value 235.392434
iter 30 value 224.452052
iter 40 value 223.463698
iter 50 value 223.324666
iter 60 value 223.246947
iter 70 value 223.182953
iter 80 value 223.170781
iter 90 value 223.168318
iter 100 value 223.166577
final value 223.166577
stopped after 100 iterations
# weights: 144 (105 variable)
initial value 418.338956
iter 10 value 276.227103
iter 20 value 234.861418
iter 30 value 229.152302
iter 40 value 228.781888
iter 50 value 228.653004
iter 60 value 228.577425
iter 70 value 228.531393
iter 80 value 228.521422
iter 90 value 228.519230
iter 100 value 228.518634
final value 228.518634
stopped after 100 iterations
# weights: 148 (108 variable)
initial value 419.893210
iter 10 value 284.614880
iter 20 value 240.601015
iter 30 value 229.044225
iter 40 value 227.335948
iter 50 value 227.006479
iter 60 value 226.915172
iter 70 value 226.884563
iter 80 value 226.872684
iter 90 value 226.862473
iter 100 value 226.861949
final value 226.861949
stopped after 100 iterations
# weights: 144 (105 variable)
initial value 419.893210
iter 10 value 286.588148
iter 20 value 238.844549
iter 30 value 232.703464
iter 40 value 231.596707
iter 50 value 231.359102
iter 60 value 231.273592
iter 70 value 231.242672
iter 80 value 231.230966
iter 90 value 231.227785
final value 231.227702
converged
# weights: 148 (108 variable)
initial value 417.329804
iter 10 value 283.057737
iter 20 value 234.393637
iter 30 value 219.570691
iter 40 value 218.420464
iter 50 value 218.302226
iter 60 value 218.249399
iter 70 value 218.207584
iter 80 value 218.196320
iter 90 value 218.180040
iter 100 value 218.176427
final value 218.176427
stopped after 100 iterations
# weights: 144 (105 variable)
initial value 417.329804
iter 10 value 303.854558
iter 20 value 232.162558
iter 30 value 224.507597
iter 40 value 224.131531
iter 50 value 224.010727
iter 60 value 223.964684
iter 70 value 223.933257
iter 80 value 223.926583
iter 90 value 223.909682
iter 100 value 223.909313
final value 223.909313
stopped after 100 iterations
# weights: 148 (108 variable)
initial value 419.393936
iter 10 value 282.306378
iter 20 value 234.193176
iter 30 value 227.967385
iter 40 value 226.957784
iter 50 value 226.702280
iter 60 value 226.649688
iter 70 value 226.592873
iter 80 value 226.576190
iter 90 value 226.574117
final value 226.573981
converged
# weights: 144 (105 variable)
initial value 419.393936
iter 10 value 278.534660
iter 20 value 236.829397
iter 30 value 232.547076
iter 40 value 231.923509
iter 50 value 231.719939
iter 60 value 231.670370
iter 70 value 231.614948
iter 80 value 231.604603
iter 90 value 231.603576
final value 231.603563
converged
# weights: 148 (108 variable)
initial value 423.407083
iter 10 value 284.819287
iter 20 value 240.651486
iter 30 value 233.335615
iter 40 value 232.438675
iter 50 value 232.262448
iter 60 value 232.230181
iter 70 value 232.159375
iter 80 value 232.145359
iter 90 value 232.144221
final value 232.144117
converged
# weights: 144 (105 variable)
initial value 423.407083
iter 10 value 281.986877
iter 20 value 241.885637
iter 30 value 237.622145
iter 40 value 237.143548
iter 50 value 236.980510
iter 60 value 236.935070
iter 70 value 236.864070
iter 80 value 236.854567
iter 90 value 236.853944
final value 236.853918
converged
# weights: 148 (108 variable)
initial value 420.621223
iter 10 value 281.525388
iter 20 value 231.893981
iter 30 value 226.624707
iter 40 value 225.838895
iter 50 value 225.702534
iter 60 value 225.675834
iter 70 value 225.621787
iter 80 value 225.603983
iter 90 value 225.602039
final value 225.601948
converged
# weights: 144 (105 variable)
initial value 420.621223
iter 10 value 280.304473
iter 20 value 234.569819
iter 30 value 230.423621
iter 40 value 229.944814
iter 50 value 229.815124
iter 60 value 229.764623
iter 70 value 229.710572
iter 80 value 229.701897
iter 90 value 229.701167
final value 229.701159
converged
# weights: 148 (108 variable)
initial value 419.716326
iter 10 value 285.883246
iter 20 value 238.878641
iter 30 value 229.995539
iter 40 value 228.844963
iter 50 value 228.554821
iter 60 value 228.432798
iter 70 value 228.406116
iter 80 value 228.398590
iter 90 value 228.397773
final value 228.397758
converged
# weights: 144 (105 variable)
initial value 419.716326
iter 10 value 290.488936
iter 20 value 242.494490
iter 30 value 235.362408
iter 40 value 234.746013
iter 50 value 234.462260
iter 60 value 234.376145
iter 70 value 234.351924
iter 80 value 234.346501
iter 90 value 234.345992
final value 234.345987
converged
# weights: 148 (108 variable)
initial value 419.248348
iter 10 value 300.737265
iter 20 value 236.543145
iter 30 value 225.342826
iter 40 value 224.147499
iter 50 value 223.953581
iter 60 value 223.856465
iter 70 value 223.798891
iter 80 value 223.784433
iter 90 value 223.783918
final value 223.783799
converged
# weights: 144 (105 variable)
initial value 419.248348
iter 10 value 301.482476
iter 20 value 236.083945
iter 30 value 228.976304
iter 40 value 228.340862
iter 50 value 228.163998
iter 60 value 228.065117
iter 70 value 228.031419
iter 80 value 228.026442
iter 90 value 228.026201
final value 228.026183
converged
# weights: 148 (108 variable)
initial value 415.014860
iter 10 value 284.324239
iter 20 value 232.634389
iter 30 value 223.887327
iter 40 value 223.202357
iter 50 value 223.019879
iter 60 value 222.946256
iter 70 value 222.892731
iter 80 value 222.886042
iter 90 value 222.882709
iter 100 value 222.882527
final value 222.882527
stopped after 100 iterations
# weights: 144 (105 variable)
initial value 415.014860
iter 10 value 281.026445
iter 20 value 235.812717
iter 30 value 231.056200
iter 40 value 230.667613
iter 50 value 230.551453
iter 60 value 230.468395
iter 70 value 230.429499
iter 80 value 230.423132
iter 90 value 230.419875
final value 230.419832
converged
# Compute final average cross-validation metricscv_logloss_with_urban <-mean(cv_results_with_urban[, 1], na.rm =TRUE)cv_logloss_without_urban <-mean(cv_results_without_urban[, 1], na.rm =TRUE)cv_accuracy_with_urban <-mean(cv_results_with_urban[, 2], na.rm =TRUE)cv_accuracy_without_urban <-mean(cv_results_without_urban[, 2], na.rm =TRUE)# Create a comparison tablecomparison_df <-data.frame(Metric =c("Log-Loss", "Accuracy"),With_Urban =c(cv_logloss_with_urban, cv_accuracy_with_urban),Without_Urban =c(cv_logloss_without_urban, cv_accuracy_without_urban))# Print the tableprint(comparison_df)
The plot shows the dependent variable of vote.intent.rev which has a description of party vote intention for the lower house ballot. This has 5 categories Dk(Don’t Know), PiS, PO/PSL, Other, and NoVote. This is categorical and the variable shows the way people vote differently all of these categories are good enough to represent the populations so there is no truncation or rarity. A potential problem can be in the form of the high number of don’t know responses which can influence how we look at the models for who people decide to vote for. This model is not binary since it has more than two categories meaning that a multinomial model is best. The model the author used was model 3 to explain the outcome variables. We have seen how people with FX exposure loans has a higher chance of voting for the party that wast eh opposite being PiS than people who weren’t as exposed. This model tells us that economic struggles because of the FX loans decrease influenced the way people voted to support political groups that promised financial relief. The models with just urban performsa little bit better than the one with not. It has a higher likelihood.
cat("- Most common category:", summary_stats$dependent_var[1], "(", round(summary_stats$percentage[1] *100, 1), "%)\n")
- Most common category: ( 26 %)
cat("- Least common category:", summary_stats$dependent_var[nrow(summary_stats)], "(", round(summary_stats$percentage[nrow(summary_stats)] *100, 1), "%)\n")
- Least common category: ( 0.1 %)
cat("- No extreme imbalance, but 'DK' (Don't Know) is the most common category, which may impact analysis.\n")
- No extreme imbalance, but 'DK' (Don't Know) is the most common category, which may impact analysis.
Quantity of Interest Model
The quantity of interest is predicted probabilities of voting choices based on Swiss Franc exposure. I chose this to find how someone votes based on a candidate can be based on the economic situation of the shock of loans of Swiss Franc in the Polish parliamentary election. The model uses multinomial logistic regression to see this relationship. The model predicts and plots the probabilities of different votes being abstain, other and PiS due to theirexposure of FX loans from exposed, none and past. This helps us understand the overall problems in politics when an economic shock happens.
Other Quantity of Interest model
The other model checks how much FX exposure loans affects a person’s chance to vote for PiS political party in the election from Poland .The model uses the exposure and past for the PiS party for the people voting in these elections. The quantity of interest here is the first difference is the chance of someone voting for the PiS party when a person ’s exposure to FX changes. This explains to us if individuals who used to have FX loans have a higher chance or lower chance of voting for the PiS than people who didn’t have one before. This will help our analysis by telling us if people being financially vulnerable would lead to them changing their political preference.
I am confident in the author’s conclusion from their data sources being surveys from Poland’s 2015 elections around the idea of economic shocks and politics regarding these relationships. The author’s use of this original survey makes his claims stronger in his research. The author uses an experiment done with people’s exposure to the shock and how their political affiliations may have changed.
The author of the paper looks more into the idea of FX shock at the time and people’s exposure mostly affecting their vote for the PiS campaign while the PiS campaign of being a more anti-migrant and far-right party could also be a combined reason why people ended up voting for this party. I would also like to see the paper compare to countries who may be facing similar FX borrowing at the same time in elections like surrounding European ones. Also looking at the way different political groups made people think of the FX shock at the time. Looking at this can help determine if the media made by these parties affected the way people thought and voted on the issue. Adding a part of the same paper to see if there are similar effects seen in a country where the party that is already in power is a populist party than one that is centrist would be interesting. This is interesting considering that his paper thinks that opposition parties can win a lot more from a crisis with money but what happens when a party like it is already in power? The paper does control for variables like attitudes that are not for immigrants but does not see if the exposure to FX shock shaped these types of attitudes which could be a reason for why people switched parties. This paper also has the assumption that FX shock voters believed their mortgage loans were most important for them when voting in this election. The paper does not see if the voters were most concerned about the FX shock as most important during the 2015 election so another study looking at this could help make this paper stronger.
I used Ai to check on code we got errors and was stuck on a problem. I also did this to fix problems when double checking I was properly thinking of the models resulsts. I also used it in order to make sure I had my figures corrected and why my code wasn’t loading properly. This as done in order to see how my code may have been not being able to render to a pdf as well because of issues.
Work Cited
Frye, Timothy, and Edward D. Mansfield. 2020. “The Political Consequences of External Economic Shocks: Evidence from Poland.” American Journal of Political Science 64 (4): 904–920. https://www.jstor.org/stable/45295356..