# continuous party
d$partyCont <- NA
d$partyCont[d$demStrength == 1] <- -3
d$partyCont[d$demStrength == 2] <- -2
d$partyCont[d$partyClose == 1] <- -1
d$partyCont[d$partyClose == 3] <- 0
d$partyCont[d$repStrength == 1] <- 3
d$partyCont[d$repStrength == 2] <- 2
d$partyCont[d$partyClose == 2] <- 1


# policy group proposer
d$Policy_Group <- NA
d$Policy_Group[d$FL_71_DO == 'proportional_dem' | d$FL_71_DO == 'US1st_dem'] <- "Democratic"
d$Policy_Group[d$FL_71_DO == 'proportional_rep' | d$FL_71_DO == 'US1st_rep'] <- "Republican"
d$Policy_Group[d$FL_71_DO == 'proportional_bipart' | d$FL_71_DO == 'US1st_bipart'] <- "Bipartisan"
d$Policy_Group[d$FL_71_DO == 'proportional_expert' | d$FL_71_DO == 'US1st_expert'] <- "Expert"

d$Policy_Group <- factor(d$Policy_Group, levels = c('Democratic', 'Republican', 'Bipartisan','Expert'))

# policy frame
d$Policy_Frame <- NA
d$Policy_Frame[d$FL_71_DO == 'proportional_dem' | d$FL_71_DO == 'proportional_rep' | d$FL_71_DO == 'proportional_bipart' | d$FL_71_DO == 'proportional_expert'] <- "Proportional"
d$Policy_Frame[d$FL_71_DO == 'US1st_dem' | d$FL_71_DO == 'US1st_rep' | d$FL_71_DO == 'US1st_bipart' | d$FL_71_DO == 'US1st_expert'] <- "US1st"

# party factor
d$party_factor <- NA
d$party_factor[d$partyCont < 0] <- 'Democrat'
d$party_factor[d$partyCont == 0] <- 'Independent'
d$party_factor[d$partyCont > 0] <- 'Republican'


## Order of timing var
d$election_timing <- factor(d$election_timing, levels = c('Pre-election', 'During-election','Post-election'))


d$party_factor <- factor(d$party_factor, levels = c('Democrat', 'Republican','Independent'))
### Partisan framing codes
# Code 1: Left vs. Right

d$fDem_Rep <- NA
d$fDem_Rep[d$Policy_Group == 'Democratic'] <- -.5
d$fDem_Rep[d$Policy_Group == 'Republican'] <- .5
d$fDem_Rep[d$Policy_Group == 'Bipartisan' | d$Policy_Group == 'Expert'] <- 0

# Code 2: Bi vs. Exp

d$fBi_Exp <- NA
d$fBi_Exp[d$Policy_Group == 'Democratic' | d$Policy_Group == 'Republican'] <- 0
d$fBi_Exp[d$Policy_Group == 'Bipartisan'] <- -.5
d$fBi_Exp[d$Policy_Group == 'Expert'] <- .5

# Code 3 = Dem and Rep vs. Exp and Bi

d$fParties_BiExp <- NA
d$fParties_BiExp[d$Policy_Group == 'Democratic' | d$Policy_Group == 'Republican'] <- -.5
d$fParties_BiExp[d$Policy_Group == 'Bipartisan' | d$Policy_Group == 'Expert'] <- .5


### Policy framing codes
# contrasts
d$fProp_US <- NA
d$fProp_US[d$Policy_Frame == 'Proportional'] <- -.5
d$fProp_US[d$Policy_Frame == 'US1st'] <- .5

#dummies
d$fProportional <- NA
d$fProportional[d$Policy_Frame == 'Proportional'] <- 0
d$fProportional[d$Policy_Frame == 'US1st'] <- 1

d$fUS <- NA
d$fUS[d$Policy_Frame == 'Proportional'] <- 1
d$fUS[d$Policy_Frame == 'US1st'] <- 0


### Timing codes
## Contrast
d$tPre_Post <- NA
d$tPre_Post[d$election_timing == 'Pre-election'] <- -.5
d$tPre_Post[d$election_timing == 'During-election'] <- 0
d$tPre_Post[d$election_timing == 'Post-election'] <- .5

d$tDuring_Not <- NA
d$tDuring_Not[d$election_timing == 'Pre-election'] <- .33
d$tDuring_Not[d$election_timing == 'During-election'] <- -.67
d$tDuring_Not[d$election_timing == 'Post-election'] <- .33

# Dummy
# Post!
d$tPostP <- NA
d$tPostP[d$election_timing == 'Pre-election'] <- 1
d$tPostP[d$election_timing == 'During-election'] <- 0
d$tPostP[d$election_timing == 'Post-election'] <- 0

d$tPostD <- NA
d$tPostD[d$election_timing == 'Pre-election'] <- 0
d$tPostD[d$election_timing == 'During-election'] <- 1
d$tPostD[d$election_timing == 'Post-election'] <- 0

# During!
d$tDurPre <- NA
d$tDurPre[d$election_timing == 'Pre-election'] <- 1
d$tDurPre[d$election_timing == 'During-election'] <- 0
d$tDurPre[d$election_timing == 'Post-election'] <- 0

d$tDurPost <- NA
d$tDurPost[d$election_timing == 'Pre-election'] <- 0
d$tDurPost[d$election_timing == 'During-election'] <- 0
d$tDurPost[d$election_timing == 'Post-election'] <- 1


### Party Factor
d$pDem_Rep <- NA
d$pDem_Rep[d$party_factor == 'Democrat'] <- -.5
d$pDem_Rep[d$party_factor == 'Independent'] <- 0
d$pDem_Rep[d$party_factor == 'Republican'] <- .5

d$pInd_Not <- NA
d$pInd_Not[d$party_factor == 'Democrat'] <- .33
d$pInd_Not[d$party_factor == 'Independent'] <- -.67
d$pInd_Not[d$party_factor == 'Republican'] <- .33

### centering

d$vaxxAtt.c <- d$vaxxAttitudes - mean(d$vaxxAttitudes, na.rm = T)

d$ownvote.c <- d$ownvote_conf - mean(d$ownvote_conf, na.rm = T)

d$overallvote.c <- d$overallvote_conf - mean(d$overallvote_conf, na.rm = T)

d$govtPolEff.c <- d$polEfficacy_1 - mean(d$polEfficacy_1, na.rm = T)

d$electPolEff.c <- d$polEfficacy_2 - mean(d$polEfficacy_2, na.rm = T)


# Media Measures - All, including Fox
d$mediaExposure_all <- rowMeans(d[,c("mediaExposure_1","mediaExposure_2","mediaExposure_3","mediaExposure_4","mediaExposure_5","mediaExposure_6","mediaExposure_7","mediaExposure_8","mediaExposure_9","mediaExposure_10","mediaExposure_11","mediaExposure_12","mediaExposure_13","mediaExposure_14","mediaExposure_15")], na.rm = T)

d$mediaTrust_all <- rowMeans(d[,c("mediaTrust_1","mediaTrust_2","mediaTrust_3","mediaTrust_4","mediaTrust_5","mediaTrust_6","mediaTrust_7","mediaTrust_8","mediaTrust_9","mediaTrust_10","mediaTrust_11","mediaTrust_12","mediaTrust_13","mediaTrust_14","mediaTrust_15")], na.rm = T)


# Media Measures - Excluding Fox
d$mediaExposure <- rowMeans(d[,c("mediaExposure_1","mediaExposure_2","mediaExposure_3","mediaExposure_4","mediaExposure_6","mediaExposure_7","mediaExposure_8","mediaExposure_9","mediaExposure_10","mediaExposure_11","mediaExposure_12","mediaExposure_13","mediaExposure_14","mediaExposure_15")], na.rm = T)

d$mediaTrust <- rowMeans(d[,c("mediaTrust_1","mediaTrust_2","mediaTrust_3","mediaTrust_4","mediaTrust_6","mediaTrust_7","mediaTrust_8","mediaTrust_9","mediaTrust_10","mediaTrust_11","mediaTrust_12","mediaTrust_13","mediaTrust_14","mediaTrust_15")], na.rm = T)


### Composite Media variables
#average own and overall vote
d$voteLegit <- (d$ownvote_conf + d$overallvote_conf)/2

d$voteLegit.c <- d$voteLegit - mean(d$voteLegit, na.rm = T)

#recenter media/fox trust to match media/fox exposure scale
d$mediaTrust5 <- d$mediaTrust_5 + 3
d$mediaTrust <- d$mediaTrust + 3

d$foxPerception <- (d$mediaExposure_5 + d$mediaTrust5)/2

d$mediaPerception <- (d$mediaExposure + d$mediaTrust)/2


d$foxPerception.c <- d$foxPerception - mean(d$foxPerception, na.rm = T)

d$mediaPerception.c <- d$mediaPerception - mean(d$mediaPerception, na.rm = T)


#### Indices

Proportional <- d$Policy_Frame == 'Proportional'
US1st <- d$Policy_Frame == 'US1st'

Pre <- d$election_timing == 'Pre-election'
During <- d$election_timing == 'During-election'
Post <- d$election_timing == 'Post-election'


#dummy codes for party  ID

d$pDemR[d$party_factor == 'Democrat'] <- 0
d$pDemR[d$party_factor == 'Republican'] <- 1
d$pDemR[d$party_factor == 'Independent'] <- 0

d$pDemI[d$party_factor == 'Democrat'] <- 0
d$pDemI[d$party_factor == 'Republican'] <- 0
d$pDemI[d$party_factor == 'Independent'] <- 1


d$pRepD[d$party_factor == 'Democrat'] <- 1
d$pRepD[d$party_factor == 'Republican'] <- 0
d$pRepD[d$party_factor == 'Independent'] <- 0

d$pRepI[d$party_factor == 'Democrat'] <- 0
d$pRepI[d$party_factor == 'Republican'] <- 0
d$pRepI[d$party_factor == 'Independent'] <- 1

# mean center fox exposure
d$foxExposure.c <- d$mediaExposure_5 - mean(d$mediaExposure_5, na.rm = T)

# mean center other media exposure
d$otherMediaExposure.c <- d$mediaExposure - mean(d$mediaExposure, na.rm = T)

#create difference score
d$diffFoxOther <- d$mediaExposure_5 - d$mediaExposure



#reverse code biden to trump rating win --> trump definitely win = 1; biden definitely win = 9

d$electPredict_T_B2 <- 10 - d$electPredict_B_T
d$electPredict_T_B3 <- 10 - d$electPredict_B_T.1

#combine to make 1 column
d$electPredictTB <- ifelse(!is.na(d$electPredict_T_B), d$electPredict_T_B, 
                           ifelse(!is.na(d$electPredict_T_B2), d$electPredict_T_B2, 
                                  ifelse(!is.na(d$electPredict_T_B3), d$electPredict_T_B3, NA)))

d$electPredictTB.plot <- d$electPredictTB - 5 

1. Models: Does media perception predict vote confidence?

a. Vote confidence by Fox News perception

vote.fox <- lm(voteLegit ~ foxPerception, data = d)
tab_model(vote.fox)
  voteLegit
Predictors Estimates CI p
(Intercept) 3.98 3.82 – 4.13 <0.001
foxPerception -0.20 -0.26 – -0.15 <0.001
Observations 1209
R2 / R2 adjusted 0.038 / 0.037

b. Vote confidence by Other Media perception

vote.othMedia <- lm(voteLegit ~ mediaPerception, data = d)
tab_model(vote.othMedia)
  voteLegit
Predictors Estimates CI p
(Intercept) 1.76 1.57 – 1.96 <0.001
mediaPerception 0.70 0.63 – 0.78 <0.001
Observations 1209
R2 / R2 adjusted 0.216 / 0.216

c. Vote confidence by Fox & Other Media perception

vote.media <- lm(voteLegit ~ foxPerception + mediaPerception, data = d)
tab_model(vote.media)
  voteLegit
Predictors Estimates CI p
(Intercept) 2.25 2.02 – 2.48 <0.001
foxPerception -0.21 -0.26 – -0.15 <0.001
mediaPerception 0.70 0.63 – 0.78 <0.001
Observations 1209
R2 / R2 adjusted 0.255 / 0.254

2. Does partisanship predict vote confidence?

a. Vote confidence by partisanship

vote.party <- lm(voteLegit ~ (pDem_Rep + pInd_Not), data = d)
tab_model(vote.party)
  voteLegit
Predictors Estimates CI p
(Intercept) 3.34 3.27 – 3.42 <0.001
pDem_Rep -1.27 -1.41 – -1.13 <0.001
pInd_Not 0.56 0.38 – 0.74 <0.001
Observations 1208
R2 / R2 adjusted 0.232 / 0.231
summary(vote.party)
## 
## Call:
## lm(formula = voteLegit ~ (pDem_Rep + pInd_Not), data = d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.1667 -0.8920  0.1080  0.8333  2.1080 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.34407    0.03644   91.78  < 2e-16 ***
## pDem_Rep    -1.27466    0.07151  -17.82  < 2e-16 ***
## pInd_Not     0.56142    0.09055    6.20 7.73e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.138 on 1205 degrees of freedom
##   (1268 observations deleted due to missingness)
## Multiple R-squared:  0.2324, Adjusted R-squared:  0.2311 
## F-statistic: 182.4 on 2 and 1205 DF,  p-value: < 2.2e-16

3. Models: Do media perception and partisanship predict vote confidence?

a. Vote confidence by Fox News perception & partisan ID

vote.fox.party <- lm(voteLegit ~ foxPerception + (pDem_Rep + pInd_Not), data = d)
tab_model(vote.fox.party)
  voteLegit
Predictors Estimates CI p
(Intercept) 3.47 3.32 – 3.62 <0.001
foxPerception -0.05 -0.11 – 0.00 0.057
pDem_Rep -1.22 -1.37 – -1.07 <0.001
pInd_Not 0.58 0.40 – 0.76 <0.001
Observations 1208
R2 / R2 adjusted 0.235 / 0.233

b. Vote confidence by Other Media perception

vote.othMedia.party <- lm(voteLegit ~ mediaPerception + (pDem_Rep + pInd_Not), data = d)
tab_model(vote.othMedia.party)
  voteLegit
Predictors Estimates CI p
(Intercept) 2.20 1.99 – 2.41 <0.001
mediaPerception 0.47 0.39 – 0.56 <0.001
pDem_Rep -0.85 -1.00 – -0.70 <0.001
pInd_Not 0.53 0.36 – 0.70 <0.001
Observations 1208
R2 / R2 adjusted 0.308 / 0.306

c. Vote confidence by Fox & Other Media perception

vote.media.party <- lm(voteLegit ~ foxPerception + mediaPerception + (pDem_Rep + pInd_Not), data = d)
tab_model(vote.media.party)
  voteLegit
Predictors Estimates CI p
(Intercept) 2.40 2.17 – 2.62 <0.001
foxPerception -0.13 -0.18 – -0.07 <0.001
mediaPerception 0.51 0.43 – 0.60 <0.001
pDem_Rep -0.69 -0.85 – -0.52 <0.001
pInd_Not 0.56 0.39 – 0.73 <0.001
Observations 1208
R2 / R2 adjusted 0.320 / 0.318
summary(vote.media.party)
## 
## Call:
## lm(formula = voteLegit ~ foxPerception + mediaPerception + (pDem_Rep + 
##     pInd_Not), data = d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3634 -0.7997  0.1389  0.7738  2.8733 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      2.39699    0.11331  21.155  < 2e-16 ***
## foxPerception   -0.12519    0.02737  -4.575 5.27e-06 ***
## mediaPerception  0.51459    0.04188  12.286  < 2e-16 ***
## pDem_Rep        -0.68835    0.08434  -8.161 8.29e-16 ***
## pInd_Not         0.56140    0.08566   6.554 8.28e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.072 on 1203 degrees of freedom
##   (1268 observations deleted due to missingness)
## Multiple R-squared:   0.32,  Adjusted R-squared:  0.3177 
## F-statistic: 141.5 on 4 and 1203 DF,  p-value: < 2.2e-16

4. Models: Do media perception and partisanship interact to predict vote confidence?

a. Vote confidence by Fox News perception & partisan ID

vote.fox.party.int <- lm(voteLegit ~ foxPerception * (pDem_Rep + pInd_Not), data = d)
tab_model(vote.fox.party.int)
  voteLegit
Predictors Estimates CI p
(Intercept) 3.50 3.33 – 3.67 <0.001
foxPerception -0.08 -0.15 – -0.01 0.025
pDem_Rep -1.57 -1.89 – -1.25 <0.001
pInd_Not 0.34 -0.09 – 0.78 0.119
foxPerception * pDem_Rep 0.14 0.02 – 0.26 0.021
foxPerception * pInd_Not 0.09 -0.09 – 0.27 0.318
Observations 1208
R2 / R2 adjusted 0.239 / 0.236

b. Vote confidence by Other Media perception

vote.othMedia.party.int <- lm(voteLegit ~ mediaPerception * (pDem_Rep + pInd_Not), data = d)
tab_model(vote.othMedia.party.int)
  voteLegit
Predictors Estimates CI p
(Intercept) 2.17 1.94 – 2.39 <0.001
mediaPerception 0.49 0.40 – 0.58 <0.001
pDem_Rep -1.00 -1.48 – -0.53 <0.001
pInd_Not 0.84 0.29 – 1.39 0.003
mediaPerception *
pDem_Rep
0.05 -0.12 – 0.23 0.549
mediaPerception *
pInd_Not
-0.13 -0.34 – 0.09 0.253
Observations 1208
R2 / R2 adjusted 0.309 / 0.306

c. Vote confidence by Fox & Other Media perception

vote.media.party.int <- lm(voteLegit ~ foxPerception * mediaPerception * (pDem_Rep + pInd_Not), data = d)
tab_model(vote.media.party.int)
  voteLegit
Predictors Estimates CI p
(Intercept) 2.16 1.68 – 2.64 <0.001
foxPerception -0.15 -0.34 – 0.04 0.128
mediaPerception 0.72 0.52 – 0.92 <0.001
pDem_Rep -1.69 -2.70 – -0.68 0.001
pInd_Not 0.19 -0.95 – 1.34 0.740
foxPerception *
mediaPerception
-0.04 -0.10 – 0.03 0.276
foxPerception * pDem_Rep 0.27 -0.11 – 0.65 0.166
foxPerception * pInd_Not 0.50 0.03 – 0.97 0.035
mediaPerception *
pDem_Rep
0.38 -0.04 – 0.79 0.078
mediaPerception *
pInd_Not
-0.14 -0.61 – 0.33 0.551
(foxPerception
mediaPerception)

pDem_Rep
-0.09 -0.23 – 0.04 0.178
(foxPerception
mediaPerception)

pInd_Not
-0.07 -0.23 – 0.09 0.396
Observations 1208
R2 / R2 adjusted 0.335 / 0.329

5. Model Testing: Does the model predicting vote confidence by partisanship and media consumption explain more variance than the model without media consumption in it?

a. ANOVA testing model 2a against model 3c

anova(vote.party, vote.media.party)

6. Figure 1: Vote Confidence by partisanship

a. Combining own and nationwide vote conf. into long df

(voteconf <- as.data.frame(cbind(d[d$election_timing != "Pre-election",]$party_factor, d[d$election_timing != "Pre-election",]$ownvote_conf, d[d$election_timing != "Pre-election",]$overallvote_conf)))
voteconf <- as.data.frame(cbind(voteconf, d[d$election_timing != "Pre-election",]$election_timing))
names(voteconf) <- c("party_factor", "Own","Nationwide", "election_timing")
voteconf$party_factor <- recode_factor(voteconf$party_factor, `1` = "Democrat", `2` = "Republican", `3` = "Independent")

voteconffull.df <- tidyr::gather(voteconf, Vote_Type, Confidence, Own:Nationwide, factor_key=TRUE) 

voteconf.df <- voteconffull.df[voteconffull.df$election_timing != "Pre-election",]

b. Violin & box plot of the two vote confidence measures

voteConf.party_plot <- ggplot(voteconf.df[!is.na(voteconf.df$party_factor),], 
  aes(x = election_timing, y = Confidence)) +
  geom_violin(alpha = .6, aes(fill = party_factor)) +
#  geom_boxplot(position = position_dodge(.9), width = .1, outlier.colour = NA) +
  geom_point(stat = 'summary', fun = 'mean', size = 1) +
  geom_path(stat = 'summary', fun = 'mean', aes(group = 1, col = party_factor)) +
  stat_summary(fun.data = mean_cl_normal, geom = "errorbar", position = position_dodge(.9), width=.1, fun.args = list(mult = 1)) +
  facet_grid(Vote_Type ~ party_factor)

voteConf.party_plot + 
  scale_fill_manual(values = c('dodgerblue','red3','orchid4')) +
  scale_color_manual(values = c('dodgerblue','red3','orchid4')) +
  xlab("Participant Partisan ID") +
  ylab("Vote Legitimacy") +
  theme_classic()
## Warning: Removed 39 rows containing non-finite values (stat_ydensity).
## Warning: Removed 39 rows containing non-finite values (stat_summary).

## Warning: Removed 39 rows containing non-finite values (stat_summary).

## Warning: Removed 39 rows containing non-finite values (stat_summary).

7. Stats for Figure 1

a. Correlation between two vote conf. measures

cor.test(d$ownvote_conf, d$overallvote_conf)
## 
##  Pearson's product-moment correlation
## 
## data:  d$ownvote_conf and d$overallvote_conf
## t = 39.423, df = 1207, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.7245086 0.7738872
## sample estimates:
##       cor 
## 0.7502422

b. Descriptives for Vote Confidence by party ID

aggregate(d$voteLegit, list(d$party_factor, d$election_timing), FUN = mean, na.rm = T)

c. Interactive model of partisanship and election timing

# Timing contrast JUST for vote confidence as DV (only during & post available)
d$tDuring_Post <- NA
d$tDuring_Post[d$election_timing == 'During-election'] <- -.5
d$tDuring_Post[d$election_timing == 'Post-election'] <- .5

# Overall Model
vote.party.time <- lm(voteLegit ~ (pDem_Rep + pInd_Not) * tDuring_Post, data = d)
summary(vote.party.time)
## 
## Call:
## lm(formula = voteLegit ~ (pDem_Rep + pInd_Not) * tDuring_Post, 
##     data = d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3636 -0.8636  0.0760  0.6364  2.2146 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            3.33537    0.03622  92.097  < 2e-16 ***
## pDem_Rep              -1.25428    0.07106 -17.652  < 2e-16 ***
## pInd_Not               0.54940    0.09002   6.103 1.40e-09 ***
## tDuring_Post           0.08277    0.07243   1.143    0.253    
## pDem_Rep:tDuring_Post -0.64791    0.14212  -4.559 5.66e-06 ***
## pInd_Not:tDuring_Post  0.09974    0.18003   0.554    0.580    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.127 on 1202 degrees of freedom
##   (1268 observations deleted due to missingness)
## Multiple R-squared:  0.248,  Adjusted R-squared:  0.2448 
## F-statistic: 79.27 on 5 and 1202 DF,  p-value: < 2.2e-16
# At level of Dems
vote.party.time.Dems <- lm(voteLegit ~ (pDemR + pDemI) * tDuring_Post, data = d)
summary(vote.party.time.Dems)
## 
## Call:
## lm(formula = voteLegit ~ (pDemR + pDemI) * tDuring_Post, data = d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3636 -0.8636  0.0760  0.6364  2.2146 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         4.14382    0.04799  86.356  < 2e-16 ***
## pDemR              -1.25428    0.07106 -17.652  < 2e-16 ***
## pDemI              -1.17654    0.09562 -12.304  < 2e-16 ***
## tDuring_Post        0.43964    0.09597   4.581 5.11e-06 ***
## pDemR:tDuring_Post -0.64791    0.14212  -4.559 5.66e-06 ***
## pDemI:tDuring_Post -0.42369    0.19124  -2.215   0.0269 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.127 on 1202 degrees of freedom
##   (1268 observations deleted due to missingness)
## Multiple R-squared:  0.248,  Adjusted R-squared:  0.2448 
## F-statistic: 79.27 on 5 and 1202 DF,  p-value: < 2.2e-16
# At level of Reps
vote.party.time.Reps <- lm(voteLegit ~ (pRepD + pRepI) * tDuring_Post, data = d)
summary(vote.party.time.Reps)
## 
## Call:
## lm(formula = voteLegit ~ (pRepD + pRepI) * tDuring_Post, data = d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3636 -0.8636  0.0760  0.6364  2.2146 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         2.88953    0.05241  55.135  < 2e-16 ***
## pRepD               1.25428    0.07106  17.652  < 2e-16 ***
## pRepI               0.07774    0.09791   0.794   0.4274    
## tDuring_Post       -0.20827    0.10482  -1.987   0.0471 *  
## pRepD:tDuring_Post  0.64791    0.14212   4.559 5.66e-06 ***
## pRepI:tDuring_Post  0.22422    0.19583   1.145   0.2525    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.127 on 1202 degrees of freedom
##   (1268 observations deleted due to missingness)
## Multiple R-squared:  0.248,  Adjusted R-squared:  0.2448 
## F-statistic: 79.27 on 5 and 1202 DF,  p-value: < 2.2e-16

8. Figure 2: Media Perception box plot

a. creating df. with only media measures, party ID, and election timing

(media <- as.data.frame(cbind(d[,c(146,141,84:98,100:114)])))
media[,18:32] <- media[,18:32] + 3

media$media_1 <- rowMeans(media[,c(3,18)], na.rm = T)
media$media_2 <- rowMeans(media[,c(4,19)], na.rm = T)
media$media_3 <- rowMeans(media[,c(5,20)], na.rm = T)
media$media_4 <- rowMeans(media[,c(6,21)], na.rm = T)
media$media_5 <- rowMeans(media[,c(7,22)], na.rm = T)
media$media_6 <- rowMeans(media[,c(8,23)], na.rm = T)
media$media_7 <- rowMeans(media[,c(9,24)], na.rm = T)
media$media_8 <- rowMeans(media[,c(10,25)], na.rm = T)
media$media_9 <- rowMeans(media[,c(11,26)], na.rm = T)
media$media_10 <- rowMeans(media[,c(12,27)], na.rm = T)
media$media_11 <- rowMeans(media[,c(13,28)], na.rm = T)
media$media_12 <- rowMeans(media[,c(14,29)], na.rm = T)
media$media_13 <- rowMeans(media[,c(15,30)], na.rm = T)
media$media_14 <- rowMeans(media[,c(16,31)], na.rm = T)
media$media_15 <- rowMeans(media[,c(17,32)], na.rm = T)

media.df <- tidyr::gather(media, Source, Perception, media_1:media_15, factor_key=TRUE) 

media.df$Source <- recode_factor(media.df$Source, "media_1" = "NYTimes", "media_2" = "WSJ", "media_3" = "WashPost", "media_4" = "USAToday", "media_5" = "Fox News", "media_6" = "CNN", "media_7" = "MSNBC", "media_8" = "Yahoo", "media_9" = "HuffPost", "media_10" = "AOL", "media_11" = "NPR", "media_12" = "ABC", "media_13" = "NBC", "media_14" = "CBS", "media_15" = "PBS")

media.df$Source <- factor(media.df$Source, levels = c("Fox News", "ABC", "AOL", "CBS", "CNN", "HuffPost", "MSNBC", "NBC", "NPR", "NYTimes",  "PBS", "USAToday", "WashPost", "WSJ", "Yahoo"))

b. Boxplot of media measures

media_plot <- ggplot(media.df[!is.na(media.df$party_factor),],
  aes(x = Source, y = Perception, fill = party_factor)) +
  geom_bar(stat = 'summary', fun = 'mean', position = position_dodge(.9), alpha = .9) +
  stat_summary(fun.data = mean_cl_normal, geom = "errorbar", position = position_dodge(.9), width=.1, fun.args = list(mult = 1)) 

media_plot +
  scale_fill_manual("Participant Partisan ID", values = c("dodgerblue", "red3", "orchid4")) +
  xlab("Media Source") +
  ylab("Perception of Media Source") +
  coord_cartesian(ylim = c(1,4)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 
## Warning: Removed 330 rows containing non-finite values (stat_summary).

## Warning: Removed 330 rows containing non-finite values (stat_summary).

9. Stats for Figure 2

a. Correlation between media measures

cor.test(d$mediaExposure, d$mediaTrust)
## 
##  Pearson's product-moment correlation
## 
## data:  d$mediaExposure and d$mediaTrust
## t = 35.364, df = 2413, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5573583 0.6099292
## sample estimates:
##       cor 
## 0.5842563