library(arules)
## Warning: package 'arules' was built under R version 4.5.3
## Loading required package: Matrix
##
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
##
## abbreviate, write
# 1. Load & Factorize
df <- read.csv("survey.csv")
cols <- c("treatment", "family_history", "care_options", "seek_help", "obs_consequence", "work_interfere")
df_arm <- as.data.frame(lapply(df[cols], as.factor))
# 2. Run Apriori
rules <- apriori(df_arm,
parameter = list(supp = 0.05, conf = 0.4, minlen = 2),
appearance = list(rhs = "obs_consequence=Yes", default = "lhs"),
control = list(verbose = FALSE))
# 3. Sort & Summary
rules_lift <- sort(rules, by = "lift", decreasing = TRUE)
inspect(head(rules_lift, 5))
summary(rules)
## set of 0 rules