Terrorism Data Set
crazyterror <- terror %>%
filter(nkillus > 50)
#typical terror
terrornormal <- terror %>%
filter(country==217, nkillus>0, nkillus <51)
terrordecade1 <- terrornormal %>%
filter(iyear>1969, iyear<1981)
terrordecade2 <- terror %>%
filter(iyear>1979, iyear<1991)
terrordecade3 <- terror %>%
filter(iyear>1989, iyear<2001)
terrordecade4 <- terror %>%
filter(iyear>1999, iyear<2011)
terrordecade5 <- terror %>%
filter(iyear>2009, iyear<2021)
tally(~nkillus, data=terrordecade1)
## nkillus
## 1 2 3 4 5 7 8
## 67 16 2 1 1 1 1
tally(~nkillus, data=terrordecade2)
## nkillus
## 0 1 2 4 5 6 7 17 31 189 241 <NA>
## 1520 81 20 3 3 1 1 1 1 1 1 33414
tally(~nkillus, data=terrordecade3)
## nkillus
## 0 1 2 3 4 5 7 12 15 17 19 60 168
## 4783 87 14 6 1 2 1 1 1 2 1 2 1
## <NA>
## 25674
tally(~nkillus, data=terrordecade4)
## nkillus
## 0 1 2 3 4 5 6 7 8 9 13 14 16
## 29360 105 40 14 16 7 3 1 1 2 1 1 1
## 17 20 38 182 1327 1360 <NA>
## 2 1 1 1 1 1 307
tally(~nkillus, data=terrordecade5)
## nkillus
## 0 1 2 3 4 5 6 9 10 13 15 44 <NA>
## 86391 255 71 28 10 7 9 1 1 1 2 1 38
#number of attacks pie chart (excluding terror attacks of over 50 deaths)
library(plotrix)
##
## Attaching package: 'plotrix'
## The following object is masked from 'package:mosaic':
##
## rescale
labels <- c("Deadly US Terror Attacks 2011-2017 (62)", "Deadly US Terror Attacks 1990-2010 (49)")
pie3D(c(62, 49), col = c('red', 'blue'), labels = labels, explode=0.1)

#number of deaths bar chart (excluding terror attacks of over 50 deaths)
A <- c("1981-1990", "1991-2000", "2001-2010", "2011-2017")
B <- c(32, 44, 69, 197)
deathcounts <- data.frame(A, B)
ggplot(deathcounts, aes(x=A, y=B)) +
geom_bar(stat = "identity") +
labs(x="Decade", y="Number of US Deaths")

#Confidence intervals of average attack deadliness by year
deathmodel <- lm(nkillus ~ iyear+country, data=terrornormal)
summary(deathmodel)
##
## Call:
## lm(formula = nkillus ~ iyear + country, data = terrornormal)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.702 -1.543 -0.596 -0.205 40.351
##
## Coefficients: (1 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -103.46375 34.86141 -2.968 0.00338 **
## iyear 0.05313 0.01751 3.034 0.00274 **
## country NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.49 on 194 degrees of freedom
## Multiple R-squared: 0.04531, Adjusted R-squared: 0.04039
## F-statistic: 9.207 on 1 and 194 DF, p-value: 0.002741
newdata <- data.frame(iyear=2025, country=217)
predict(deathmodel, newdata=newdata, int="confidence", level=0.95)
## Warning in predict.lm(deathmodel, newdata = newdata, int = "confidence", :
## prediction from a rank-deficient fit may be misleading
## fit lwr upr
## 1 4.127177 2.788042 5.466312
newdata1 <- data.frame(iyear=2020, country=217)
predict(deathmodel, newdata=newdata1, int="confidence", level=0.95)
## Warning in predict.lm(deathmodel, newdata = newdata1, int = "confidence", :
## prediction from a rank-deficient fit may be misleading
## fit lwr upr
## 1 3.861521 2.671789 5.051252
newdata1 <- data.frame(iyear=2015, country=217)
predict(deathmodel, newdata=newdata1, int="confidence", level=0.95)
## Warning in predict.lm(deathmodel, newdata = newdata1, int = "confidence", :
## prediction from a rank-deficient fit may be misleading
## fit lwr upr
## 1 3.595864 2.548355 4.643373
newdata1 <- data.frame(iyear=2010, country=217)
predict(deathmodel, newdata=newdata1, int="confidence", level=0.95)
## Warning in predict.lm(deathmodel, newdata = newdata1, int = "confidence", :
## prediction from a rank-deficient fit may be misleading
## fit lwr upr
## 1 3.330207 2.41439 4.246024
tally(~attacktype1_txt, groups = iyear, data=terrornormal)
## iyear
## attacktype1_txt 1970 1971 1972 1973 1974 1975 1976 1977
## Armed Assault 13 6 3 11 7 0 0 1
## Assassination 4 2 0 6 1 4 0 0
## Bombing/Explosion 3 2 0 0 1 1 0 0
## Facility/Infrastructure Attack 0 1 0 0 0 0 0 0
## Hijacking 0 0 0 0 0 0 1 0
## Hostage Taking (Barricade Incident) 0 0 0 1 0 0 0 0
## Hostage Taking (Kidnapping) 1 0 0 2 0 0 0 0
## Unarmed Assault 0 0 0 0 0 0 0 0
## Unknown 0 1 0 0 0 0 0 0
## iyear
## attacktype1_txt 1978 1979 1980 1981 1982 1983 1984 1985
## Armed Assault 2 5 7 1 0 2 0 0
## Assassination 2 0 1 0 2 0 1 0
## Bombing/Explosion 0 0 0 0 0 0 0 1
## Facility/Infrastructure Attack 0 0 0 0 0 1 0 1
## Hijacking 0 0 0 0 0 0 0 0
## Hostage Taking (Barricade Incident) 0 0 0 1 2 1 0 0
## Hostage Taking (Kidnapping) 0 0 0 1 0 0 0 0
## Unarmed Assault 0 0 0 0 0 0 0 0
## Unknown 0 0 0 0 0 0 0 0
## iyear
## attacktype1_txt 1989 1990 1994 1995 1996 1997 1998 1999
## Armed Assault 0 0 4 0 0 0 2 3
## Assassination 1 3 0 0 0 0 0 0
## Bombing/Explosion 1 0 1 1 2 1 0 0
## Facility/Infrastructure Attack 0 0 1 1 0 0 0 0
## Hijacking 0 0 0 0 0 0 0 0
## Hostage Taking (Barricade Incident) 0 0 0 1 0 0 0 0
## Hostage Taking (Kidnapping) 0 0 0 0 0 0 0 1
## Unarmed Assault 0 0 0 0 0 0 0 0
## Unknown 0 0 0 0 0 0 0 0
## iyear
## attacktype1_txt 2001 2006 2008 2009 2010 2012 2013 2014
## Armed Assault 0 1 1 5 1 1 3 13
## Assassination 0 0 0 0 0 0 0 0
## Bombing/Explosion 0 0 0 0 0 0 2 1
## Facility/Infrastructure Attack 0 0 0 0 1 0 1 0
## Hijacking 1 0 0 0 0 0 1 0
## Hostage Taking (Barricade Incident) 0 0 0 0 1 0 0 0
## Hostage Taking (Kidnapping) 0 0 0 0 0 0 0 0
## Unarmed Assault 4 0 0 0 0 0 0 0
## Unknown 0 0 0 0 0 0 0 0
## iyear
## attacktype1_txt 2015 2016 2017
## Armed Assault 7 6 13
## Assassination 0 0 1
## Bombing/Explosion 1 0 0
## Facility/Infrastructure Attack 0 0 0
## Hijacking 0 0 0
## Hostage Taking (Barricade Incident) 2 1 0
## Hostage Taking (Kidnapping) 0 0 0
## Unarmed Assault 0 0 2
## Unknown 0 0 0