Data Preparation

Libraries

Import datasets used for processing or analyses;

# Set working directory
#setwd("C:/Users/Dani Grant/OneDrive/Desktop") # Dani
setwd("~/Documents/COVID Studies/NSF Rapid Study/Wave2_US") # Alex

# Import dataset
d <- read.csv("Covid-19_NSF_RAPID_US_Wave2_Cleaned.csv", header = T, stringsAsFactors = F) 

d <- d[d$election_timing != 'Pre-election',] # Exclude Pre-election

Codes and variable construction

##########################
# Partisan Identification
##########################

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

# party factor
d$party_factor <- NA
d$party_factor[d$partyCont == -1 | d$partyCont == -2 | d$partyCont == -3] <- 'Democrat'
d$party_factor[d$partyCont == 0] <- 'Independent'
d$party_factor[d$partyCont == 1 | d$partyCont == 2 | d$partyCont == 3] <- 'Republican'

## Order of party variable
d$party_factor <- factor(d$party_factor, levels = c('Democrat', 'Republican','Independent'))

### dummy and contrast codes for party

## Contrast codes

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

## Dummy codes 

### democrat
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

### republican
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

### independent
d$pIndD[d$party_factor == 'Democrat'] <- 1
d$pIndD[d$party_factor == 'Republican'] <- 0
d$pIndD[d$party_factor == 'Independent'] <- 0

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


########################
# Election timing codes
########################

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

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


##############################
# election legitimacy measure
##############################

d$voteLegit <- rowMeans(d[,127:128], na.rm = T)

Analyses

Main Model (w/o repeated factors): Election legitimacy = Party ID x Time

# Augmented Model
vote.party.time.a <- lm(voteLegit ~ pDem_Rep +
                        pInd_Not +
                        tDur_Post+
                        pDem_Rep:tDur_Post +
                        pInd_Not:tDur_Post, data = d)


# Compact Model
vote.party.time.c <- lm(voteLegit ~ pDem_Rep +
                        pInd_Not +
                        tDur_Post, data = d)


# model comparison
modelCompare(vote.party.time.c, vote.party.time.a) # Gives F-value and partial eta squared for the 2df test of party ID x Timing
## SSE (Compact) =  1558.324 
## SSE (Augmented) =  1530.822 
## Delta R-Squared =  0.01349716 
## Partial Eta-Squared (PRE) =  0.01764868 
## F(2,1202) = 10.79742, p = 2.250956e-05

Simple Effects of Timing, at each level of Party

# Democrats
vote.party.time.D <- lm(voteLegit ~  (pDemR + pDemI) * (tDur_Post), data = d)
mcSummary(vote.party.time.D)
## Loading required package: car
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
## lm(formula = voteLegit ~ (pDemR + pDemI) * (tDur_Post), data = d)
## 
## Omnibus ANOVA
##                  SS   df      MS EtaSq      F p
## Model       506.819    5 101.364 0.249 79.591 0
## Error      1530.822 1202   1.274               
## Corr Total 2037.641 1207   1.688               
## 
##   RMSE AdjEtaSq
##  1.129    0.246
## 
## Coefficients
##                    Est StErr       t   SSR(3) EtaSq   tol CI_2.5 CI_97.5    p
## (Intercept)      4.145 0.048  86.234 9470.640 0.861    NA  4.051   4.240 0.00
## pDemR           -1.256 0.071 -17.647  396.631 0.206 0.881 -1.395  -1.116 0.00
## pDemI           -1.188 0.096 -12.426  196.656 0.114 0.878 -1.375  -1.000 0.00
## tDur_Post        0.442 0.096   4.602   26.974 0.017 0.457  0.254   0.631 0.00
## pDemR:tDur_Post -0.651 0.142  -4.573   26.629 0.017 0.543 -0.930  -0.372 0.00
## pDemI:tDur_Post -0.446 0.191  -2.333    6.929 0.005 0.742 -0.821  -0.071 0.02
# Republicans
vote.party.time.R <- lm(voteLegit ~  (pRepD + pRepI) * (tDur_Post), data = d)
mcSummary(vote.party.time.R)
## lm(formula = voteLegit ~ (pRepD + pRepI) * (tDur_Post), data = d)
## 
## Omnibus ANOVA
##                  SS   df      MS EtaSq      F p
## Model       506.819    5 101.364 0.249 79.591 0
## Error      1530.822 1202   1.274               
## Corr Total 2037.641 1207   1.688               
## 
##   RMSE AdjEtaSq
##  1.129    0.246
## 
## Coefficients
##                    Est StErr      t   SSR(3) EtaSq   tol CI_2.5 CI_97.5     p
## (Intercept)      2.890 0.052 55.079 3863.595 0.716    NA  2.787   2.992 0.000
## pRepD            1.256 0.071 17.647  396.631 0.206 0.838  1.116   1.395 0.000
## pRepI            0.068 0.098  0.695    0.616 0.000 0.838 -0.124   0.260 0.487
## tDur_Post       -0.208 0.105 -1.985    5.018 0.003 0.384 -0.414  -0.002 0.047
## pRepD:tDur_Post  0.651 0.142  4.573   26.629 0.017 0.454  0.372   0.930 0.000
## pRepI:tDur_Post  0.205 0.196  1.047    1.395 0.001 0.708 -0.179   0.589 0.295
# Independents
vote.party.time.I <- lm(voteLegit ~  (pIndD + pIndR) * (tDur_Post), data = d)
mcSummary(vote.party.time.I)
## lm(formula = voteLegit ~ (pIndD + pIndR) * (tDur_Post), data = d)
## 
## Omnibus ANOVA
##                  SS   df      MS EtaSq      F p
## Model       506.819    5 101.364 0.249 79.591 0
## Error      1530.822 1202   1.274               
## Corr Total 2037.641 1207   1.688               
## 
##   RMSE AdjEtaSq
##  1.129    0.246
## 
## Coefficients
##                    Est StErr      t   SSR(3) EtaSq   tol CI_2.5 CI_97.5     p
## (Intercept)      2.958 0.083 35.804 1632.591 0.516    NA  2.796   3.120 0.000
## pIndD            1.188 0.096 12.426  196.656 0.114 0.464  1.000   1.375 0.000
## pIndR           -0.068 0.098 -0.695    0.616 0.000 0.466 -0.260   0.124 0.487
## tDur_Post       -0.003 0.165 -0.021    0.001 0.000 0.155 -0.328   0.321 0.983
## pIndD:tDur_Post  0.446 0.191  2.333    6.929 0.005 0.252  0.071   0.821 0.020
## pIndR:tDur_Post -0.205 0.196 -1.047    1.395 0.001 0.287 -0.589   0.179 0.295