#data
load("~/Desktop/NORFACE/trilogues_number.RData")
load("~/Desktop/NORFACE/trilogues_duration.RData")

#subset data omitting outlier
trilogues_duration_noRegi <- trilogues_duration %>% filter(N_trilogues < 60)
trilogues_number_noRegi <- trilogues_number %>% filter(N_trilogues < 60)
#correlation plots
correlation_data1 <- trilogues_duration %>% dplyr::select(N_trilogues,  
                          proposal_t_eupolarizarion , proposal_t_wmean_eu_salience  ,
                             Interinst_conflict , EP_polarization , council_dissent ,
                             N_eurovoc_terms  , competence_length  , ep_amendments_tabled , elections_days, duration_negotiations_days)

cor1 <- cor(correlation_data1, use = "complete.obs")
corrplot(cor1,   method='color', tl.col = "black",  tl.cex = 0.7,   type = "full", tl.srt = 45, addCoef.col = "black", number.cex=0.7)

correlation_data2 <- trilogues_number %>% dplyr::select(N_trilogues,  
                          proposal_t_eupolarizarion , proposal_t_wmean_eu_salience  ,
                             Interinst_conflict , EP_polarization , council_dissent ,
                             N_eurovoc_terms  , competence_length  , ep_amendments_tabled , elections_days, duration_negotiations_days)

cor2 <- cor(correlation_data2, use = "complete.obs")
corrplot(cor2,   method='color', tl.col = "black",  tl.cex = 0.7,   type = "full", tl.srt = 45,
             addCoef.col = "black", number.cex=0.7)

rm(cor1, correlation_data1, cor2, correlation_data2)

#Models INTENSITY OF TRILOGUES

Modelling:
1. no CAP FEs –> not enough observations
2. instead of year FE, EP term FE
3. ep_amenmdnets_tabled –> use it as a proxy for EP polarization (then we do not have issues with correlation between EP_polarization measure and inter-inst conflict)
4. Variables:
- main: EU polarization at the t of proposal and EU salience at the t of proposal (Average t between proposal and first trilogue is 13 months)
- institutional controls: Council dissent (sum of abstentions and against votes), EP polarization (n of tabled amendments), interinst conflict
- procedure controls: form, package_deal (1 if proposal is part of a package), complexity (N_eurovoc_terms), new vs amending (1 if new), days to next EP elections (from proposal) // election proximity dummy (1 if proposal submitted in the last year of EP term), competence_length, authority expansion
5. Method: negative binomial regression
6. Two sets of models: with and without outliers (regi package procedures with 85 trilogues)

#with outlier
#model with contrinous elections variable
m1_intensity <- glm.nb(N_trilogues ~ 
                             proposal_t_eupolarizarion + proposal_t_wmean_eu_salience  +
                             Interinst_conflict + ep_amendments_tabled + council_dissent +
                             N_eurovoc_terms + factor(package_deal) + competence_length + factor(new) + factor(form) + elections_days + lr_proposal_probability +
                              factor(term),
                           data = trilogues_number)

summary(m1_intensity)
## 
## Call:
## glm.nb(formula = N_trilogues ~ proposal_t_eupolarizarion + proposal_t_wmean_eu_salience + 
##     Interinst_conflict + ep_amendments_tabled + council_dissent + 
##     N_eurovoc_terms + factor(package_deal) + competence_length + 
##     factor(new) + factor(form) + elections_days + lr_proposal_probability + 
##     factor(term), data = trilogues_number, init.theta = 2.149228153, 
##     link = log)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -3.1132  -0.7580  -0.2088   0.2670   4.7045  
## 
## Coefficients:
##                                Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                  -7.196e-01  4.658e-01  -1.545  0.12232    
## proposal_t_eupolarizarion     3.226e-01  2.022e-01   1.596  0.11058    
## proposal_t_wmean_eu_salience  7.771e-01  3.117e-01   2.493  0.01266 *  
## Interinst_conflict           -1.624e-01  9.224e-02  -1.761  0.07826 .  
## ep_amendments_tabled          2.537e-03  4.936e-04   5.141 2.73e-07 ***
## council_dissent               6.212e-02  3.000e-02   2.070  0.03841 *  
## N_eurovoc_terms               3.424e-02  2.485e-02   1.378  0.16827    
## factor(package_deal)1         1.374e+00  1.071e-01  12.824  < 2e-16 ***
## competence_length            -6.568e-03  3.673e-03  -1.788  0.07376 .  
## factor(new)1                  1.782e-02  9.864e-02   0.181  0.85662    
## factor(form)Directive         5.627e-01  1.906e-01   2.952  0.00316 ** 
## factor(form)Regulation        5.416e-01  1.796e-01   3.015  0.00257 ** 
## elections_days                9.848e-05  1.139e-04   0.865  0.38714    
## lr_proposal_probability       4.750e-01  1.506e-01   3.154  0.00161 ** 
## factor(term)8                -9.458e-02  9.676e-02  -0.977  0.32834    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for Negative Binomial(2.1492) family taken to be 1)
## 
##     Null deviance: 730.43  on 427  degrees of freedom
## Residual deviance: 414.40  on 413  degrees of freedom
##   (103 observations deleted due to missingness)
## AIC: 1981.3
## 
## Number of Fisher Scoring iterations: 1
## 
## 
##               Theta:  2.149 
##           Std. Err.:  0.212 
## 
##  2 x log-likelihood:  -1949.287
#model with dummy elections variable
m2_intensity <- glm.nb(N_trilogues ~ 
                             proposal_t_eupolarizarion + proposal_t_wmean_eu_salience  +
                             Interinst_conflict + ep_amendments_tabled + council_dissent +
                             N_eurovoc_terms + factor(package_deal) + competence_length + factor(new) + factor(form) + factor(elections_dummy) + lr_proposal_probability +
                              factor(term),
                           data = trilogues_number)

summary(m2_intensity)
## 
## Call:
## glm.nb(formula = N_trilogues ~ proposal_t_eupolarizarion + proposal_t_wmean_eu_salience + 
##     Interinst_conflict + ep_amendments_tabled + council_dissent + 
##     N_eurovoc_terms + factor(package_deal) + competence_length + 
##     factor(new) + factor(form) + factor(elections_dummy) + lr_proposal_probability + 
##     factor(term), data = trilogues_number, init.theta = 2.18031119, 
##     link = log)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -3.0952  -0.7730  -0.2093   0.2739   4.6455  
## 
## Coefficients:
##                                Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                  -0.6447754  0.4485877  -1.437  0.15062    
## proposal_t_eupolarizarion     0.3140623  0.1992997   1.576  0.11507    
## proposal_t_wmean_eu_salience  0.8463453  0.3120576   2.712  0.00668 ** 
## Interinst_conflict           -0.1801803  0.0919799  -1.959  0.05012 .  
## ep_amendments_tabled          0.0024907  0.0004894   5.089  3.6e-07 ***
## council_dissent               0.0637549  0.0299215   2.131  0.03311 *  
## N_eurovoc_terms               0.0379335  0.0246980   1.536  0.12456    
## factor(package_deal)1         1.3377421  0.1072351  12.475  < 2e-16 ***
## competence_length            -0.0059331  0.0036523  -1.624  0.10427    
## factor(new)1                  0.0290433  0.0984680   0.295  0.76803    
## factor(form)Directive         0.5341906  0.1906333   2.802  0.00508 ** 
## factor(form)Regulation        0.5181724  0.1795574   2.886  0.00390 ** 
## factor(elections_dummy)1     -0.2863151  0.1398257  -2.048  0.04059 *  
## lr_proposal_probability       0.4449176  0.1507092   2.952  0.00316 ** 
## factor(term)8                -0.1321846  0.0982512  -1.345  0.17850    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for Negative Binomial(2.1803) family taken to be 1)
## 
##     Null deviance: 736.94  on 427  degrees of freedom
## Residual deviance: 414.46  on 413  degrees of freedom
##   (103 observations deleted due to missingness)
## AIC: 1977.9
## 
## Number of Fisher Scoring iterations: 1
## 
## 
##               Theta:  2.180 
##           Std. Err.:  0.216 
## 
##  2 x log-likelihood:  -1945.890
#without outlier
#model with contrinous elections variable
m3_intensity <- glm.nb(N_trilogues ~ 
                             proposal_t_eupolarizarion + proposal_t_wmean_eu_salience  +
                             Interinst_conflict + ep_amendments_tabled + council_dissent +
                             N_eurovoc_terms + factor(package_deal) + competence_length + factor(new) + factor(form) + elections_days + lr_proposal_probability +
                              factor(term),
                           data = trilogues_number_noRegi)

summary(m3_intensity)
## 
## Call:
## glm.nb(formula = N_trilogues ~ proposal_t_eupolarizarion + proposal_t_wmean_eu_salience + 
##     Interinst_conflict + ep_amendments_tabled + council_dissent + 
##     N_eurovoc_terms + factor(package_deal) + competence_length + 
##     factor(new) + factor(form) + elections_days + lr_proposal_probability + 
##     factor(term), data = trilogues_number_noRegi, init.theta = 6.312253359, 
##     link = log)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -3.2412  -0.7548  -0.2243   0.3951   3.8231  
## 
## Coefficients:
##                                Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                   1.637e-01  3.644e-01   0.449 0.653299    
## proposal_t_eupolarizarion     7.182e-02  1.597e-01   0.450 0.652915    
## proposal_t_wmean_eu_salience -1.469e-01  2.374e-01  -0.619 0.536070    
## Interinst_conflict           -1.470e-01  7.429e-02  -1.979 0.047797 *  
## ep_amendments_tabled          1.592e-03  3.920e-04   4.061 4.89e-05 ***
## council_dissent               7.381e-02  2.250e-02   3.280 0.001038 ** 
## N_eurovoc_terms               2.220e-02  1.997e-02   1.111 0.266479    
## factor(package_deal)1         6.824e-01  8.575e-02   7.958 1.74e-15 ***
## competence_length            -6.017e-03  2.888e-03  -2.083 0.037247 *  
## factor(new)1                  4.085e-02  7.688e-02   0.531 0.595210    
## factor(form)Directive         5.397e-01  1.507e-01   3.581 0.000343 ***
## factor(form)Regulation        4.124e-01  1.434e-01   2.875 0.004038 ** 
## elections_days                4.816e-05  9.178e-05   0.525 0.599788    
## lr_proposal_probability       8.845e-01  1.204e-01   7.344 2.08e-13 ***
## factor(term)8                 6.018e-02  7.634e-02   0.788 0.430471    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for Negative Binomial(6.3123) family taken to be 1)
## 
##     Null deviance: 659.21  on 422  degrees of freedom
## Residual deviance: 437.06  on 408  degrees of freedom
##   (103 observations deleted due to missingness)
## AIC: 1758.7
## 
## Number of Fisher Scoring iterations: 1
## 
## 
##               Theta:  6.31 
##           Std. Err.:  1.22 
## 
##  2 x log-likelihood:  -1726.707
#model with dummy elections variable
m4_intensity <- glm.nb(N_trilogues ~ 
                             proposal_t_eupolarizarion + proposal_t_wmean_eu_salience  +
                             Interinst_conflict + ep_amendments_tabled + council_dissent +
                             N_eurovoc_terms + factor(package_deal) + competence_length + factor(new) + factor(form) + factor(elections_dummy) + lr_proposal_probability +
                              factor(term),
                           data = trilogues_number_noRegi)

summary(m4_intensity)
## 
## Call:
## glm.nb(formula = N_trilogues ~ proposal_t_eupolarizarion + proposal_t_wmean_eu_salience + 
##     Interinst_conflict + ep_amendments_tabled + council_dissent + 
##     N_eurovoc_terms + factor(package_deal) + competence_length + 
##     factor(new) + factor(form) + factor(elections_dummy) + lr_proposal_probability + 
##     factor(term), data = trilogues_number_noRegi, init.theta = 6.417957895, 
##     link = log)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -3.2274  -0.7422  -0.2154   0.3802   3.7963  
## 
## Coefficients:
##                                Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                   0.2081344  0.3502335   0.594 0.552329    
## proposal_t_eupolarizarion     0.0652934  0.1575082   0.415 0.678479    
## proposal_t_wmean_eu_salience -0.1106138  0.2380491  -0.465 0.642169    
## Interinst_conflict           -0.1576615  0.0741189  -2.127 0.033408 *  
## ep_amendments_tabled          0.0015696  0.0003894   4.031 5.55e-05 ***
## council_dissent               0.0748465  0.0224607   3.332 0.000861 ***
## N_eurovoc_terms               0.0243153  0.0198834   1.223 0.221370    
## factor(package_deal)1         0.6695117  0.0857775   7.805 5.94e-15 ***
## competence_length            -0.0056985  0.0028700  -1.986 0.047089 *  
## factor(new)1                  0.0469095  0.0768044   0.611 0.541354    
## factor(form)Directive         0.5188231  0.1512799   3.430 0.000605 ***
## factor(form)Regulation        0.3940440  0.1438357   2.740 0.006152 ** 
## factor(elections_dummy)1     -0.1559720  0.1128788  -1.382 0.167044    
## lr_proposal_probability       0.8665095  0.1207665   7.175 7.23e-13 ***
## factor(term)8                 0.0396510  0.0776250   0.511 0.609490    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for Negative Binomial(6.418) family taken to be 1)
## 
##     Null deviance: 662.56  on 422  degrees of freedom
## Residual deviance: 437.57  on 408  degrees of freedom
##   (103 observations deleted due to missingness)
## AIC: 1757.1
## 
## Number of Fisher Scoring iterations: 1
## 
## 
##               Theta:  6.42 
##           Std. Err.:  1.26 
## 
##  2 x log-likelihood:  -1725.067

Thoughts:
1. no effect of polarization, significant positive effect of salience
2. effect of salience dissappears if using a restricted sample –> have it in appendix only?
3. effect of salience changes the direction in models with a restricted sample if we move from continious elections variable to a dummy
4. models with elections dummy have a slightly better performance
5. we lose ~ a hundred observations due to missings in public opinion data –> should we think of data imputations?

#visualizations (based on model 2)

#polarization (whole range)
i_predict_polarization <- ggpredict(m2_intensity, terms = "proposal_t_eupolarizarion[all]")

ggplot(i_predict_polarization, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Polarization (time proposal)", y = "Predicted number of trilogues") 

#salience 
i_predict_salience <- ggpredict(m2_intensity, terms = "proposal_t_wmean_eu_salience[all]")

ggplot(i_predict_salience, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Salience (time proposal)", y = "Predicted number of trilogues") 

#authority expansion
i_predict_eu <- ggpredict(m2_intensity, terms = "lr_proposal_probability[all]")

ggplot(i_predict_eu, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Pr. of EU authority expansion", y = "Predicted number of trilogues") 

#ep amendments
i_predict_ep <- ggpredict(m2_intensity, terms = "ep_amendments_tabled[all]")

ggplot(i_predict_ep, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "N of EP amendments", y = "Predicted number of trilogues") 

#council dissent
i_predict_council <- ggpredict(m2_intensity, terms = "council_dissent[all]")

ggplot(i_predict_council, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Council dissent", y = "Predicted number of trilogues") 

#interinst conflict
i_predict_insitutions <- ggpredict(m2_intensity, terms = "Interinst_conflict[all]")

ggplot(i_predict_insitutions, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Interinstitutional conflict", y = "Predicted number of trilogues") 

#Models DURATION OF TRILOGUES

Modelling:
1. no CAP FEs –> not enough observations
2. instead of year FE, EP term FE
3. ep_amenmdnets_tabled –> use it as a proxy for EP polarization (then we do not have issues with correlation between EP_polarization measure and inter-inst conflict)
4. Variables:
- main: EU polarization at the t of proposal and EU salience at the t of proposal (Average t between proposal and first trilogue is 13 months)
- institutional controls: Council dissent (sum of abstentions and against votes), EP polarization (n of tabled amendments), interinst conflict
- procedure controls: form, package_deal (1 if proposal is part of a package), complexity (N_eurovoc_terms), new vs amending (1 if new), days to next EP elections (from proposal) // election proximity dummy (1 if proposal submitted in the last year of EP term), competence_length, authority expansion; N_trilogues should not be used (correlation 0.65)
5. Method: Negative binomial model (below) and Cox survival model (TBD)
6. One set of models: only without outliers (we don’t have info on duration of negotiations for the outlier with 85 trilogues)

#model with continious elections variable
m1_duration <-  glm.nb(duration_negotiations_days ~ 
                             proposal_t_eupolarizarion + proposal_t_wmean_eu_salience  +
                             Interinst_conflict + ep_amendments_tabled + council_dissent +
                             N_eurovoc_terms + factor(package_deal) + competence_length + factor(new) + factor(form) + elections_days +  lr_proposal_probability +
                              factor(term),
                           data = trilogues_duration)

summary(m1_duration)
## 
## Call:
## glm.nb(formula = duration_negotiations_days ~ proposal_t_eupolarizarion + 
##     proposal_t_wmean_eu_salience + Interinst_conflict + ep_amendments_tabled + 
##     council_dissent + N_eurovoc_terms + factor(package_deal) + 
##     competence_length + factor(new) + factor(form) + elections_days + 
##     lr_proposal_probability + factor(term), data = trilogues_duration, 
##     init.theta = 0.6875067857, link = log)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.4789  -1.1205  -0.3413   0.3116   2.5418  
## 
## Coefficients:
##                                Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                   1.6214362  0.6250626   2.594 0.009486 ** 
## proposal_t_eupolarizarion     0.1151913  0.2845405   0.405 0.685601    
## proposal_t_wmean_eu_salience  0.0296648  0.4204935   0.071 0.943758    
## Interinst_conflict           -0.1928231  0.1295318  -1.489 0.136588    
## ep_amendments_tabled          0.0027440  0.0007711   3.558 0.000373 ***
## council_dissent               0.0583364  0.0411993   1.416 0.156788    
## N_eurovoc_terms               0.0861234  0.0347488   2.478 0.013195 *  
## factor(package_deal)1         0.7411478  0.1703862   4.350 1.36e-05 ***
## competence_length            -0.0064616  0.0051835  -1.247 0.212556    
## factor(new)1                  0.2019334  0.1410996   1.431 0.152390    
## factor(form)Directive         0.8688806  0.2617015   3.320 0.000900 ***
## factor(form)Regulation        0.8287800  0.2445761   3.389 0.000702 ***
## elections_days                0.0006551  0.0001652   3.966 7.29e-05 ***
## lr_proposal_probability       1.1307861  0.2201100   5.137 2.79e-07 ***
## factor(term)8                -0.1462926  0.1364094  -1.072 0.283517    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for Negative Binomial(0.6875) family taken to be 1)
## 
##     Null deviance: 572.81  on 390  degrees of freedom
## Residual deviance: 459.49  on 376  degrees of freedom
##   (165 observations deleted due to missingness)
## AIC: 4109.9
## 
## Number of Fisher Scoring iterations: 1
## 
## 
##               Theta:  0.6875 
##           Std. Err.:  0.0444 
## 
##  2 x log-likelihood:  -4077.9330
#model with dummy elections variable
m2_duration <- glm.nb(duration_negotiations_days ~ 
                             proposal_t_eupolarizarion + proposal_t_wmean_eu_salience  +
                             Interinst_conflict + ep_amendments_tabled + council_dissent +
                             N_eurovoc_terms + factor(package_deal) + competence_length + factor(new) + factor(form) + factor(elections_dummy) + lr_proposal_probability +
                              factor(term),
                           data = trilogues_duration)

summary(m2_duration)
## 
## Call:
## glm.nb(formula = duration_negotiations_days ~ proposal_t_eupolarizarion + 
##     proposal_t_wmean_eu_salience + Interinst_conflict + ep_amendments_tabled + 
##     council_dissent + N_eurovoc_terms + factor(package_deal) + 
##     competence_length + factor(new) + factor(form) + factor(elections_dummy) + 
##     lr_proposal_probability + factor(term), data = trilogues_duration, 
##     init.theta = 0.668353591, link = log)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.4248  -1.1396  -0.3846   0.2822   2.3099  
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                   2.356255   0.617769   3.814 0.000137 ***
## proposal_t_eupolarizarion     0.373769   0.284377   1.314 0.188730    
## proposal_t_wmean_eu_salience  0.094994   0.426147   0.223 0.823602    
## Interinst_conflict           -0.225020   0.132031  -1.704 0.088326 .  
## ep_amendments_tabled          0.002353   0.000780   3.017 0.002552 ** 
## council_dissent               0.052179   0.041876   1.246 0.212752    
## N_eurovoc_terms               0.057998   0.035154   1.650 0.098976 .  
## factor(package_deal)1         0.762435   0.173266   4.400 1.08e-05 ***
## competence_length            -0.009272   0.005241  -1.769 0.076861 .  
## factor(new)1                  0.172679   0.143031   1.207 0.227323    
## factor(form)Directive         0.916399   0.266377   3.440 0.000581 ***
## factor(form)Regulation        0.845952   0.248671   3.402 0.000669 ***
## factor(elections_dummy)1     -0.216851   0.191488  -1.132 0.257445    
## lr_proposal_probability       1.159324   0.223845   5.179 2.23e-07 ***
## factor(term)8                -0.072504   0.141342  -0.513 0.607970    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for Negative Binomial(0.6684) family taken to be 1)
## 
##     Null deviance: 557.60  on 390  degrees of freedom
## Residual deviance: 461.02  on 376  degrees of freedom
##   (165 observations deleted due to missingness)
## AIC: 4123.7
## 
## Number of Fisher Scoring iterations: 1
## 
## 
##               Theta:  0.6684 
##           Std. Err.:  0.0429 
## 
##  2 x log-likelihood:  -4091.7400

Thoughts:
1. Salience and polarization are not significant
2. we lose ~ a hundred observations due to missings in public opinion data –> should we think of data imputations?

#visualizations (based on model 2)
#polarization (whole range)
d_predict_polarization <- ggpredict(m2_duration, terms = "proposal_t_eupolarizarion[all]")

ggplot(d_predict_polarization, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Polarization (time proposal)", y = "Predicted number of days") 

#salience 
d_predict_salience <- ggpredict(m2_duration, terms = "proposal_t_wmean_eu_salience[all]")

ggplot(d_predict_salience, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Salience (time proposal)", y = "Predicted number of days") 

#authority expansion
d_predict_eu <- ggpredict(m2_duration, terms = "lr_proposal_probability[all]")

ggplot(d_predict_eu, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Pr. of EU authority expansion", y = "Predicted number of days") 

#ep amendments
d_predict_ep <- ggpredict(m2_duration, terms = "ep_amendments_tabled[all]")

ggplot(d_predict_ep, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "N of EP amendments", y = "Predicted number of days") 

#council dissent
d_predict_council <- ggpredict(m2_duration, terms = "council_dissent[all]")

ggplot(d_predict_council, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Council dissent", y = "Predicted number of days") 

#interinst conflict
d_predict_insitutions <- ggpredict(m2_duration, terms = "Interinst_conflict[all]")

ggplot(d_predict_insitutions, aes(x=x, y=predicted)) +
  geom_line(stat = "identity", linetype="solid") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high) , linetype=1,  alpha = .3, fill = "deepskyblue2") +
  theme_minimal() +
  labs(title = NULL, x = "Interinstitutional conflict", y = "Predicted number of days")