Then mean standard deviation and summary of the victims of the mass shooting are below:
df <- read.csv("Project.csv")
mean(df$Total.victims)
## [1] 10.26316
sd(df$Total.victims)
## [1] 33.66231
summary(df$Total.victims)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.00 4.00 5.00 10.26 9.00 585.00
##HISTOGRAM OF THE VICTIMS OF THE SHOOTING
hist(df$Total.victims,
main = "HIST victim",
xlab = "victims",
col = "red" ,
probability = TRUE)
lines(df$Total.victims, col ="blue")
##BOX PLOT FOR THE DATASET OF THE VICTIMS
boxplot(df$Total.victims,
main = "BOX PLOT",
horizontal = FALSE,
xlab = " victim ")
##QQ PLOT
qqnorm(df$Total.victims,
main = "QQplot victims",
xlab = "",
ylab = "victims")
qqline(df$Total.victims, col = "blue")
IQR(df$Total.victims, na.rm = FALSE)
## [1] 5
##OUTLINERS
outliners <-boxplot(df$Total.victims, plot = FALSE) $out
outliners
## [1] 46 585 102 17 17 35 35 19 19 29 82 19 45 18 26 55 21 37 29
## [20] 27 25 43 17 20 35 20 20 40 22 48
plot(df$Total.victims,df$Injured,
main = "MULTIPLE VARIABLE GRAPHICAL DISPLAY",
xlab = "victims",
ylab = "Injured",
pch = 20)
table(df$Mental.Health.Issues)
##
## No Yes
## 129 194
table(df$Fatalities/length(df$Fatalities))
##
## 0 0.00309597523219814 0.00619195046439629 0.00928792569659443
## 41 46 38 45
## 0.0123839009287926 0.0154798761609907 0.0185758513931889 0.021671826625387
## 34 38 27 14
## 0.0247678018575851 0.0278637770897833 0.0309597523219814 0.0340557275541796
## 9 7 5 1
## 0.0371517027863777 0.0402476780185759 0.043343653250774 0.0464396284829721
## 2 3 2 2
## 0.0495356037151703 0.0526315789473684 0.0681114551083591 0.0743034055727554
## 1 1 1 1
## 0.0804953560371517 0.086687306501548 0.0990712074303406 0.151702786377709
## 1 1 1 1
## 0.18266253869969
## 1
two_way_table <-table(df$Mental.Health.Issues,df$Gender)
par(mfrow=c(1,2))
plot(df$Total.victims,
main = "scatter plot of victims",
xlab = "",
ylab = "victims")
plot(df$Injured,
main = "Scatter plot of Injured",
xlab = "",
ylab = "Injured")
print("victims summary:")
## [1] "victims summary:"
summary(df$Total.victims)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.00 4.00 5.00 10.26 9.00 585.00
print("Injured summary:")
## [1] "Injured summary:"
summary(df$Injured)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 1.000 3.000 6.176 5.000 527.000
barplot(df$Injured,
main = "BAR CHART",
xlab = "Injured")
scatter.smooth(df$Injured,
main = "SCATTER PLOT")
data <-read.csv("Project.csv",header = TRUE)
data <-data.matrix(data[,-1])
heatmap(t(data),
main = "HEAT MAP",
Rowv = NA,
Colv = NA,
col = heat.colors(200, alpha = 1, rev = FALSE),
scale = "row")
##Decision Tree
library(rpart)
library(rpart.plot)
tree <- rpart(Gender ~.,data = df)
tree
## n= 323
##
## node), split, n, loss, yval, (yprob)
## * denotes terminal node
##
## 1) root 323 38 Male (0.1176471 0.8823529)
## 2) Title=Atlanta Nightclub shooting,Carnation, Washington,Cedarville Rancheria Tribe,Chicago Birthday Party Bus Shooting,Chicago Rap video Shootout,Detroit Drive-by,Ferguson, MO Drive by,Florida Family celebration ends in shooting,Florida Hookah Bar Shooting,Forestville, Maryland Drive-by,Fresno downtown shooting,Goleta Post Office,Grover Cleveland Elementary School,Houston Drive-by,Hubbard Woods Elementary School,Lafayette, LA drive by,Long Beach Street murder,Los Angeles Drive-by,Los Angeles, CA street shooting,Louisville, KY Family Murder-Suicide,Marysville-Pilchuck High School,Memphis, TN gas station shooting,Moon Lake,Nellis Plaza,Nightclub fight turns into shootout,Northern Arizona University at Flagstaff Campus,Omaha, Nebraska,Palo Duro High School,Roadside in Memphis, Tennessee,San Bernardino mass shooting,San Bernardino, California,Tampa, FL Strip club shooting,The Spot Nightclub,Trenton, NJ sidewalk shooting,University of Alabama in Huntsville,University of Texas at Austin,Vallejo, CA car shooting,Wichita Nightclub shooting 38 0 Female (1.0000000 0.0000000) *
## 3) Title=49th Street Elementary School,Accent Signage Systems in Minneapolis,Alabama highway random shooting,Albuquerque Auto Shop,Albuquerque, NM Family restaurant shooting,Albuquerque, NM House party shooting,Amish school shooting,Amnicola Training Center, Chattanooga,Annual motorcycle event in Newark,Appalachian School of Law,Arizona Family Murder,Atlanta Post Office,Atlantis Plastics,Aurora theater shooting,Azana Spa in Brookfield,Baton Rouge police shooting,Belfair, WA Family murder-suicide,Belfair, Washington,Bethel Regional High School,Binghamton shootings,Birchwood, Wisconsin,Birmingham's Washington Park,Boom Boom Room,Bourbon Street New Orleans,Bristol, Tennessee,Brookhaven,Cafe in Seattle,Cal State Fullerton,Caltrans Maintenance Yard,Capitol Hill massacre,Caroline County, VA Family Murder Suicide,Carthage nursing home shooting,Cascade Mall shooting,Case Western Reserve University,Centennial Hill Bar & Grill,Central Middle School,Chapel Hill,Chardon High School,Charleston Church Shooting,Charlotte,Chelsea High School,Chelsea, MA empty apartment party shooting,Chesapeake, Virginia,Chuck E. Cheese in Aurora,Clackamas Town Center,Clara Barton Elementary School,Clarkesville,Clearbrook (Greenwood), Minnesota,Cleveland,Cleveland Elementary School,Club Maxey's,Coffee shop police killings,Colerain Township, Ohio,Colorado Springs,Columbine High School,Columbus, Ohio,Comet Auto Parts and Montefiore School,Connecticut State Lottery Headquarters,Conyers,Cottonwood,Covina, California,Crandon shooting,Dallas police shooting,Damageplan show at the Alrosa Villa Nightclub,Dana Point Post Office,Daytona Beach,Dearborn Post Office,Deer Lodge,Detroit Strip Club Shootout,Douglasville,Downtown Chapel Hill,Duquesne University,Edgewood businees park shooting,Elberton, Georgia murder-suicide,Electromagnetic Systems Laboratory (ESL),Ensley Birmingham,Essex Elementary School,Excel Industries mass shooting,Fairchild Air Force Base Hospital,Fergus County High School,Florida awning manufacturer shooting,Florida family murder,Florida State University,Fort Gibson Middle School,Fort Hood,Fort Hood Army Base,Fort Hood shooting 2,Fort Lauderdale airport shooting,Fort Lauderdale revenge shooting,Fox Cities Trestle Trail bridge over Little Lake Butte des Morts,Frontier Junior High School,Gates Pub,Geneva County, Alabama,Glendale, AZ House Party shooting,Gloucester County, VA, House Party,GMAC Loan Office,Goddard Junior High School,Grand 16 Theatre, Louisiana,Greenhill, AL Family murder-suicide,Halifax County, VA,Hartford Beer Distributor shooting,Heath High School,Heritage High School,Hesston, Kansas,Hialeah apartment shooting,Hill Haven Event Center (Formerly Club CJ's),Homes in Desoto and Dallas,Houston, Texas,Ianni's Club in Dallas,IHOP shooting,Indianapolis,Inglis, Florida,Isla Vista mass murder,Iuka, Mississippi,Jacksonville, Florida,Johnston Post Office,Kalamazoo shooting spree,Kalamazoo Uber Driver Spree Killing,Kansas City Home Invasion,Kansas City, Kansas,Kennesaw FedEx,Killeen,King, North Carolina,Kirkwood City Hall,Ladera Ranch, Santa Ana, Tustin and Orange,LaGrange,Las Vegas Strip mass shooting,Lawrenceburg, Tennessee,Lindhurst High School,Little Water,Living Church of God,Lockheed Martin shooting,Long Island Rail Road Commuter Train,Los Angeles Computer Learning Center,Los Angeles International Airport (LAX),Los Angeles Police Department,Louisburg, North Carolina,Luby's Cafeteria in Killeen, Texas,Luigi's Restaurant in Fayetteville,Massachusetts Abortion Clinic,McAvan's Pub,McDonald's restaurant in San Ysidro,Memphis,Mesa,Miami Gardens,Michigan school shooting,Milwaukee,Milwaukee Post Office,Minneapolis, Minnesota,Missouri Highway shooting,Mohawk and Herkimer Villages in New York,Mojave High School Bus,Monroeville Macy's,Montclair Post Office,Morgantown,Moscow,Navistar International,New Orleans Downtown Post Office,New Orleans gas station shoot-out,New Orleans Police Shootings,New York Technical College,North Tulsa, Oklahoma,Northern Illinois University shooting,Oakland Elementary School,Oakland, Maine,Offices of All-Tech Investment Group and Momentum Securities,Offices of Pettit & Martin in San Francisco,Oikos University killings,Oklahoma City Residence,Olean High School,Omaha,Orange Glenn Post Office,Orange High School,Orlando nightclub massacre,Orlando, Florida,Palm Bay Shopping Centers,Panama City Beach,Parker Middle School Dance,Parking lot near Boys and Girls Club,Parkland Coffee Shop,Pearl High School,Pennsburg, Souderton, Lansdale, Harleysville,Pennsylvania supermarket shooting,Perris, CA Mexican restaurant shooting,Phoenix,Phoenix Law Firm,Pinelake Health and Rehab nursing home,Pinellas Park High School,Pinewood Village Apartments,Pittsburgh, Pennsylvania,Planned Parenthood clinic,Plantation, Florida,Platte, South Dakota,Post office in Edmond, Oklahoma,Queens,R.E. Phelon Company,Radisson Bay Harbor Inn,Red Lake High School,Residence in Lakeland, Florida,Residence in Union, Kentucky,Residences in Grand Rapids,Richland High School,Richmond, Virginia,Ridgewood Post Office,River Forest,Rivermark, Santa Clara, California,Riverside City Hall,Riverside restaurant shooting,Rome,Rose-Mar College of Beauty,Ross Township Supervisor Council Meeting,Roswell, GA Hookah shootout,Royal Oak Post Office,Rural Ohio nursing home shooting,Salon Meritage,San Diego State University,San Francisco Tenderloin,San Francisco UPS shooting,Sandy Hook Elementary School,Santa Monica College,Santana High School,Schuyler County Office Building,Seattle cafe shooting,Seattle Pacific University,Sherman, Texas Family Murder-Suicide,Sikh Temple in Wisconsin,Simon's Rock College of Bard,South Middle School Football Game,South Mountain Community College,South Valley Residence,Southern Union State Community College,Sparks Middle School,Springwater Trail High School,St. Aloysius Church,Standard Gravure Corporation,Su Jung Health Sauna shooting,SuccessTech Academy,Suwanee,Tarboro,Tennessee Colony, Texas,Texas church mass shooting,Texas family murder-suicide,Texas teen commits family murder suicide,Thurston High School,Tire-Slashing revenge escalation,Trestle Trail bridge shooting,Trolley Square,Tucson,Tucson shooting,Tulsa,Tyler Courthouse,Tyrone,Umpqua Community College,University Heights Apartments in Auburn,University of Arizona College of Nursing,University of Central Arkansas,University of Iowa,University of South Carolina,Valley High School,Village of Manchester in Illinois,Virginia Tech massacre,Virginia WDBJ live TV interview shooting,Wah Mee Club in Seattle,Wakefield massacre,Walmart shooting in suburban Denver,Walter Rossler Company,Washington Navy Yard,Wat Promkunaram Buddhist Temple,Waycross, GA,Weber State University,Wedgwood Baptist Church,Welding shop in Miami,West Nickel Mines Amish School,Westroads Mall shooting,Westside Middle School killings,Wetumpka Drive-by,Wickliffe Middle School,Wilkinsburg BBQ cookout shootout,Wilmington, DE robbery,Windy City Core Supply Warehouse,Woodbridge, Virginia,Xerox killings,Youngstown State University,Youth With A Mission and New Life Church 285 0 Male (0.0000000 1.0000000) *
rpart.plot(tree, extra = 2)
predict
pred <- predict(tree, df, type = "class")
head(pred)
## 1 2 3 4 5 6
## Male Male Male Male Male Male
## Levels: Female Male
Confusion matrix
confusion_table <- with(df, table(Gender, pred))
confusion_table
## pred
## Gender Female Male
## Female 38 0
## Male 0 285
Cross validation
library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(magrittr)
imp <- varImp(tree)
head(imp)
## Overall
## Fatalities 3.9450458
## Injured 0.9188003
## open.Close 2.8078900
## Title 67.0588235
## Total.victims 0.8175364
## Policeman.Killed 0.0000000
imp %>% ggplot(aes(x = row.names(imp), weight = Overall)) +
geom_bar()
library(FSelector)
weights <- df %>% chi.squared(Mental.Health.Issues ~ ., data = .) %>%
as_tibble(rownames = "feature") %>%
arrange(desc(attr_importance))
weights
## # A tibble: 8 × 2
## feature attr_importance
## <chr> <dbl>
## 1 Title 0.997
## 2 Age 0.244
## 3 open.Close 0.147
## 4 Gender 0.00346
## 5 Fatalities 0
## 6 Injured 0
## 7 Total.victims 0
## 8 Policeman.Killed 0
library(arules)
## Loading required package: Matrix
##
## Attaching package: 'arules'
## The following object is masked from 'package:dplyr':
##
## recode
## The following objects are masked from 'package:base':
##
## abbreviate, write
library(arulesViz)
transactions(df)
## Warning: Column(s) 1, 2, 3, 4, 5, 6, 7, 8, 9 not logical or factor. Applying
## default discretization (see '? discretizeDF').
## Warning in discretize(x = c(0L, 0L, 0L, 1L, 0L, 2L, 1L, 1L, 1L, 0L, 0L, : The calculated breaks are: 0, 0, 0, 5
## Only unique breaks are used reducing the number of intervals. Look at ? discretize for details.
## transactions in sparse format with
## 323 transactions (rows) and
## 343 items (columns)
colnames(df)[c(1,2,3,4,5,6,7,8,9,13)]
## [1] "Title" "open.Close" "Fatalities"
## [4] "Injured" "Total.victims" "Policeman.Killed"
## [7] "Age" "Mental.Health.Issues" "Gender"
## [10] NA
df<- df %>% mutate(
Total.victims = (Total.victims > 10 ),
Fatalities = (Fatalities >5 )
)
trans <- transactions(df)
## Warning: Column(s) 1, 2, 4, 6, 7, 8, 9 not logical or factor. Applying default
## discretization (see '? discretizeDF').
## Warning in discretize(x = c(0L, 0L, 0L, 1L, 0L, 2L, 1L, 1L, 1L, 0L, 0L, : The calculated breaks are: 0, 0, 0, 5
## Only unique breaks are used reducing the number of intervals. Look at ? discretize for details.
summary(trans)
## transactions as itemMatrix in sparse format with
## 323 rows (elements/itemsets/transactions) and
## 339 columns (items) and a density of 0.02196407
##
## most frequent items:
## Policeman.Killed=[0,5] Gender=Male open.Close=Close
## 323 285 204
## Mental.Health.Issues=Yes Injured=[4,527] (Other)
## 194 129 1270
##
## element (itemset/transaction) length distribution:
## sizes
## 7 8 9
## 219 64 40
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 7.000 7.000 7.000 7.446 8.000 9.000
##
## includes extended item information - examples:
## labels variables
## 1 Title=49th Street Elementary School Title
## 2 Title=Accent Signage Systems in Minneapolis Title
## 3 Title=Alabama highway random shooting Title
## levels
## 1 49th Street Elementary School
## 2 Accent Signage Systems in Minneapolis
## 3 Alabama highway random shooting
##
## includes extended transaction information - examples:
## transactionID
## 1 1
## 2 2
## 3 3
colnames(trans)
## [1] "Title=49th Street Elementary School"
## [2] "Title=Accent Signage Systems in Minneapolis"
## [3] "Title=Alabama highway random shooting"
## [4] "Title=Albuquerque Auto Shop"
## [5] "Title=Albuquerque, NM Family restaurant shooting"
## [6] "Title=Albuquerque, NM House party shooting"
## [7] "Title=Amish school shooting"
## [8] "Title=Amnicola Training Center, Chattanooga"
## [9] "Title=Annual motorcycle event in Newark"
## [10] "Title=Appalachian School of Law"
## [11] "Title=Arizona Family Murder"
## [12] "Title=Atlanta Nightclub shooting"
## [13] "Title=Atlanta Post Office"
## [14] "Title=Atlantis Plastics"
## [15] "Title=Aurora theater shooting"
## [16] "Title=Azana Spa in Brookfield"
## [17] "Title=Baton Rouge police shooting"
## [18] "Title=Belfair, WA Family murder-suicide"
## [19] "Title=Belfair, Washington"
## [20] "Title=Bethel Regional High School"
## [21] "Title=Binghamton shootings"
## [22] "Title=Birchwood, Wisconsin"
## [23] "Title=Birmingham's Washington Park"
## [24] "Title=Boom Boom Room"
## [25] "Title=Bourbon Street New Orleans"
## [26] "Title=Bristol, Tennessee"
## [27] "Title=Brookhaven"
## [28] "Title=Cafe in Seattle"
## [29] "Title=Cal State Fullerton"
## [30] "Title=Caltrans Maintenance Yard"
## [31] "Title=Capitol Hill massacre"
## [32] "Title=Carnation, Washington"
## [33] "Title=Caroline County, VA Family Murder Suicide"
## [34] "Title=Carthage nursing home shooting"
## [35] "Title=Cascade Mall shooting"
## [36] "Title=Case Western Reserve University"
## [37] "Title=Cedarville Rancheria Tribe"
## [38] "Title=Centennial Hill Bar & Grill"
## [39] "Title=Central Middle School"
## [40] "Title=Chapel Hill"
## [41] "Title=Chardon High School"
## [42] "Title=Charleston Church Shooting"
## [43] "Title=Charlotte"
## [44] "Title=Chelsea High School"
## [45] "Title=Chelsea, MA empty apartment party shooting"
## [46] "Title=Chesapeake, Virginia"
## [47] "Title=Chicago Birthday Party Bus Shooting"
## [48] "Title=Chicago Rap video Shootout"
## [49] "Title=Chuck E. Cheese in Aurora"
## [50] "Title=Clackamas Town Center"
## [51] "Title=Clara Barton Elementary School"
## [52] "Title=Clarkesville"
## [53] "Title=Clearbrook (Greenwood), Minnesota"
## [54] "Title=Cleveland"
## [55] "Title=Cleveland Elementary School"
## [56] "Title=Club Maxey's"
## [57] "Title=Coffee shop police killings"
## [58] "Title=Colerain Township, Ohio"
## [59] "Title=Colorado Springs"
## [60] "Title=Columbine High School"
## [61] "Title=Columbus, Ohio"
## [62] "Title=Comet Auto Parts and Montefiore School"
## [63] "Title=Connecticut State Lottery Headquarters"
## [64] "Title=Conyers"
## [65] "Title=Cottonwood"
## [66] "Title=Covina, California"
## [67] "Title=Crandon shooting"
## [68] "Title=Dallas police shooting"
## [69] "Title=Damageplan show at the Alrosa Villa Nightclub"
## [70] "Title=Dana Point Post Office"
## [71] "Title=Daytona Beach"
## [72] "Title=Dearborn Post Office"
## [73] "Title=Deer Lodge"
## [74] "Title=Detroit Drive-by"
## [75] "Title=Detroit Strip Club Shootout"
## [76] "Title=Douglasville"
## [77] "Title=Downtown Chapel Hill"
## [78] "Title=Duquesne University"
## [79] "Title=Edgewood businees park shooting"
## [80] "Title=Elberton, Georgia murder-suicide"
## [81] "Title=Electromagnetic Systems Laboratory (ESL)"
## [82] "Title=Ensley Birmingham"
## [83] "Title=Essex Elementary School"
## [84] "Title=Excel Industries mass shooting"
## [85] "Title=Fairchild Air Force Base Hospital"
## [86] "Title=Fergus County High School"
## [87] "Title=Ferguson, MO Drive by"
## [88] "Title=Florida awning manufacturer shooting"
## [89] "Title=Florida Family celebration ends in shooting"
## [90] "Title=Florida family murder"
## [91] "Title=Florida Hookah Bar Shooting"
## [92] "Title=Florida State University"
## [93] "Title=Forestville, Maryland Drive-by"
## [94] "Title=Fort Gibson Middle School"
## [95] "Title=Fort Hood"
## [96] "Title=Fort Hood Army Base"
## [97] "Title=Fort Hood shooting 2"
## [98] "Title=Fort Lauderdale airport shooting"
## [99] "Title=Fort Lauderdale revenge shooting"
## [100] "Title=Fox Cities Trestle Trail bridge over Little Lake Butte des Morts"
## [101] "Title=Fresno downtown shooting"
## [102] "Title=Frontier Junior High School"
## [103] "Title=Gates Pub"
## [104] "Title=Geneva County, Alabama"
## [105] "Title=Glendale, AZ House Party shooting"
## [106] "Title=Gloucester County, VA, House Party"
## [107] "Title=GMAC Loan Office"
## [108] "Title=Goddard Junior High School"
## [109] "Title=Goleta Post Office"
## [110] "Title=Grand 16 Theatre, Louisiana"
## [111] "Title=Greenhill, AL Family murder-suicide"
## [112] "Title=Grover Cleveland Elementary School"
## [113] "Title=Halifax County, VA"
## [114] "Title=Hartford Beer Distributor shooting"
## [115] "Title=Heath High School"
## [116] "Title=Heritage High School"
## [117] "Title=Hesston, Kansas"
## [118] "Title=Hialeah apartment shooting"
## [119] "Title=Hill Haven Event Center (Formerly Club CJ's)"
## [120] "Title=Homes in Desoto and Dallas"
## [121] "Title=Houston Drive-by"
## [122] "Title=Houston, Texas"
## [123] "Title=Hubbard Woods Elementary School"
## [124] "Title=Ianni's Club in Dallas"
## [125] "Title=IHOP shooting"
## [126] "Title=Indianapolis"
## [127] "Title=Inglis, Florida"
## [128] "Title=Isla Vista mass murder"
## [129] "Title=Iuka, Mississippi"
## [130] "Title=Jacksonville, Florida"
## [131] "Title=Johnston Post Office"
## [132] "Title=Kalamazoo shooting spree"
## [133] "Title=Kalamazoo Uber Driver Spree Killing"
## [134] "Title=Kansas City Home Invasion"
## [135] "Title=Kansas City, Kansas"
## [136] "Title=Kennesaw FedEx"
## [137] "Title=Killeen"
## [138] "Title=King, North Carolina"
## [139] "Title=Kirkwood City Hall"
## [140] "Title=Ladera Ranch, Santa Ana, Tustin and Orange"
## [141] "Title=Lafayette, LA drive by"
## [142] "Title=LaGrange"
## [143] "Title=Las Vegas Strip mass shooting"
## [144] "Title=Lawrenceburg, Tennessee"
## [145] "Title=Lindhurst High School"
## [146] "Title=Little Water"
## [147] "Title=Living Church of God"
## [148] "Title=Lockheed Martin shooting"
## [149] "Title=Long Beach Street murder"
## [150] "Title=Long Island Rail Road Commuter Train"
## [151] "Title=Los Angeles Computer Learning Center"
## [152] "Title=Los Angeles Drive-by"
## [153] "Title=Los Angeles International Airport (LAX)"
## [154] "Title=Los Angeles Police Department"
## [155] "Title=Los Angeles, CA street shooting"
## [156] "Title=Louisburg, North Carolina"
## [157] "Title=Louisville, KY Family Murder-Suicide"
## [158] "Title=Luby's Cafeteria in Killeen, Texas"
## [159] "Title=Luigi's Restaurant in Fayetteville"
## [160] "Title=Marysville-Pilchuck High School"
## [161] "Title=Massachusetts Abortion Clinic"
## [162] "Title=McAvan's Pub"
## [163] "Title=McDonald's restaurant in San Ysidro"
## [164] "Title=Memphis"
## [165] "Title=Memphis, TN gas station shooting"
## [166] "Title=Mesa"
## [167] "Title=Miami Gardens"
## [168] "Title=Michigan school shooting"
## [169] "Title=Milwaukee"
## [170] "Title=Milwaukee Post Office"
## [171] "Title=Minneapolis, Minnesota"
## [172] "Title=Missouri Highway shooting"
## [173] "Title=Mohawk and Herkimer Villages in New York"
## [174] "Title=Mojave High School Bus"
## [175] "Title=Monroeville Macy's"
## [176] "Title=Montclair Post Office"
## [177] "Title=Moon Lake"
## [178] "Title=Morgantown"
## [179] "Title=Moscow"
## [180] "Title=Navistar International"
## [181] "Title=Nellis Plaza"
## [182] "Title=New Orleans Downtown Post Office"
## [183] "Title=New Orleans gas station shoot-out"
## [184] "Title=New Orleans Police Shootings"
## [185] "Title=New York Technical College"
## [186] "Title=Nightclub fight turns into shootout"
## [187] "Title=North Tulsa, Oklahoma"
## [188] "Title=Northern Arizona University at Flagstaff Campus"
## [189] "Title=Northern Illinois University shooting"
## [190] "Title=Oakland Elementary School"
## [191] "Title=Oakland, Maine"
## [192] "Title=Offices of All-Tech Investment Group and Momentum Securities"
## [193] "Title=Offices of Pettit & Martin in San Francisco"
## [194] "Title=Oikos University killings"
## [195] "Title=Oklahoma City Residence"
## [196] "Title=Olean High School"
## [197] "Title=Omaha"
## [198] "Title=Omaha, Nebraska"
## [199] "Title=Orange Glenn Post Office"
## [200] "Title=Orange High School"
## [201] "Title=Orlando nightclub massacre"
## [202] "Title=Orlando, Florida"
## [203] "Title=Palm Bay Shopping Centers"
## [204] "Title=Palo Duro High School"
## [205] "Title=Panama City Beach"
## [206] "Title=Parker Middle School Dance"
## [207] "Title=Parking lot near Boys and Girls Club"
## [208] "Title=Parkland Coffee Shop"
## [209] "Title=Pearl High School"
## [210] "Title=Pennsburg, Souderton, Lansdale, Harleysville"
## [211] "Title=Pennsylvania supermarket shooting"
## [212] "Title=Perris, CA Mexican restaurant shooting"
## [213] "Title=Phoenix"
## [214] "Title=Phoenix Law Firm"
## [215] "Title=Pinelake Health and Rehab nursing home"
## [216] "Title=Pinellas Park High School"
## [217] "Title=Pinewood Village Apartments"
## [218] "Title=Pittsburgh, Pennsylvania"
## [219] "Title=Planned Parenthood clinic"
## [220] "Title=Plantation, Florida"
## [221] "Title=Platte, South Dakota"
## [222] "Title=Post office in Edmond, Oklahoma"
## [223] "Title=Queens"
## [224] "Title=R.E. Phelon Company"
## [225] "Title=Radisson Bay Harbor Inn"
## [226] "Title=Red Lake High School"
## [227] "Title=Residence in Lakeland, Florida"
## [228] "Title=Residence in Union, Kentucky"
## [229] "Title=Residences in Grand Rapids"
## [230] "Title=Richland High School"
## [231] "Title=Richmond, Virginia"
## [232] "Title=Ridgewood Post Office"
## [233] "Title=River Forest"
## [234] "Title=Rivermark, Santa Clara, California"
## [235] "Title=Riverside City Hall"
## [236] "Title=Riverside restaurant shooting"
## [237] "Title=Roadside in Memphis, Tennessee"
## [238] "Title=Rome"
## [239] "Title=Rose-Mar College of Beauty"
## [240] "Title=Ross Township Supervisor Council Meeting"
## [241] "Title=Roswell, GA Hookah shootout"
## [242] "Title=Royal Oak Post Office"
## [243] "Title=Rural Ohio nursing home shooting"
## [244] "Title=Salon Meritage"
## [245] "Title=San Bernardino mass shooting"
## [246] "Title=San Bernardino, California"
## [247] "Title=San Diego State University"
## [248] "Title=San Francisco Tenderloin"
## [249] "Title=San Francisco UPS shooting"
## [250] "Title=Sandy Hook Elementary School"
## [251] "Title=Santa Monica College"
## [252] "Title=Santana High School"
## [253] "Title=Schuyler County Office Building"
## [254] "Title=Seattle cafe shooting"
## [255] "Title=Seattle Pacific University"
## [256] "Title=Sherman, Texas Family Murder-Suicide"
## [257] "Title=Sikh Temple in Wisconsin"
## [258] "Title=Simon's Rock College of Bard"
## [259] "Title=South Middle School Football Game"
## [260] "Title=South Mountain Community College"
## [261] "Title=South Valley Residence"
## [262] "Title=Southern Union State Community College"
## [263] "Title=Sparks Middle School"
## [264] "Title=Springwater Trail High School"
## [265] "Title=St. Aloysius Church"
## [266] "Title=Standard Gravure Corporation"
## [267] "Title=Su Jung Health Sauna shooting"
## [268] "Title=SuccessTech Academy"
## [269] "Title=Suwanee"
## [270] "Title=Tampa, FL Strip club shooting"
## [271] "Title=Tarboro"
## [272] "Title=Tennessee Colony, Texas"
## [273] "Title=Texas church mass shooting"
## [274] "Title=Texas family murder-suicide"
## [275] "Title=Texas teen commits family murder suicide"
## [276] "Title=The Spot Nightclub"
## [277] "Title=Thurston High School"
## [278] "Title=Tire-Slashing revenge escalation"
## [279] "Title=Trenton, NJ sidewalk shooting"
## [280] "Title=Trestle Trail bridge shooting"
## [281] "Title=Trolley Square"
## [282] "Title=Tucson"
## [283] "Title=Tucson shooting"
## [284] "Title=Tulsa"
## [285] "Title=Tyler Courthouse"
## [286] "Title=Tyrone"
## [287] "Title=Umpqua Community College"
## [288] "Title=University Heights Apartments in Auburn"
## [289] "Title=University of Alabama in Huntsville"
## [290] "Title=University of Arizona College of Nursing"
## [291] "Title=University of Central Arkansas"
## [292] "Title=University of Iowa"
## [293] "Title=University of South Carolina"
## [294] "Title=University of Texas at Austin"
## [295] "Title=Vallejo, CA car shooting"
## [296] "Title=Valley High School"
## [297] "Title=Village of Manchester in Illinois"
## [298] "Title=Virginia Tech massacre"
## [299] "Title=Virginia WDBJ live TV interview shooting"
## [300] "Title=Wah Mee Club in Seattle"
## [301] "Title=Wakefield massacre"
## [302] "Title=Walmart shooting in suburban Denver"
## [303] "Title=Walter Rossler Company"
## [304] "Title=Washington Navy Yard"
## [305] "Title=Wat Promkunaram Buddhist Temple"
## [306] "Title=Waycross, GA"
## [307] "Title=Weber State University"
## [308] "Title=Wedgwood Baptist Church"
## [309] "Title=Welding shop in Miami"
## [310] "Title=West Nickel Mines Amish School"
## [311] "Title=Westroads Mall shooting"
## [312] "Title=Westside Middle School killings"
## [313] "Title=Wetumpka Drive-by"
## [314] "Title=Wichita Nightclub shooting"
## [315] "Title=Wickliffe Middle School"
## [316] "Title=Wilkinsburg BBQ cookout shootout"
## [317] "Title=Wilmington, DE robbery"
## [318] "Title=Windy City Core Supply Warehouse"
## [319] "Title=Woodbridge, Virginia"
## [320] "Title=Xerox killings"
## [321] "Title=Youngstown State University"
## [322] "Title=Youth With A Mission and New Life Church"
## [323] "open.Close="
## [324] "open.Close=close"
## [325] "open.Close=Close"
## [326] "open.Close=Open"
## [327] "Fatalities"
## [328] "Injured=[0,2)"
## [329] "Injured=[2,4)"
## [330] "Injured=[4,527]"
## [331] "Total.victims"
## [332] "Policeman.Killed=[0,5]"
## [333] "Age=[12,25)"
## [334] "Age=[25,35)"
## [335] "Age=[35,70]"
## [336] "Mental.Health.Issues=No"
## [337] "Mental.Health.Issues=Yes"
## [338] "Gender=Female"
## [339] "Gender=Male"
inspect(trans[1:4])
## items transactionID
## [1] {Title=Texas church mass shooting,
## open.Close=Close,
## Fatalities,
## Injured=[4,527],
## Total.victims,
## Policeman.Killed=[0,5],
## Age=[25,35),
## Mental.Health.Issues=No,
## Gender=Male} 1
## [2] {Title=Walmart shooting in suburban Denver,
## open.Close=Open,
## Injured=[0,2),
## Policeman.Killed=[0,5],
## Age=[35,70],
## Mental.Health.Issues=No,
## Gender=Male} 2
## [3] {Title=Edgewood businees park shooting,
## open.Close=Close,
## Injured=[2,4),
## Policeman.Killed=[0,5],
## Age=[35,70],
## Mental.Health.Issues=No,
## Gender=Male} 3
## [4] {Title=Las Vegas Strip mass shooting,
## open.Close=Open,
## Fatalities,
## Injured=[4,527],
## Total.victims,
## Policeman.Killed=[0,5],
## Age=[35,70],
## Mental.Health.Issues=No,
## Gender=Male} 4
image(trans)
itemFrequencyPlot(trans,topN =10)
vertical <- as(trans, "tidLists")
as(vertical, "matrix")[1:10, 1:4]
## 1 2 3 4
## Title=49th Street Elementary School FALSE FALSE FALSE FALSE
## Title=Accent Signage Systems in Minneapolis FALSE FALSE FALSE FALSE
## Title=Alabama highway random shooting FALSE FALSE FALSE FALSE
## Title=Albuquerque Auto Shop FALSE FALSE FALSE FALSE
## Title=Albuquerque, NM Family restaurant shooting FALSE FALSE FALSE FALSE
## Title=Albuquerque, NM House party shooting FALSE FALSE FALSE FALSE
## Title=Amish school shooting FALSE FALSE FALSE FALSE
## Title=Amnicola Training Center, Chattanooga FALSE FALSE FALSE FALSE
## Title=Annual motorcycle event in Newark FALSE FALSE FALSE FALSE
## Title=Appalachian School of Law FALSE FALSE FALSE FALSE
trans
## transactions in sparse format with
## 323 transactions (rows) and
## 339 items (columns)
its <- apriori(trans, parameter=list(target = "frequent"))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## NA 0.1 1 none FALSE TRUE 5 0.1 1
## maxlen target ext
## 10 frequent itemsets TRUE
##
## Algorithmic control:
## filter tree heap memopt load sort verbose
## 0.1 TRUE TRUE FALSE TRUE 2 TRUE
##
## Absolute minimum support count: 32
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[339 item(s), 323 transaction(s)] done [0.00s].
## sorting and recoding items ... [15 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 done [0.00s].
## sorting transactions ... done [0.00s].
## writing ... [247 set(s)] done [0.00s].
## creating S4 object ... done [0.00s].
its
## set of 247 itemsets
inspect(head(its, n = 10))
## items support transIdenticalToItemsets count
## [1] {Gender=Female} 0.1176471 0 38
## [2] {Total.victims} 0.1950464 0 63
## [3] {Fatalities} 0.2507740 0 81
## [4] {Injured=[2,4)} 0.2972136 0 96
## [5] {Age=[12,25)} 0.2972136 0 96
## [6] {Injured=[0,2)} 0.3034056 0 98
## [7] {Age=[25,35)} 0.3529412 0 114
## [8] {Age=[35,70]} 0.3498452 0 113
## [9] {open.Close=Open} 0.3622291 0 117
## [10] {Mental.Health.Issues=No} 0.3993808 0 129
ggplot(tibble(`Itemset Size` = factor(size(its))), aes(`Itemset Size`)) + geom_bar()
rules <- apriori(trans, parameter = list(support = 0.5, confidence = 0.95))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.95 0.1 1 none FALSE TRUE 5 0.5 1
## maxlen target ext
## 10 rules TRUE
##
## Algorithmic control:
## filter tree heap memopt load sort verbose
## 0.1 TRUE TRUE FALSE TRUE 2 TRUE
##
## Absolute minimum support count: 161
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[339 item(s), 323 transaction(s)] done [0.00s].
## sorting and recoding items ... [4 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 done [0.00s].
## writing ... [6 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
plot(rules,jitter = 1)
plot(rules, shading = "order", jitter=1)
plot(head(rules, n = 19), method = "graph")