US elections is an old story about Republican’s and Democrat’s ambitions, voters, taxes and budget deficit. For more see: https://en.wikipedia.org/wiki/United_States_elections,_2018
I found some interesting data about 2018 US Congress election: https://www.bbc.com/news/world-us-canada-46267519
Let’s explore the data.
uscongress<-read.csv(file = "uscongress.csv",header = T)
uscongress
## Year President Party House Senate
## 1 1958 Eisenhower Rep -48 -13
## 2 1962 Kennedy Dem -4 3
## 3 1966 Johnson Dem -47 -4
## 4 1970 Nixon Rep -12 2
## 5 1974 Ford Rep -48 -5
## 6 1978 Carter Dem -15 -3
## 7 1982 Reagan Rep -26 1
## 8 1986 Reagan Rep -5 -8
## 9 1990 HWBush Rep -8 -1
## 10 1994 Clinton Dem -52 -8
## 11 1998 Clinton Dem 5 0
## 12 2002 WBush Rep 8 2
## 13 2006 WBush Rep -30 -6
## 14 2010 Obama Dem -63 -6
## 15 2014 Obama Dem -13 -9
## 16 2018 Trump Rep -37 2
summary(uscongress)
## Year President Party House Senate
## Min. :1958 Clinton :2 Dem:7 Min. :-63.00 Min. :-13.000
## 1st Qu.:1973 Obama :2 Rep:9 1st Qu.:-47.25 1st Qu.: -6.500
## Median :1988 Reagan :2 Median :-20.50 Median : -3.500
## Mean :1988 WBush :2 Mean :-24.69 Mean : -3.312
## 3rd Qu.:2003 Carter :1 3rd Qu.: -7.25 3rd Qu.: 1.250
## Max. :2018 Eisenhower:1 Max. : 8.00 Max. : 3.000
## (Other) :6
boxplot(House~Party,col=c("blue","red"),data = uscongress,main="US House of representatives", ylab="Seats")
boxplot(Senate~Party,col=c("blue","red"),data = uscongress,main="US Senate", ylab="Seats")
cols <- c("blue", "red")[(uscongress$Party=="Rep")+1]
barplot(uscongress$House,names.arg=uscongress$President,col=cols,main = "US House change by president",cex.names = 0.7,ylab = "Seats",legend.text = c("Democrat", "Republican"),las=2)
barplot(uscongress$Senate,names.arg=uscongress$President,col=cols,main = "US Senate change by president",cex.names = 0.7,ylab = "Seats",legend.text = c("Democrat", "Republican"),las=2)
Our goal is to check out if there is any difference between Republican’s and Democrat’s presidents as far as changes in Congress are concerned during midterms. So we got null hypothesis H0 : there is no difference between Republicans and Democrats. The alternative hypothesis H1 : there is difference between Republicans and Democrats.
library(fitdistrplus)
## Loading required package: MASS
## Loading required package: survival
## Loading required package: npsurv
## Loading required package: lsei
library(nortest)
plotdist(uscongress$House, histo = TRUE, demp = TRUE, col="grey", pch=16)
shapiro.test(uscongress$House)
##
## Shapiro-Wilk normality test
##
## data: uscongress$House
## W = 0.9395, p-value = 0.343
ad.test(uscongress$House)
##
## Anderson-Darling normality test
##
## data: uscongress$House
## A = 0.41041, p-value = 0.3026
plotdist(uscongress$Senate, histo = TRUE, demp = TRUE, col="grey", pch=16)
shapiro.test(uscongress$Senate)
##
## Shapiro-Wilk normality test
##
## data: uscongress$Senate
## W = 0.93688, p-value = 0.3125
ad.test(uscongress$Senate)
##
## Anderson-Darling normality test
##
## data: uscongress$Senate
## A = 0.38167, p-value = 0.3569
According to the obtained results distribution passed the test for normality. So we can apply classical Student test.
we have two independent samples (D, P) for the changes in House and Senate seats. In fact we don’t know the future that is why our data is a sample not a population.
t.test(House~Party,data = uscongress,exact=F)
##
## Welch Two Sample t-test
##
## data: House by Party
## t = -0.34274, df = 10.811, p-value = 0.7384
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -30.56789 22.34567
## sample estimates:
## mean in group Dem mean in group Rep
## -27.00000 -22.88889
t.test(Senate~Party,data = uscongress,exact=F)
##
## Welch Two Sample t-test
##
## data: Senate by Party
## t = -0.3995, df = 13.975, p-value = 0.6956
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -6.167301 4.230793
## sample estimates:
## mean in group Dem mean in group Rep
## -3.857143 -2.888889
So we can’t reject null hypothesis.