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. > #Using Association rules in Antimicrobial Resistance in stone disease patients - ICIMTH 2022 - Warning message: replacing previous import ‘dplyr::collapse’ by ‘glue::collapse’ when loading ‘statsExpressions’ > #install.packages("arulesViz") > #install.packages("arules") > library(arulesViz) Loading required package: arules Loading required package: Matrix Attaching package: ‘arules’ The following objects are masked from ‘package:base’: abbreviate, write > library(arules) > #import csv from location > data <- read.csv(file.choose()) > summary(data) Sex Specimen.Type Gram DrugName_group Inter Length:5156 Length:5156 Length:5156 Length:5156 Length:5156 Class :character Class :character Class :character Class :character Class :character Mode :character Mode :character Mode :character Mode :character Mode :character > #convert to factor > data$Sex<- factor(data$Sex) > data$Specimen.Type<- factor(data$Specimen.Type) > data$Gram<- factor(data$Gram) > data$DrugName_group<- factor(data$DrugName_group) > data$Inter<- factor(data$Inter) > summary(data) Sex Specimen.Type Gram DrugName_group Inter F:3081 Blood: 354 Negative:4165 Ampicillin : 322 R:1568 M:2075 pus : 193 Positive: 991 Norfloxacin : 264 S:3588 Ur :4609 Amikacin : 261 Colistin : 261 AmoxicillinClavulanic: 257 Gentamicin : 257 (Other) :3534 > #Rules LHS Inter=R > rules_R <- apriori(data, parameter = list(support = 0.01, confidence = 0.35, minlen = 3), appearance = list(default="lhs", rhs="Inter=R")) Apriori Parameter specification: confidence minval smax arem aval originalSupport maxtime support minlen maxlen target ext 0.35 0.1 1 none FALSE TRUE 5 0.01 3 10 rules TRUE Algorithmic control: filter tree heap memopt load sort verbose 0.1 TRUE TRUE FALSE TRUE 2 TRUE Absolute minimum support count: 51 set item appearances ...[1 item(s)] done [0.00s]. set transactions ...[48 item(s), 5156 transaction(s)] done [0.00s]. sorting and recoding items ... [36 item(s)] done [0.00s]. creating transaction tree ... done [0.00s]. checking subsets of size 1 2 3 4 5 done [0.00s]. writing ... [49 rule(s)] done [0.00s]. creating S4 object ... done [0.00s]. > rules.sorted_R <- sort(rules_R , by = "confidence", decreasing=T) > inspect(rules.sorted_R) lhs rhs support confidence coverage lift count [1] {Sex=M, Specimen.Type=Ur, Gram=Negative, DrugName_group=Ampicillin} => {Inter=R} 0.01144298 0.8194444 0.01396431 2.694551 59 [2] {Sex=M, Gram=Negative, DrugName_group=Ampicillin} => {Inter=R} 0.01299457 0.8170732 0.01590380 2.686753 67 [3] {Gram=Negative, DrugName_group=Ampicillin} => {Inter=R} 0.03200155 0.7568807 0.04228084 2.488825 165 [4] {Specimen.Type=Ur, Gram=Negative, DrugName_group=Ampicillin} => {Inter=R} 0.02889837 0.7525253 0.03840186 2.474503 149 [5] {Sex=F, Gram=Negative, DrugName_group=Ampicillin} => {Inter=R} 0.01900698 0.7205882 0.02637704 2.369485 98 [6] {Sex=F, Specimen.Type=Ur, Gram=Negative, DrugName_group=Ampicillin} => {Inter=R} 0.01745539 0.7142857 0.02443755 2.348761 90 [7] {Specimen.Type=Ur, DrugName_group=Tetracycline} => {Inter=R} 0.01241272 0.6530612 0.01900698 2.147439 64 [8] {Specimen.Type=Ur, DrugName_group=AmpicillinSulbactam} => {Inter=R} 0.01027929 0.6309524 0.01629170 2.074739 53 [9] {Specimen.Type=Ur, Gram=Negative, DrugName_group=AmpicillinSulbactam} => {Inter=R} 0.01027929 0.6309524 0.01629170 2.074739 53 [10] {Specimen.Type=Ur, DrugName_group=Ciprofloxacin} => {Inter=R} 0.01745539 0.6293706 0.02773468 2.069538 90 [11] {Gram=Negative, DrugName_group=AmpicillinSulbactam} => {Inter=R} 0.01280062 0.6285714 0.02036462 2.066910 66 [12] {Sex=F, DrugName_group=Ampicillin} => {Inter=R} 0.02346780 0.6269430 0.03743212 2.061555 121 [13] {Sex=F, Specimen.Type=Ur, DrugName_group=Ampicillin} => {Inter=R} 0.02114042 0.6228571 0.03394104 2.048120 109 [14] {Gram=Negative, DrugName_group=Ciprofloxacin} => {Inter=R} 0.01823119 0.6184211 0.02948022 2.033532 94 [15] {Gram=Positive, DrugName_group=Tetracycline} => {Inter=R} 0.01027929 0.6162791 0.01667960 2.026489 53 [16] {Specimen.Type=Ur, Gram=Negative, DrugName_group=Ciprofloxacin} => {Inter=R} 0.01493406 0.6160000 0.02424360 2.025571 77 [17] {Specimen.Type=Ur, DrugName_group=Ampicillin} => {Inter=R} 0.03394104 0.6013746 0.05643910 1.977479 175 [18] {Sex=F, DrugName_group=Ciprofloxacin} => {Inter=R} 0.01241272 0.5981308 0.02075252 1.966813 64 [19] {Sex=M, DrugName_group=Ampicillin} => {Inter=R} 0.01454616 0.5813953 0.02501939 1.911782 75 [20] {Sex=M, Specimen.Type=Ur, DrugName_group=Ampicillin} => {Inter=R} 0.01280062 0.5689655 0.02249806 1.870910 66 [21] {Specimen.Type=pus, Gram=Negative} => {Inter=R} 0.01493406 0.5620438 0.02657099 1.848149 77 [22] {Sex=M, DrugName_group=Norfloxacin} => {Inter=R} 0.01008534 0.5000000 0.02017067 1.644133 52 [23] {Sex=M, Specimen.Type=Blood, Gram=Negative} => {Inter=R} 0.01532196 0.5000000 0.03064391 1.644133 79 [24] {Gram=Negative, DrugName_group=TrimethoprimSulfamethoxazole} => {Inter=R} 0.02055857 0.4732143 0.04344453 1.556054 106 [25] {Specimen.Type=Ur, DrugName_group=Norfloxacin} => {Inter=R} 0.02385570 0.4730769 0.05042669 1.555602 123 [26] {Gram=Negative, DrugName_group=Cefotaxime} => {Inter=R} 0.01163693 0.4724409 0.02463150 1.553511 60 [27] {Sex=M, Specimen.Type=Blood} => {Inter=R} 0.01551590 0.4678363 0.03316524 1.538370 80 [28] {Sex=F, DrugName_group=Norfloxacin} => {Inter=R} 0.01435221 0.4625000 0.03103181 1.520823 74 [29] {Sex=F, Specimen.Type=Ur, DrugName_group=Norfloxacin} => {Inter=R} 0.01415826 0.4591195 0.03083786 1.509707 73 [30] {Specimen.Type=Ur, Gram=Negative, DrugName_group=TrimethoprimSulfamethoxazole} => {Inter=R} 0.01784329 0.4577114 0.03898371 1.505077 92 [31] {Sex=F, Specimen.Type=pus} => {Inter=R} 0.01086113 0.4480000 0.02424360 1.473143 56 [32] {Sex=F, Gram=Negative, DrugName_group=TrimethoprimSulfamethoxazole} => {Inter=R} 0.01183088 0.4420290 0.02676493 1.453509 61 [33] {Gram=Negative, DrugName_group=Norfloxacin} => {Inter=R} 0.01667960 0.4410256 0.03782002 1.450209 86 [34] {Sex=F, Specimen.Type=Ur, Gram=Negative, DrugName_group=TrimethoprimSulfamethoxazole} => {Inter=R} 0.01086113 0.4409449 0.02463150 1.449944 56 [35] {Specimen.Type=Ur, Gram=Negative, DrugName_group=Norfloxacin} => {Inter=R} 0.01629170 0.4375000 0.03723817 1.438616 84 [36] {Specimen.Type=Ur, DrugName_group=TrimethoprimSulfamethoxazole} => {Inter=R} 0.01803724 0.4266055 0.04228084 1.402792 93 [37] {Gram=Negative, DrugName_group=Cefuroxime} => {Inter=R} 0.01629170 0.4221106 0.03859581 1.388011 84 [38] {Sex=F, Specimen.Type=Ur, DrugName_group=TrimethoprimSulfamethoxazole} => {Inter=R} 0.01086113 0.4179104 0.02598914 1.374200 56 [39] {Sex=F, DrugName_group=TrimethoprimSulfamethoxazole} => {Inter=R} 0.01183088 0.4178082 0.02831652 1.373864 61 [40] {Specimen.Type=Ur, DrugName_group=Cefuroxime} => {Inter=R} 0.01454616 0.4143646 0.03510473 1.362541 75 [41] {Specimen.Type=Ur, Gram=Negative, DrugName_group=Cefuroxime} => {Inter=R} 0.01454616 0.4143646 0.03510473 1.362541 75 [42] {Sex=M, Gram=Negative} => {Inter=R} 0.12490303 0.3995037 0.31264546 1.313674 644 [43] {Gram=Negative, DrugName_group=AmoxicillinClavulanic} => {Inter=R} 0.01377036 0.3837838 0.03588053 1.261983 71 [44] {Sex=M, Specimen.Type=Ur, Gram=Negative} => {Inter=R} 0.10279286 0.3796562 0.27075252 1.248410 530 [45] {Specimen.Type=Ur, Gram=Negative, DrugName_group=AmoxicillinClavulanic} => {Inter=R} 0.01202483 0.3668639 0.03277735 1.206346 62 [46] {Specimen.Type=Blood, Gram=Negative} => {Inter=R} 0.02191621 0.3633441 0.06031808 1.194772 113 [47] {Gram=Negative, DrugName_group=Cefepime} => {Inter=R} 0.01027929 0.3630137 0.02831652 1.193685 53 [48] {Specimen.Type=Ur, Gram=Negative, DrugName_group=Nitrofurantoin} => {Inter=R} 0.01027929 0.3581081 0.02870442 1.177554 53 [49] {Gram=Negative, DrugName_group=Nitrofurantoin} => {Inter=R} 0.01027929 0.3557047 0.02889837 1.169651 53