R version 4.1.2 (2021-11-01) -- "Bird Hippie" Copyright (C) 2021 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > #Discovering Association rules and data mining in Antimicrobial Resistance in Intensive Care Unit > #install.packages("arulesViz") > library(arulesViz) > #import csv from location > data <- read.csv(file.choose()) > #preview file > summary(data) Sex Age Specimen_Type Organism_group DrugName_group Inter Length:6086 Min. :20.00 Length:6086 Length:6086 Length:6086 Length:6086 Class :character 1st Qu.:63.00 Class :character Class :character Class :character Class :character Mode :character Median :73.00 Mode :character Mode :character Mode :character Mode :character Mean :69.08 3rd Qu.:82.00 Max. :94.00 > #convert to factor > data$Sex<- factor(data$Sex) > data$Specimen_Type<- factor(data$Specimen_Type) > data$Organism_group<- factor(data$Organism_group) > data$DrugName_group<- factor(data$DrugName_group) > data$Inter<- factor(data$Inter) > summary(data) Sex Age Specimen_Type Organism_group DrugName_group Inter F:2369 Min. :20.00 resp :4671 Abaumannii :2383 Colistin : 446 R:4321 M:3717 1st Qu.:63.00 Blood : 510 Kpneumoniae:2132 Imipenem : 445 S:1765 Median :73.00 Ur : 446 Paeruginosa:1571 Meropenem : 440 Mean :69.08 pyon : 238 Amikacin : 433 3rd Qu.:82.00 kath : 159 Gentamicin : 430 Max. :94.00 asc : 39 Ceftazidime: 421 (Other): 23 (Other) :3471 > #remove Age > data.noAge = subset(data, select = -c(2)) > summary(data.noAge) Sex Specimen_Type Organism_group DrugName_group Inter F:2369 resp :4671 Abaumannii :2383 Colistin : 446 R:4321 M:3717 Blood : 510 Kpneumoniae:2132 Imipenem : 445 S:1765 Ur : 446 Paeruginosa:1571 Meropenem : 440 pyon : 238 Amikacin : 433 kath : 159 Gentamicin : 430 asc : 39 Ceftazidime: 421 (Other): 23 (Other) :3471 > #Rules RHS = (Inter=S) > rules<- apriori(data.noAge, parameter = list(support = 0.001, confidence = 0.30, minlen = 5), appearance = list(default="lhs", rhs="Inter=S")) Apriori Parameter specification: confidence minval smax arem aval originalSupport maxtime support minlen maxlen target ext 0.3 0.1 1 none FALSE TRUE 5 0.001 5 10 rules TRUE Algorithmic control: filter tree heap memopt load sort verbose 0.1 TRUE TRUE FALSE TRUE 2 TRUE Absolute minimum support count: 6 > inspect(rules.sorted[1:15]) lhs rhs support confidence coverage lift count [1] {Sex=F, Specimen_Type=resp, Organism_group=Kpneumoniae, DrugName_group=CeftazidAvibactam} => {Inter=S} 0.001314492 1.0000000 0.001314492 3.448159 8 [2] {Sex=M, Specimen_Type=resp, Organism_group=Kpneumoniae, DrugName_group=CeftazidAvibactam} => {Inter=S} 0.002300361 1.0000000 0.002300361 3.448159 14 [3] {Sex=F, Specimen_Type=Ur, Organism_group=Paeruginosa, DrugName_group=Colistin} => {Inter=S} 0.001150181 1.0000000 0.001150181 3.448159 7 [4] {Sex=F, Specimen_Type=resp, Organism_group=Paeruginosa, DrugName_group=Colistin} => {Inter=S} 0.007065396 1.0000000 0.007065396 3.448159 43 [5] {Sex=M, Specimen_Type=resp, Organism_group=Paeruginosa, DrugName_group=Colistin} => {Inter=S} 0.012651988 1.0000000 0.012651988 3.448159 77 [6] {Sex=F, Specimen_Type=resp, Organism_group=Kpneumoniae, DrugName_group=Colistin} => {Inter=S} 0.004600723 0.8750000 0.005257969 3.017139 28 [7] {Sex=M, Specimen_Type=resp, Organism_group=Abaumannii, DrugName_group=Tigecycline} => {Inter=S} 0.005586592 0.8500000 0.006572461 2.930935 34 [8] {Sex=M, Specimen_Type=resp, Organism_group=Paeruginosa, DrugName_group=PiperaciTazoba} => {Inter=S} 0.007065396 0.7678571 0.009201446 2.647693 43 [9] {Sex=M, Specimen_Type=resp, Organism_group=Kpneumoniae, DrugName_group=Colistin} => {Inter=S} 0.006572461 0.7272727 0.009037134 2.507752 40 [10] {Sex=M, Specimen_Type=resp, Organism_group=Paeruginosa, DrugName_group=Doripenem} => {Inter=S} 0.006572461 0.6779661 0.009694381 2.337735 40 [11] {Sex=M, Specimen_Type=resp, Organism_group=Paeruginosa, DrugName_group=Aztreonam} => {Inter=S} 0.006901084 0.6774194 0.010187315 2.335849 42 [12] {Sex=F, Specimen_Type=resp, Organism_group=Paeruginosa, DrugName_group=Aztreonam} => {Inter=S} 0.002957608 0.6666667 0.004436411 2.298772 18 [13] {Sex=M, Specimen_Type=resp, Organism_group=Kpneumoniae, DrugName_group=Gentamicin} => {Inter=S} 0.005915215 0.6545455 0.009037134 2.256977 36 [14] {Sex=M, Specimen_Type=resp, Organism_group=Paeruginosa, DrugName_group=Ceftazidime} => {Inter=S} 0.006736773 0.6307692 0.010680250 2.174992 41 [15] {Sex=M, Specimen_Type=resp, Organism_group=Paeruginosa, DrugName_group=Gentamicin} => {Inter=S} 0.006736773 0.6212121 0.010844561 2.142038 41 > plot(rules) To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter. > plot(rules@quality) >