library(readr)
library(psych)
library(lme4)
## Loading required package: Matrix
library(lmerTest)
##
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
##
## lmer
## The following object is masked from 'package:stats':
##
## step
library(ggcorrplot)
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
d <- read.csv (file.choose())
# 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
# 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'))
### 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
#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
d$IndR[d$party_factor == 'Democrat'] <- 0
d$IndR[d$party_factor == 'Republican'] <- 1
d$IndR[d$party_factor == 'Independent'] <- 0
d$IndD[d$party_factor == 'Democrat'] <- 1
d$IndD[d$party_factor == 'Republican'] <- 0
d$IndD[d$party_factor == 'Independent'] <- 0
## negative emotions
d$negEmo <- (d$emotion_1 + d$emotion_3 + d$emotion_8 + d$emotion_9 + d$emotion_10+ d$emotion_12)/5
d$negEmo.c <- d$negEmo - mean(d$negEmo, na.rm = T)
d2 <- d[d$election_timing != "Pre-election",]
### Timing codes
## Contrast
d2$tDur_Post <- NA
d2$tDur_Post[d2$election_timing == 'During-election'] <- -.5
d2$tDur_Post[d2$election_timing == 'Post-election'] <- .5
# Dummy
# Post!
d2$tDurD <- NA
d2$tDurD[d2$election_timing == 'During-election'] <- 0
d2$tDurD[d2$election_timing == 'Post-election'] <- 1
# During!
d2$tPostD <- NA
d2$tPostD[d2$election_timing == 'During-election'] <- 1
d2$tPostD[d2$election_timing == 'Post-election'] <- 0
corr <- data.frame(d$emotion_1)
colnames(corr)[colnames(corr)=="d.emotion_1"] <- "anger"
corr$shame <- d$emotion_3
corr$embarassment <- d$emotion_8
corr$nervousness <- d$emotion_9
corr$distress <- d$emotion_10
corr$irritability <- d$emotion_12
corr2 <- cor(corr, use = "complete.obs")
ggcorrplot(corr2, type = "lower",
lab = TRUE, title = "correlations")
## negative emotions
main model
negEmotion.m <- lm(negEmo.c ~ (pDem_Rep + pInd_Not) * (tDur_Post), data = d2)
summary(negEmotion.m)
##
## Call:
## lm(formula = negEmo.c ~ (pDem_Rep + pInd_Not) * (tDur_Post),
## data = d2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1378 -1.6304 -0.2304 1.4084 5.2194
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.16489 0.06256 -2.636 0.0085 **
## pDem_Rep 0.10104 0.12318 0.820 0.4122
## pInd_Not 0.67655 0.15523 4.358 1.42e-05 ***
## tDur_Post -0.22545 0.12512 -1.802 0.0718 .
## pDem_Rep:tDur_Post 1.29459 0.24636 5.255 1.75e-07 ***
## pInd_Not:tDur_Post -0.10508 0.31046 -0.338 0.7351
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.957 on 1208 degrees of freedom
## (28 observations deleted due to missingness)
## Multiple R-squared: 0.04253, Adjusted R-squared: 0.03857
## F-statistic: 10.73 on 5 and 1208 DF, p-value: 4.123e-10
dummy coded for dem
negEmotion.D <- lm(negEmo.c ~ (pDemR + pDemI) * (tDur_Post), data = d2)
summary(negEmotion.D)
##
## Call:
## lm(formula = negEmo.c ~ (pDemR + pDemI) * (tDur_Post), data = d2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1378 -1.6304 -0.2304 1.4084 5.2194
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.007849 0.083149 0.094 0.924805
## pDemR 0.101044 0.123182 0.820 0.412218
## pDemI -0.626027 0.164974 -3.795 0.000155 ***
## tDur_Post -0.907428 0.166298 -5.457 5.88e-08 ***
## pDemR:tDur_Post 1.294592 0.246365 5.255 1.75e-07 ***
## pDemI:tDur_Post 0.752378 0.329948 2.280 0.022764 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.957 on 1208 degrees of freedom
## (28 observations deleted due to missingness)
## Multiple R-squared: 0.04253, Adjusted R-squared: 0.03857
## F-statistic: 10.73 on 5 and 1208 DF, p-value: 4.123e-10
dummy coded for rep
negEmotion.R <- lm(negEmo.c ~ (pRepD + pRepI) * (tDur_Post), data = d2)
summary(negEmotion.R)
##
## Call:
## lm(formula = negEmo.c ~ (pRepD + pRepI) * (tDur_Post), data = d2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1378 -1.6304 -0.2304 1.4084 5.2194
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.10889 0.09089 1.198 0.2311
## pRepD -0.10104 0.12318 -0.820 0.4122
## pRepI -0.72707 0.16901 -4.302 1.83e-05 ***
## tDur_Post 0.38716 0.18177 2.130 0.0334 *
## pRepD:tDur_Post -1.29459 0.24636 -5.255 1.75e-07 ***
## pRepI:tDur_Post -0.54221 0.33801 -1.604 0.1089
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.957 on 1208 degrees of freedom
## (28 observations deleted due to missingness)
## Multiple R-squared: 0.04253, Adjusted R-squared: 0.03857
## F-statistic: 10.73 on 5 and 1208 DF, p-value: 4.123e-10
dummy coded for independent
negEmotion.I <- lm(negEmo.c ~ (IndR + IndD) * (tDur_Post), data = d2)
summary(negEmotion.I)
##
## Call:
## lm(formula = negEmo.c ~ (IndR + IndD) * (tDur_Post), data = d2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1378 -1.6304 -0.2304 1.4084 5.2194
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.6182 0.1425 -4.338 1.55e-05 ***
## IndR 0.7271 0.1690 4.302 1.83e-05 ***
## IndD 0.6260 0.1650 3.795 0.000155 ***
## tDur_Post -0.1550 0.2850 -0.544 0.586486
## IndR:tDur_Post 0.5422 0.3380 1.604 0.108946
## IndD:tDur_Post -0.7524 0.3299 -2.280 0.022764 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.957 on 1208 degrees of freedom
## (28 observations deleted due to missingness)
## Multiple R-squared: 0.04253, Adjusted R-squared: 0.03857
## F-statistic: 10.73 on 5 and 1208 DF, p-value: 4.123e-10
means
print("means democrat")
## [1] "means democrat"
dDem <- d2[d2$party_factor == "Democrat",]
mean(dDem$negEmo[dDem$election_timing == "During-election"], na.rm = T)
## [1] 4.337849
mean(dDem$negEmo[dDem$election_timing == "Post-election"], na.rm = T)
## [1] 3.430421
print("means republican")
## [1] "means republican"
dRep <- d2[d2$party_factor == "Republican",]
mean(dRep$negEmo[dRep$election_timing == "During-election"], na.rm = T)
## [1] 3.791597
mean(dRep$negEmo[dRep$election_timing == "Post-election"], na.rm = T)
## [1] 4.178761
print("means independent")
## [1] "means independent"
dInd <- d2[d2$party_factor == "Independent",]
mean(dInd$negEmo[dInd$election_timing == "During-election"], na.rm = T)
## [1] 3.335632
mean(dInd$negEmo[dInd$election_timing == "Post-election"], na.rm = T)
## [1] 3.180583
decomposing anger interaction
Model: Dem vs Rep interegnum There is no sig difference between Dems and Reps during the election, t(1209) = -1.30, p = 0.194.
anger.m <- lm(emotion_1 ~ (pDem_Rep + pInd_Not) * (tDurD), data = d2)
summary(anger.m)
##
## Call:
## lm(formula = emotion_1 ~ (pDem_Rep + pInd_Not) * (tDurD), data = d2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.7345 -1.7217 -0.6295 1.3705 4.4138
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.20523 0.09448 33.923 < 2e-16 ***
## pDem_Rep -0.23873 0.18349 -1.301 0.194
## pInd_Not 0.92391 0.23600 3.915 9.55e-05 ***
## tDurD -0.14125 0.12950 -1.091 0.276
## pDem_Rep:tDurD 1.25156 0.25531 4.902 1.08e-06 ***
## pInd_Not:tDurD -0.42658 0.32113 -1.328 0.184
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.028 on 1209 degrees of freedom
## (27 observations deleted due to missingness)
## Multiple R-squared: 0.04703, Adjusted R-squared: 0.04309
## F-statistic: 11.93 on 5 and 1209 DF, p-value: 2.711e-11
Model: Dem vs Rep declared There is a significant difference between Dems and Reps such that Reps are 1.01 units angrier then Dems, t(1209) = 5.71, p<.001.
anger.m <- lm(emotion_1 ~ (pDem_Rep + pInd_Not) * (tPostD), data = d2)
summary(anger.m)
##
## Call:
## lm(formula = emotion_1 ~ (pDem_Rep + pInd_Not) * (tPostD), data = d2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.7345 -1.7217 -0.6295 1.3705 4.4138
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.06398 0.08856 34.597 < 2e-16 ***
## pDem_Rep 1.01283 0.17752 5.706 1.46e-08 ***
## pInd_Not 0.49733 0.21778 2.284 0.0226 *
## tPostD 0.14125 0.12950 1.091 0.2756
## pDem_Rep:tPostD -1.25156 0.25531 -4.902 1.08e-06 ***
## pInd_Not:tPostD 0.42658 0.32113 1.328 0.1843
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.028 on 1209 degrees of freedom
## (27 observations deleted due to missingness)
## Multiple R-squared: 0.04703, Adjusted R-squared: 0.04309
## F-statistic: 11.93 on 5 and 1209 DF, p-value: 2.711e-11