Aim of the project

The aim of this project is to find common characteristics between music and mental health problems. I am using a survey data set from kaggle. Technique used for this project is association rules.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Data overview and manipulation

First we need to load the data. I am also deleting some variables I know will not be useful.

mxmh_survey_results <- read.csv("C:/Users/mateu/Downloads/mxmh_survey_results.csv")
names(mxmh_survey_results)
##  [1] "Timestamp"                    "Age"                         
##  [3] "Primary.streaming.service"    "Hours.per.day"               
##  [5] "While.working"                "Instrumentalist"             
##  [7] "Composer"                     "Fav.genre"                   
##  [9] "Exploratory"                  "Foreign.languages"           
## [11] "BPM"                          "Frequency..Classical."       
## [13] "Frequency..Country."          "Frequency..EDM."             
## [15] "Frequency..Folk."             "Frequency..Gospel."          
## [17] "Frequency..Hip.hop."          "Frequency..Jazz."            
## [19] "Frequency..K.pop."            "Frequency..Latin."           
## [21] "Frequency..Lofi."             "Frequency..Metal."           
## [23] "Frequency..Pop."              "Frequency..R.B."             
## [25] "Frequency..Rap."              "Frequency..Rock."            
## [27] "Frequency..Video.game.music." "Anxiety"                     
## [29] "Depression"                   "Insomnia"                    
## [31] "OCD"                          "Music.effects"               
## [33] "Permissions"
data <- mxmh_survey_results[,c(-1, -33)]

Now, I am looking for any NAs in the dataset.

colSums(is.na(data))
##                          Age    Primary.streaming.service 
##                            1                            0 
##                Hours.per.day                While.working 
##                            0                            0 
##              Instrumentalist                     Composer 
##                            0                            0 
##                    Fav.genre                  Exploratory 
##                            0                            0 
##            Foreign.languages                          BPM 
##                            0                          107 
##        Frequency..Classical.          Frequency..Country. 
##                            0                            0 
##              Frequency..EDM.             Frequency..Folk. 
##                            0                            0 
##           Frequency..Gospel.          Frequency..Hip.hop. 
##                            0                            0 
##             Frequency..Jazz.            Frequency..K.pop. 
##                            0                            0 
##            Frequency..Latin.             Frequency..Lofi. 
##                            0                            0 
##            Frequency..Metal.              Frequency..Pop. 
##                            0                            0 
##              Frequency..R.B.              Frequency..Rap. 
##                            0                            0 
##             Frequency..Rock. Frequency..Video.game.music. 
##                            0                            0 
##                      Anxiety                   Depression 
##                            0                            0 
##                     Insomnia                          OCD 
##                            0                            0 
##                Music.effects 
##                            0

It turns out there are a lot of NAs in BPM section. Let’s look into it.

summary(data$BPM)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
## 0.00e+00 1.00e+02 1.20e+02 1.59e+06 1.44e+02 1.00e+09      107

It turns out some people have put some ridiculous values. We will omit this column anyway so I am going to delete only the row with the age missing.

data <- data[!is.na(data$Age),]

Now we can check the structure of the data. We can see right now looking at Music.effects variable that some values have nothing in them but aren’t indicated as NA’s. I am going to explore this issue later on.

str(data)
## 'data.frame':    735 obs. of  31 variables:
##  $ Age                         : int  18 63 18 61 18 18 18 21 19 18 ...
##  $ Primary.streaming.service   : chr  "Spotify" "Pandora" "Spotify" "YouTube Music" ...
##  $ Hours.per.day               : num  3 1.5 4 2.5 4 5 3 1 6 1 ...
##  $ While.working               : chr  "Yes" "Yes" "No" "Yes" ...
##  $ Instrumentalist             : chr  "Yes" "No" "No" "No" ...
##  $ Composer                    : chr  "Yes" "No" "No" "Yes" ...
##  $ Fav.genre                   : chr  "Latin" "Rock" "Video game music" "Jazz" ...
##  $ Exploratory                 : chr  "Yes" "Yes" "No" "Yes" ...
##  $ Foreign.languages           : chr  "Yes" "No" "Yes" "Yes" ...
##  $ BPM                         : int  156 119 132 84 107 86 66 95 94 155 ...
##  $ Frequency..Classical.       : chr  "Rarely" "Sometimes" "Never" "Sometimes" ...
##  $ Frequency..Country.         : chr  "Never" "Never" "Never" "Never" ...
##  $ Frequency..EDM.             : chr  "Rarely" "Never" "Very frequently" "Never" ...
##  $ Frequency..Folk.            : chr  "Never" "Rarely" "Never" "Rarely" ...
##  $ Frequency..Gospel.          : chr  "Never" "Sometimes" "Never" "Sometimes" ...
##  $ Frequency..Hip.hop.         : chr  "Sometimes" "Rarely" "Rarely" "Never" ...
##  $ Frequency..Jazz.            : chr  "Never" "Very frequently" "Rarely" "Very frequently" ...
##  $ Frequency..K.pop.           : chr  "Very frequently" "Rarely" "Very frequently" "Sometimes" ...
##  $ Frequency..Latin.           : chr  "Very frequently" "Sometimes" "Never" "Very frequently" ...
##  $ Frequency..Lofi.            : chr  "Rarely" "Rarely" "Sometimes" "Sometimes" ...
##  $ Frequency..Metal.           : chr  "Never" "Never" "Sometimes" "Never" ...
##  $ Frequency..Pop.             : chr  "Very frequently" "Sometimes" "Rarely" "Sometimes" ...
##  $ Frequency..R.B.             : chr  "Sometimes" "Sometimes" "Never" "Sometimes" ...
##  $ Frequency..Rap.             : chr  "Very frequently" "Rarely" "Rarely" "Never" ...
##  $ Frequency..Rock.            : chr  "Never" "Very frequently" "Rarely" "Never" ...
##  $ Frequency..Video.game.music.: chr  "Sometimes" "Rarely" "Very frequently" "Never" ...
##  $ Anxiety                     : num  3 7 7 9 7 8 4 5 2 2 ...
##  $ Depression                  : num  0 2 7 7 2 8 8 3 0 2 ...
##  $ Insomnia                    : num  1 2 10 3 5 7 6 5 0 5 ...
##  $ OCD                         : num  0 1 2 3 9 7 0 3 0 1 ...
##  $ Music.effects               : chr  "" "" "No effect" "Improve" ...

Now I am looking at distribution of Age to think of a way to split it into a low number of levels.

hist(data$Age, labels = T)

This looks OK.

sum(data$Age<18)
## [1] 153
sum(data$Age>=18 & data$Age<20)
## [1] 146
sum(data$Age>=20 & data$Age<23)
## [1] 131
sum(data$Age>=23 & data$Age<=29)
## [1] 145
sum(data$Age>29)
## [1] 160

Now let’s explore the previous issue and check unique values for each column.

lapply(data, unique)
## $Age
##  [1] 18 63 61 21 19 17 16 15 14 20 26 23 37 36 24 22 42 25 32 29 41 31 33 30 43
## [26] 28 34 13 35 27 53 49 60 38 44 40 64 56 59 10 12 54 57 69 72 73 39 58 67 70
## [51] 55 48 71 74 51 65 80 50 68 46 89
## 
## $Primary.streaming.service
## [1] "Spotify"                           "Pandora"                          
## [3] "YouTube Music"                     "I do not use a streaming service."
## [5] "Apple Music"                       "Other streaming service"          
## [7] ""                                 
## 
## $Hours.per.day
##  [1]  3.00  1.50  4.00  2.50  5.00  1.00  6.00  8.00  2.00 12.00 24.00  0.50
## [13]  0.25  0.00  7.00 10.00  9.00  0.70  4.50 20.00 16.00 15.00 14.00 13.00
## [25]  0.10 11.00 18.00
## 
## $While.working
## [1] "Yes" "No"  ""   
## 
## $Instrumentalist
## [1] "Yes" "No"  ""   
## 
## $Composer
## [1] "Yes" "No"  ""   
## 
## $Fav.genre
##  [1] "Latin"            "Rock"             "Video game music" "Jazz"            
##  [5] "R&B"              "K pop"            "Country"          "EDM"             
##  [9] "Pop"              "Hip hop"          "Rap"              "Classical"       
## [13] "Metal"            "Folk"             "Lofi"             "Gospel"          
## 
## $Exploratory
## [1] "Yes" "No" 
## 
## $Foreign.languages
## [1] "Yes" "No"  ""   
## 
## $BPM
##   [1]       156       119       132        84       107        86        66
##   [8]        95        94       155        NA       125        88       148
##  [15]       103       120        99       118        79       169       136
##  [22]       101       126       183       142        75        89       140
##  [29]       161        80       130       147        77       115       157
##  [36]        90       128        96        91        55        85       160
##  [43]       108       170       174       127       165       113       167
##  [50]       110       150        93       109       175       162       189
##  [57]       121       200       105       193       149       134       100
##  [64]        98        78       117       122       179       166       144
##  [71]        61       185        92       194        60       190        87
##  [78]       171       114       141       146       164       145       112
##  [85]       111       172       180        76       129        81        52
##  [92]        97       143       158       104       135       220       138
##  [99]       139       178        62        72         0       208        20
## [106]       124       181       106       191        40       173       123
## [113]         4        73       137       133       102        82       116
## [120]       131       204       159        70       210         8 999999999
## [127]       153       192        56        63        68       624       218
## [134]       186       163       168
## 
## $Frequency..Classical.
## [1] "Rarely"          "Sometimes"       "Never"           "Very frequently"
## 
## $Frequency..Country.
## [1] "Never"           "Sometimes"       "Very frequently" "Rarely"         
## 
## $Frequency..EDM.
## [1] "Rarely"          "Never"           "Very frequently" "Sometimes"      
## 
## $Frequency..Folk.
## [1] "Never"           "Rarely"          "Sometimes"       "Very frequently"
## 
## $Frequency..Gospel.
## [1] "Never"           "Sometimes"       "Rarely"          "Very frequently"
## 
## $Frequency..Hip.hop.
## [1] "Sometimes"       "Rarely"          "Never"           "Very frequently"
## 
## $Frequency..Jazz.
## [1] "Never"           "Very frequently" "Rarely"          "Sometimes"      
## 
## $Frequency..K.pop.
## [1] "Very frequently" "Rarely"          "Sometimes"       "Never"          
## 
## $Frequency..Latin.
## [1] "Very frequently" "Sometimes"       "Never"           "Rarely"         
## 
## $Frequency..Lofi.
## [1] "Rarely"          "Sometimes"       "Very frequently" "Never"          
## 
## $Frequency..Metal.
## [1] "Never"           "Sometimes"       "Rarely"          "Very frequently"
## 
## $Frequency..Pop.
## [1] "Very frequently" "Sometimes"       "Rarely"          "Never"          
## 
## $Frequency..R.B.
## [1] "Sometimes"       "Never"           "Very frequently" "Rarely"         
## 
## $Frequency..Rap.
## [1] "Very frequently" "Rarely"          "Never"           "Sometimes"      
## 
## $Frequency..Rock.
## [1] "Never"           "Very frequently" "Rarely"          "Sometimes"      
## 
## $Frequency..Video.game.music.
## [1] "Sometimes"       "Rarely"          "Very frequently" "Never"          
## 
## $Anxiety
##  [1]  3.0  7.0  9.0  8.0  4.0  5.0  2.0  1.0  6.0 10.0  0.0  7.5
## 
## $Depression
##  [1]  0.0  2.0  7.0  8.0  3.0  1.0  4.0  5.0  9.0 10.0  6.0  3.5
## 
## $Insomnia
##  [1]  1.0  2.0 10.0  3.0  5.0  7.0  6.0  0.0  4.0  8.0  9.0  3.5
## 
## $OCD
##  [1]  0.0  1.0  2.0  3.0  9.0  7.0  4.0  6.0 10.0  5.0  8.0  8.5  5.5
## 
## $Music.effects
## [1] ""          "No effect" "Improve"   "Worsen"

As we can see we need to delete the values with empty spaces, but without BPM variable as it will not be taken into account anyway. This way we saved about 100 observations. (Now the number dropped from 735 to 718).

data3 <- data[,-10]

data2 <- data3 %>% 
  mutate_all(~ifelse(. == "", NA, .)) %>%
  mutate(Age = as.character(Age))

cleaned_data <- na.omit(data2)

Checking the result

lapply(cleaned_data, unique)
## $Age
##  [1] "18" "61" "21" "19" "17" "16" "15" "14" "20" "26" "23" "37" "36" "24" "22"
## [16] "25" "32" "29" "41" "31" "33" "30" "43" "28" "34" "13" "35" "27" "53" "49"
## [31] "42" "60" "38" "44" "40" "64" "56" "59" "10" "12" "54" "57" "69" "72" "73"
## [46] "39" "63" "58" "67" "70" "55" "48" "71" "74" "51" "65" "80" "50" "68" "46"
## [61] "89"
## 
## $Primary.streaming.service
## [1] "Spotify"                           "YouTube Music"                    
## [3] "I do not use a streaming service." "Apple Music"                      
## [5] "Other streaming service"           "Pandora"                          
## 
## $Hours.per.day
##  [1]  4.00  2.50  5.00  3.00  1.00  6.00  8.00  2.00 12.00 24.00  0.50  0.25
## [13]  7.00 10.00  1.50  9.00  0.70  4.50 20.00 16.00 15.00  0.00 14.00  0.10
## [25] 11.00 18.00
## 
## $While.working
## [1] "No"  "Yes"
## 
## $Instrumentalist
## [1] "No"  "Yes"
## 
## $Composer
## [1] "No"  "Yes"
## 
## $Fav.genre
##  [1] "Video game music" "Jazz"             "R&B"              "K pop"           
##  [5] "Rock"             "Country"          "EDM"              "Pop"             
##  [9] "Hip hop"          "Rap"              "Classical"        "Metal"           
## [13] "Folk"             "Lofi"             "Gospel"           "Latin"           
## 
## $Exploratory
## [1] "No"  "Yes"
## 
## $Foreign.languages
## [1] "Yes" "No" 
## 
## $Frequency..Classical.
## [1] "Never"           "Sometimes"       "Rarely"          "Very frequently"
## 
## $Frequency..Country.
## [1] "Never"           "Sometimes"       "Very frequently" "Rarely"         
## 
## $Frequency..EDM.
## [1] "Very frequently" "Never"           "Rarely"          "Sometimes"      
## 
## $Frequency..Folk.
## [1] "Never"           "Rarely"          "Sometimes"       "Very frequently"
## 
## $Frequency..Gospel.
## [1] "Never"           "Sometimes"       "Rarely"          "Very frequently"
## 
## $Frequency..Hip.hop.
## [1] "Rarely"          "Never"           "Very frequently" "Sometimes"      
## 
## $Frequency..Jazz.
## [1] "Rarely"          "Very frequently" "Never"           "Sometimes"      
## 
## $Frequency..K.pop.
## [1] "Very frequently" "Sometimes"       "Never"           "Rarely"         
## 
## $Frequency..Latin.
## [1] "Never"           "Very frequently" "Sometimes"       "Rarely"         
## 
## $Frequency..Lofi.
## [1] "Sometimes"       "Very frequently" "Rarely"          "Never"          
## 
## $Frequency..Metal.
## [1] "Sometimes"       "Never"           "Rarely"          "Very frequently"
## 
## $Frequency..Pop.
## [1] "Rarely"          "Sometimes"       "Very frequently" "Never"          
## 
## $Frequency..R.B.
## [1] "Never"           "Sometimes"       "Very frequently" "Rarely"         
## 
## $Frequency..Rap.
## [1] "Rarely"          "Never"           "Very frequently" "Sometimes"      
## 
## $Frequency..Rock.
## [1] "Rarely"          "Never"           "Very frequently" "Sometimes"      
## 
## $Frequency..Video.game.music.
## [1] "Very frequently" "Never"           "Rarely"          "Sometimes"      
## 
## $Anxiety
##  [1]  7.0  9.0  8.0  4.0  5.0  2.0  1.0  6.0 10.0  3.0  0.0  7.5
## 
## $Depression
##  [1]  7.0  2.0  8.0  3.0  0.0  1.0  4.0  5.0  9.0 10.0  6.0  3.5
## 
## $Insomnia
##  [1] 10.0  3.0  5.0  7.0  6.0  0.0  4.0  2.0  8.0  1.0  9.0  3.5
## 
## $OCD
##  [1]  2.0  3.0  9.0  7.0  0.0  1.0  4.0  6.0 10.0  5.0  8.0  8.5  5.5
## 
## $Music.effects
## [1] "No effect" "Improve"   "Worsen"

Creating levels for daily hours spent for listening to music, Anxiety, Depression, OCD and insomnia variables.

par(mfrow = c(2, 2))
hist(data$Anxiety, labels = T)
hist(data$Depression, labels = T)
hist(data$Insomnia, labels = T)
hist(data$OCD, labels = T)

hist(cleaned_data$Hours.per.day, labels = T)

summary(cleaned_data$Hours.per.day)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   2.000   3.000   3.578   5.000  24.000

For the hours variable I am going to use the quartiles. As for the mental health variables I am going to use one type of levels for the sake of similarity of results for each variable. Since I want to differentiate between high-low symptoms observations equal or below 6 are going to be classified as low, and those above as high.

cleaned_data$agecat<-ifelse(cleaned_data[,1]<18, "underage", ifelse(cleaned_data[,1]<20, "age: 18-19", ifelse(cleaned_data[,1]<23, "age: 20-22", ifelse(cleaned_data[,1]<29, "age: 23-28", ifelse(cleaned_data[,1]>=29, "age: older than 28", NA)))))

cleaned_data$anxietycat<-ifelse(cleaned_data[,26]<6, "low anxiety",ifelse(cleaned_data[,26]<11, "high anxiety", NA))

cleaned_data$depressioncat<-ifelse(cleaned_data[,27]<6, "low depression", ifelse(cleaned_data[,27]<11, "high depression", NA))

cleaned_data$insomniacat<-ifelse(cleaned_data[,28]<6, "low insomnia", ifelse(cleaned_data[,28]<11, "high insomnia", NA))

cleaned_data$ocdcat<-ifelse(cleaned_data[,29]<6, "low ocd", ifelse(cleaned_data[,29]<11, "high ocd", NA))

cleaned_data$hourscat<-ifelse(cleaned_data[,3]<2, "under 2 hours", ifelse(cleaned_data[,3]<3, "between 2-3 hours", ifelse(cleaned_data[,3]<5, "between 3-5 hours",ifelse(cleaned_data[,3]>=5, "equal or above 5 hours" , NA))))

Now I am transforming variables with two categories into booleans.

cleaned_data1 <- cleaned_data
columns_to_transform <- c(4:6, 8:9)

for (col in columns_to_transform) {
  cleaned_data1[, col] <- as.logical(cleaned_data1[, col] == "YES")
}

Association rules code

Now we are ready to start using the association rules algorithm. First I am choosing the variables I want to use for the algorithm.

data_AR<-cleaned_data1[, c(2, 4:25, 30:36)] 
write.csv(data_AR, file="data_AR.csv")

Changing the type of variables into character.

data_AR <-as.data.frame(data_AR)
data_AR1 <- data.frame(lapply(data_AR, as.character), stringsAsFactors = FALSE)
str(data_AR1)
## 'data.frame':    718 obs. of  30 variables:
##  $ Primary.streaming.service   : chr  "Spotify" "YouTube Music" "Spotify" "Spotify" ...
##  $ While.working               : chr  "FALSE" "FALSE" "FALSE" "FALSE" ...
##  $ Instrumentalist             : chr  "FALSE" "FALSE" "FALSE" "FALSE" ...
##  $ Composer                    : chr  "FALSE" "FALSE" "FALSE" "FALSE" ...
##  $ Fav.genre                   : chr  "Video game music" "Jazz" "R&B" "Jazz" ...
##  $ Exploratory                 : chr  "FALSE" "FALSE" "FALSE" "FALSE" ...
##  $ Foreign.languages           : chr  "FALSE" "FALSE" "FALSE" "FALSE" ...
##  $ Frequency..Classical.       : chr  "Never" "Sometimes" "Never" "Rarely" ...
##  $ Frequency..Country.         : chr  "Never" "Never" "Never" "Sometimes" ...
##  $ Frequency..EDM.             : chr  "Very frequently" "Never" "Rarely" "Never" ...
##  $ Frequency..Folk.            : chr  "Never" "Rarely" "Never" "Never" ...
##  $ Frequency..Gospel.          : chr  "Never" "Sometimes" "Rarely" "Never" ...
##  $ Frequency..Hip.hop.         : chr  "Rarely" "Never" "Very frequently" "Sometimes" ...
##  $ Frequency..Jazz.            : chr  "Rarely" "Very frequently" "Never" "Very frequently" ...
##  $ Frequency..K.pop.           : chr  "Very frequently" "Sometimes" "Very frequently" "Very frequently" ...
##  $ Frequency..Latin.           : chr  "Never" "Very frequently" "Sometimes" "Rarely" ...
##  $ Frequency..Lofi.            : chr  "Sometimes" "Sometimes" "Sometimes" "Very frequently" ...
##  $ Frequency..Metal.           : chr  "Sometimes" "Never" "Never" "Rarely" ...
##  $ Frequency..Pop.             : chr  "Rarely" "Sometimes" "Sometimes" "Very frequently" ...
##  $ Frequency..R.B.             : chr  "Never" "Sometimes" "Very frequently" "Very frequently" ...
##  $ Frequency..Rap.             : chr  "Rarely" "Never" "Very frequently" "Very frequently" ...
##  $ Frequency..Rock.            : chr  "Rarely" "Never" "Never" "Very frequently" ...
##  $ Frequency..Video.game.music.: chr  "Very frequently" "Never" "Rarely" "Never" ...
##  $ Music.effects               : chr  "No effect" "Improve" "Improve" "Improve" ...
##  $ agecat                      : chr  "age: 18-19" "age: older than 28" "age: 18-19" "age: 18-19" ...
##  $ anxietycat                  : chr  "high anxiety" "high anxiety" "high anxiety" "high anxiety" ...
##  $ depressioncat               : chr  "high depression" "high depression" "low depression" "high depression" ...
##  $ insomniacat                 : chr  "high insomnia" "low insomnia" "low insomnia" "high insomnia" ...
##  $ ocdcat                      : chr  "low ocd" "low ocd" "high ocd" "high ocd" ...
##  $ hourscat                    : chr  "between 3-5 hours" "between 2-3 hours" "between 3-5 hours" "equal or above 5 hours" ...

Reading the data as transactions using arules library.

library(arules)
## Warning: package 'arules' was built under R version 4.3.2
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## 
## Attaching package: 'arules'
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
trans1 <- as(data_AR1, "transactions")
## Warning: Column(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
## 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 not logical or factor.
## Applying default discretization (see '? discretizeDF').
length(trans1)
## [1] 718
colnames(trans1)
##   [1] "Primary.streaming.service=Apple Music"                      
##   [2] "Primary.streaming.service=I do not use a streaming service."
##   [3] "Primary.streaming.service=Other streaming service"          
##   [4] "Primary.streaming.service=Pandora"                          
##   [5] "Primary.streaming.service=Spotify"                          
##   [6] "Primary.streaming.service=YouTube Music"                    
##   [7] "While.working=FALSE"                                        
##   [8] "Instrumentalist=FALSE"                                      
##   [9] "Composer=FALSE"                                             
##  [10] "Fav.genre=Classical"                                        
##  [11] "Fav.genre=Country"                                          
##  [12] "Fav.genre=EDM"                                              
##  [13] "Fav.genre=Folk"                                             
##  [14] "Fav.genre=Gospel"                                           
##  [15] "Fav.genre=Hip hop"                                          
##  [16] "Fav.genre=Jazz"                                             
##  [17] "Fav.genre=K pop"                                            
##  [18] "Fav.genre=Latin"                                            
##  [19] "Fav.genre=Lofi"                                             
##  [20] "Fav.genre=Metal"                                            
##  [21] "Fav.genre=Pop"                                              
##  [22] "Fav.genre=R&B"                                              
##  [23] "Fav.genre=Rap"                                              
##  [24] "Fav.genre=Rock"                                             
##  [25] "Fav.genre=Video game music"                                 
##  [26] "Exploratory=FALSE"                                          
##  [27] "Foreign.languages=FALSE"                                    
##  [28] "Frequency..Classical.=Never"                                
##  [29] "Frequency..Classical.=Rarely"                               
##  [30] "Frequency..Classical.=Sometimes"                            
##  [31] "Frequency..Classical.=Very frequently"                      
##  [32] "Frequency..Country.=Never"                                  
##  [33] "Frequency..Country.=Rarely"                                 
##  [34] "Frequency..Country.=Sometimes"                              
##  [35] "Frequency..Country.=Very frequently"                        
##  [36] "Frequency..EDM.=Never"                                      
##  [37] "Frequency..EDM.=Rarely"                                     
##  [38] "Frequency..EDM.=Sometimes"                                  
##  [39] "Frequency..EDM.=Very frequently"                            
##  [40] "Frequency..Folk.=Never"                                     
##  [41] "Frequency..Folk.=Rarely"                                    
##  [42] "Frequency..Folk.=Sometimes"                                 
##  [43] "Frequency..Folk.=Very frequently"                           
##  [44] "Frequency..Gospel.=Never"                                   
##  [45] "Frequency..Gospel.=Rarely"                                  
##  [46] "Frequency..Gospel.=Sometimes"                               
##  [47] "Frequency..Gospel.=Very frequently"                         
##  [48] "Frequency..Hip.hop.=Never"                                  
##  [49] "Frequency..Hip.hop.=Rarely"                                 
##  [50] "Frequency..Hip.hop.=Sometimes"                              
##  [51] "Frequency..Hip.hop.=Very frequently"                        
##  [52] "Frequency..Jazz.=Never"                                     
##  [53] "Frequency..Jazz.=Rarely"                                    
##  [54] "Frequency..Jazz.=Sometimes"                                 
##  [55] "Frequency..Jazz.=Very frequently"                           
##  [56] "Frequency..K.pop.=Never"                                    
##  [57] "Frequency..K.pop.=Rarely"                                   
##  [58] "Frequency..K.pop.=Sometimes"                                
##  [59] "Frequency..K.pop.=Very frequently"                          
##  [60] "Frequency..Latin.=Never"                                    
##  [61] "Frequency..Latin.=Rarely"                                   
##  [62] "Frequency..Latin.=Sometimes"                                
##  [63] "Frequency..Latin.=Very frequently"                          
##  [64] "Frequency..Lofi.=Never"                                     
##  [65] "Frequency..Lofi.=Rarely"                                    
##  [66] "Frequency..Lofi.=Sometimes"                                 
##  [67] "Frequency..Lofi.=Very frequently"                           
##  [68] "Frequency..Metal.=Never"                                    
##  [69] "Frequency..Metal.=Rarely"                                   
##  [70] "Frequency..Metal.=Sometimes"                                
##  [71] "Frequency..Metal.=Very frequently"                          
##  [72] "Frequency..Pop.=Never"                                      
##  [73] "Frequency..Pop.=Rarely"                                     
##  [74] "Frequency..Pop.=Sometimes"                                  
##  [75] "Frequency..Pop.=Very frequently"                            
##  [76] "Frequency..R.B.=Never"                                      
##  [77] "Frequency..R.B.=Rarely"                                     
##  [78] "Frequency..R.B.=Sometimes"                                  
##  [79] "Frequency..R.B.=Very frequently"                            
##  [80] "Frequency..Rap.=Never"                                      
##  [81] "Frequency..Rap.=Rarely"                                     
##  [82] "Frequency..Rap.=Sometimes"                                  
##  [83] "Frequency..Rap.=Very frequently"                            
##  [84] "Frequency..Rock.=Never"                                     
##  [85] "Frequency..Rock.=Rarely"                                    
##  [86] "Frequency..Rock.=Sometimes"                                 
##  [87] "Frequency..Rock.=Very frequently"                           
##  [88] "Frequency..Video.game.music.=Never"                         
##  [89] "Frequency..Video.game.music.=Rarely"                        
##  [90] "Frequency..Video.game.music.=Sometimes"                     
##  [91] "Frequency..Video.game.music.=Very frequently"               
##  [92] "Music.effects=Improve"                                      
##  [93] "Music.effects=No effect"                                    
##  [94] "Music.effects=Worsen"                                       
##  [95] "agecat=age: 18-19"                                          
##  [96] "agecat=age: 20-22"                                          
##  [97] "agecat=age: 23-28"                                          
##  [98] "agecat=age: older than 28"                                  
##  [99] "agecat=underage"                                            
## [100] "anxietycat=high anxiety"                                    
## [101] "anxietycat=low anxiety"                                     
## [102] "depressioncat=high depression"                              
## [103] "depressioncat=low depression"                               
## [104] "insomniacat=high insomnia"                                  
## [105] "insomniacat=low insomnia"                                   
## [106] "ocdcat=high ocd"                                            
## [107] "ocdcat=low ocd"                                             
## [108] "hourscat=between 2-3 hours"                                 
## [109] "hourscat=between 3-5 hours"                                 
## [110] "hourscat=equal or above 5 hours"                            
## [111] "hourscat=under 2 hours"

Checking the results

Now we can look at the results of the algorithm.

rules.high_depression<-apriori(data=trans1, parameter=list(supp=0.001, conf=0.08), appearance=list(default="lhs", rhs="depressioncat=high depression"), control=list(verbose=F)) 

rules.high_depression.byconf<-sort(rules.high_depression, by="confidence", decreasing=TRUE)
inspect(head(rules.high_depression.byconf, n = 10))
##      lhs                                         rhs                                 support confidence    coverage     lift count
## [1]  {Primary.streaming.service=Apple Music,                                                                                      
##       Fav.genre=Latin}                        => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1
## [2]  {Fav.genre=Latin,                                                                                                            
##       Frequency..K.pop.=Sometimes}            => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1
## [3]  {Fav.genre=Latin,                                                                                                            
##       Frequency..Country.=Sometimes}          => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1
## [4]  {Fav.genre=Latin,                                                                                                            
##       agecat=age: 18-19}                      => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1
## [5]  {Fav.genre=Latin,                                                                                                            
##       Frequency..Lofi.=Sometimes}             => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1
## [6]  {Fav.genre=Latin,                                                                                                            
##       Frequency..R.B.=Sometimes}              => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1
## [7]  {Fav.genre=Latin,                                                                                                            
##       Frequency..Rap.=Rarely}                 => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1
## [8]  {Fav.genre=Latin,                                                                                                            
##       Frequency..Hip.hop.=Sometimes}          => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1
## [9]  {Fav.genre=Latin,                                                                                                            
##       Frequency..Rock.=Sometimes}             => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1
## [10] {Fav.genre=Latin,                                                                                                            
##       Frequency..Video.game.music.=Never}     => {depressioncat=high depression} 0.001392758          1 0.001392758 2.130564     1

Here we can observe top 10 baskets (by confidence) where high depression category is on the right hand side. In other words, we can see what might cause the high depression in this data set. We can see Lofi and Gosper genres as favorite are popular in this case.

rules.high_ocd<-apriori(data=trans1, parameter=list(supp=0.001, conf=0.08), appearance=list(default="lhs", rhs="ocdcat=high ocd"), control=list(verbose=F)) 

rules.high_ocd.byconf<-sort(rules.high_ocd, by="confidence", decreasing=TRUE)
inspect(head(rules.high_ocd.byconf, n = 10))
##      lhs                                      rhs                   support confidence    coverage     lift count
## [1]  {Fav.genre=Lofi,                                                                                            
##       Frequency..Gospel.=Very frequently}  => {ocdcat=high ocd} 0.001392758          1 0.001392758 5.698413     1
## [2]  {Fav.genre=Lofi,                                                                                            
##       Frequency..Latin.=Very frequently}   => {ocdcat=high ocd} 0.001392758          1 0.001392758 5.698413     1
## [3]  {Fav.genre=Lofi,                                                                                            
##       Frequency..Country.=Very frequently} => {ocdcat=high ocd} 0.002785515          1 0.002785515 5.698413     2
## [4]  {Fav.genre=Lofi,                                                                                            
##       Frequency..K.pop.=Very frequently}   => {ocdcat=high ocd} 0.001392758          1 0.001392758 5.698413     1
## [5]  {Fav.genre=Lofi,                                                                                            
##       Frequency..Folk.=Very frequently}    => {ocdcat=high ocd} 0.001392758          1 0.001392758 5.698413     1
## [6]  {Fav.genre=Lofi,                                                                                            
##       Frequency..Rap.=Very frequently}     => {ocdcat=high ocd} 0.001392758          1 0.001392758 5.698413     1
## [7]  {Fav.genre=Lofi,                                                                                            
##       agecat=age: 20-22}                   => {ocdcat=high ocd} 0.004178273          1 0.004178273 5.698413     3
## [8]  {Fav.genre=Lofi,                                                                                            
##       Frequency..Pop.=Rarely}              => {ocdcat=high ocd} 0.001392758          1 0.001392758 5.698413     1
## [9]  {Fav.genre=Lofi,                                                                                            
##       Frequency..Video.game.music.=Never}  => {ocdcat=high ocd} 0.001392758          1 0.001392758 5.698413     1
## [10] {Frequency..Gospel.=Very frequently,                                                                        
##       Frequency..Jazz.=Very frequently}    => {ocdcat=high ocd} 0.001392758          1 0.001392758 5.698413     1

When it comes to high OCD Lofi as favorite genre is in every case of this top 10. We can also obvserve high frequency of multiple different genres.

rules.high_insomnia<-apriori(data=trans1, parameter=list(supp=0.001, conf=0.08), appearance=list(default="lhs", rhs="insomniacat=high insomnia"), control=list(verbose=F)) 

rules.high_insomnia.byconf<-sort(rules.high_insomnia, by="confidence", decreasing=TRUE)
inspect(head(rules.high_insomnia.byconf, n = 10))
##      lhs                                         rhs                             support confidence    coverage     lift count
## [1]  {Fav.genre=Latin,                                                                                                        
##       Frequency..Gospel.=Sometimes}           => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1
## [2]  {Fav.genre=Latin,                                                                                                        
##       Frequency..Hip.hop.=Very frequently}    => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1
## [3]  {Fav.genre=Latin,                                                                                                        
##       Frequency..Rap.=Very frequently}        => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1
## [4]  {Fav.genre=Latin,                                                                                                        
##       Frequency..Metal.=Sometimes}            => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1
## [5]  {Fav.genre=Latin,                                                                                                        
##       Frequency..Pop.=Rarely}                 => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1
## [6]  {Fav.genre=Latin,                                                                                                        
##       agecat=underage}                        => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1
## [7]  {Fav.genre=Latin,                                                                                                        
##       Music.effects=No effect}                => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1
## [8]  {Fav.genre=Latin,                                                                                                        
##       Frequency..K.pop.=Rarely}               => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1
## [9]  {Fav.genre=Latin,                                                                                                        
##       Frequency..Video.game.music.=Sometimes} => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1
## [10] {Fav.genre=Latin,                                                                                                        
##       Frequency..Lofi.=Rarely}                => {insomniacat=high insomnia} 0.001392758          1 0.001392758 3.191111     1

This is interesting. While lofi was popular when it came to OCD, Latin music is popular with high insomnia. We should also note that each basket found has count of 1 only.

rules.high_anxiety<-apriori(data=trans1, parameter=list(supp=0.001, conf=0.08), appearance=list(default="lhs", rhs="anxietycat=high anxiety"), control=list(verbose=F)) 

rules.high_anxiety.byconf<-sort(rules.high_anxiety, by="confidence", decreasing=TRUE)
inspect(head(rules.high_anxiety.byconf, n = 10))
##      lhs                                         rhs                           support confidence    coverage     lift count
## [1]  {Primary.streaming.service=Apple Music,                                                                                
##       Fav.genre=Latin}                        => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1
## [2]  {Fav.genre=Latin,                                                                                                      
##       Frequency..K.pop.=Sometimes}            => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1
## [3]  {Fav.genre=Latin,                                                                                                      
##       Frequency..Country.=Sometimes}          => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1
## [4]  {Fav.genre=Latin,                                                                                                      
##       agecat=age: 18-19}                      => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1
## [5]  {Fav.genre=Latin,                                                                                                      
##       Frequency..Lofi.=Sometimes}             => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1
## [6]  {Fav.genre=Latin,                                                                                                      
##       Frequency..R.B.=Sometimes}              => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1
## [7]  {Fav.genre=Latin,                                                                                                      
##       Frequency..Rap.=Rarely}                 => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1
## [8]  {Fav.genre=Latin,                                                                                                      
##       Frequency..Hip.hop.=Sometimes}          => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1
## [9]  {Fav.genre=Latin,                                                                                                      
##       Frequency..Rock.=Sometimes}             => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1
## [10] {Fav.genre=Latin,                                                                                                      
##       Frequency..Video.game.music.=Never}     => {anxietycat=high anxiety} 0.001392758          1 0.001392758 1.654378     1

Here, with high anxiety, latin music as favorite is popular as well. Also, count is really low. It might be due to the fact that not many people indicated they feel high level of anxiety or insomnia. 9 Overall from the Unsupervised Learning technique we can conclude that the type of favorite genre might be the the indicator of mental health problems. Other than that, we could observe second or third indicator in the basket, however they varied a lot.