library(readxl)
mydata <- read_xlsx("./NLB_anketa_pociscena.xlsx")
## New names:
## • `` -> `...13`
## • `` -> `...31`
## • `` -> `...38`
## • `` -> `...45`
## • `` -> `...52`
## • `` -> `...58`
## • `` -> `...64`
## • `` -> `...75`
## • `` -> `...91`
## • `` -> `...106`
mydata <- as.data.frame(mydata)
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
mydata <- mydata %>%
mutate(ID = 1:nrow(.)) %>%
select(ID, everything()) #adding a column ID
mydata <- mydata[-1,] #removing questions
mydata <- mydata[mydata$Q1 >= 16 & mydata$Q1 <= 27, ] #removing all aged below 16 and above 27
head(mydata)
## ID Q1 Q3 Q4a Q4b Q4c Q4d Q4e Q4f Q4g Q4h Q4i Q4j ...13 Q5 Q6a
## 2 2 23 1 5 3 4 5 3 3 4 5 5 5 4.2 2 -2
## 3 3 23 1 4 2 5 4 4 4 5 5 4 4 4.0999999999999996 2 -2
## 4 4 22 1 5 5 5 5 5 5 5 5 4 4 4.8 2 -2
## 5 5 23 1 4 5 4 5 2 4 5 5 3 4 4.0999999999999996 1 0
## 6 6 22 1 5 4 5 5 3 5 5 5 4 4 4.5 2 -2
## 7 7 23 3 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 2 -2
## Q6b Q6c Q6d Q6e Q6f Q6g Q8a Q8b Q8c Q8d Q8e Q8f Q8g Q8h Q8i ...31 Q32_2a
## 2 -2 -2 -2 -2 -2 -2 5 5 5 5 3 4 5 5 -1 4.625 4
## 3 -2 -2 -2 -2 -2 -2 5 4 5 5 2 2 4 4 -1 3.875 6
## 4 -2 -2 -2 -2 -2 -2 5 5 5 5 4 5 5 5 -1 4.875 3
## 5 0 0 0 0 0 1 4 5 5 5 3 3 4 5 -1 4.25 6
## 6 -2 -2 -2 -2 -2 -2 5 5 5 5 4 4 4 5 -1 4.625 6
## 7 -2 -2 -2 -2 -2 -2 5 5 5 5 4 4 4 5 -1 4.625 6
## Q32_2b Q32_2c Q32_2d Q32_2e Q32_2f ...38 Q9a Q9b Q9c Q9d Q9e Q9f
## 2 4 4 3 5 6 4.333333333333333 5 5 5 5 4 6
## 3 6 5 6 5 6 5.666666666666667 4 6 6 6 4 6
## 4 4 4 3 5 4 3.8333333333333335 5 5 5 5 5 5
## 5 5 6 6 5 6 5.666666666666667 6 4 6 6 4 6
## 6 6 4 6 6 6 5.666666666666667 4 6 6 6 6 6
## 7 6 4 6 5 6 5.5 5 6 6 6 3 6
## ...45 Q32_3a Q32_3b Q32_3c Q32_3d Q32_3e Q32_3f
## 2 5 4 4 4 3 5 6
## 3 5.333333333333333 4 6 6 6 5 6
## 4 5 3 3 2 6 5 4
## 5 5.333333333333333 6 6 4 6 4 6
## 6 5.666666666666667 3 6 6 6 6 6
## 7 5.333333333333333 2 6 6 6 5 6
## ...52 Q31_2a Q31_2b Q31_2c Q31_2d Q31_2e ...58 Q11a Q11b Q11c
## 2 4.333333333333333 3 4 3 3 2 3 4 4 5
## 3 5.5 2 4 2 4 4 3.2 5 5 4
## 4 3.8333333333333335 4 4 4 4 2 3.6 4 3 3
## 5 5.333333333333333 3 4 2 4 3 3.2 4 4 4
## 6 5.5 4 4 3 2 3 3.2 4 5 3
## 7 5.166666666666667 3 4 2 4 5 3.6 4 4 3
## Q11d Q11e ...64 Q13a Q13b Q13c Q13d Q13e Q13f Q13g Q13h Q13i
## 2 5 4 4.4000000000000004 1 5 3 1 2 1 2 1 4
## 3 4 4 4.4000000000000004 2 5 4 4 4 1 3 2 3
## 4 2 4 3.2 2 4 4 2 2 2 1 2 3
## 5 2 4 3.6 2 5 4 4 4 1 2 1 4
## 6 3 3 3.6 3 5 5 2 3 2 2 1 5
## 7 3 4 3.6 2 5 4 1 3 1 1 1 4
## Q13j ...75 Q14a Q14b Q14c Q14d Q14e Q14f Q14g Q14h Q16a Q16b
## 2 -1 2.2222222222222223 1 0 0 0 1 1 1 0 3 4
## 3 -1 3.1111111111111112 0 1 0 1 1 1 1 0 4 4
## 4 -1 2.4444444444444446 1 1 0 1 1 1 1 0 5 5
## 5 -1 3 1 1 0 1 0 1 0 0 3 4
## 6 -1 3.1111111111111112 1 0 0 1 0 0 0 0 2 1
## 7 -1 2.4444444444444446 0 1 0 0 0 1 0 0 3 3
## Q16c Q16d Q16e Q16f Q16g ...91 Q17a Q17b Q17c Q17d Q17e Q17f
## 2 3 4 5 5 4 4 1 0 1 1 1 1
## 3 4 5 4 5 4 4.2857142857142856 0 0 1 0 1 0
## 4 5 5 4 5 4 4.7142857142857144 1 0 1 0 1 0
## 5 4 3 5 5 4 4 1 0 0 1 1 0
## 6 2 2 5 5 1 2.5714285714285716 1 0 0 0 0 0
## 7 2 3 5 4 4 3.4285714285714284 0 1 0 0 0 0
## Q17g Q17h Q17i Q18a Q18b Q18c Q18d Q18e ...106 Q19 Q20 Q21 Q22 Q23 Q24 Q25
## 2 1 1 0 4 3 4 4 4 3.8 2 5 4 3 3 2 7
## 3 1 1 0 4 2 4 2 4 3.2 2 5 5 -2 2 1 7
## 4 1 1 0 2 2 3 2 3 2.4 1 5 4 2 2 2 7
## 5 1 1 0 3 4 4 3 4 3.6 2 5 4 1 3 1 7
## 6 0 0 0 5 5 5 5 5 5 2 3 4 4 2 2 7
## 7 1 0 0 4 4 4 4 4 4 2 5 5 -2 1 3 7
## Q26 Q27 Q28 Q29a Q29b Q29c Q29d Q29e Q29f Q29g Q29h Q29i Q29j Q29k Q29l Q29m
## 2 -2 6 1 0 0 0 0 0 0 0 0 0 1 0 0 0
## 3 -2 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0
## 4 -2 3 1 1 0 0 0 0 0 0 0 0 1 0 0 0
## 5 -2 3 2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
## 6 -2 1 2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
## 7 -2 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0
columns_to_delete <- c("...13","...31","...38","...45","...52","...58","...64","...75","...91","...106")
mydata <- mydata[, !(names(mydata) %in% columns_to_delete)]
head(mydata)
## ID Q1 Q3 Q4a Q4b Q4c Q4d Q4e Q4f Q4g Q4h Q4i Q4j Q5 Q6a Q6b Q6c Q6d Q6e Q6f
## 2 2 23 1 5 3 4 5 3 3 4 5 5 5 2 -2 -2 -2 -2 -2 -2
## 3 3 23 1 4 2 5 4 4 4 5 5 4 4 2 -2 -2 -2 -2 -2 -2
## 4 4 22 1 5 5 5 5 5 5 5 5 4 4 2 -2 -2 -2 -2 -2 -2
## 5 5 23 1 4 5 4 5 2 4 5 5 3 4 1 0 0 0 0 0 0
## 6 6 22 1 5 4 5 5 3 5 5 5 4 4 2 -2 -2 -2 -2 -2 -2
## 7 7 23 3 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 2 -2 -2 -2 -2 -2 -2
## Q6g Q8a Q8b Q8c Q8d Q8e Q8f Q8g Q8h Q8i Q32_2a Q32_2b Q32_2c Q32_2d Q32_2e
## 2 -2 5 5 5 5 3 4 5 5 -1 4 4 4 3 5
## 3 -2 5 4 5 5 2 2 4 4 -1 6 6 5 6 5
## 4 -2 5 5 5 5 4 5 5 5 -1 3 4 4 3 5
## 5 1 4 5 5 5 3 3 4 5 -1 6 5 6 6 5
## 6 -2 5 5 5 5 4 4 4 5 -1 6 6 4 6 6
## 7 -2 5 5 5 5 4 4 4 5 -1 6 6 4 6 5
## Q32_2f Q9a Q9b Q9c Q9d Q9e Q9f Q32_3a Q32_3b Q32_3c Q32_3d Q32_3e Q32_3f
## 2 6 5 5 5 5 4 6 4 4 4 3 5 6
## 3 6 4 6 6 6 4 6 4 6 6 6 5 6
## 4 4 5 5 5 5 5 5 3 3 2 6 5 4
## 5 6 6 4 6 6 4 6 6 6 4 6 4 6
## 6 6 4 6 6 6 6 6 3 6 6 6 6 6
## 7 6 5 6 6 6 3 6 2 6 6 6 5 6
## Q31_2a Q31_2b Q31_2c Q31_2d Q31_2e Q11a Q11b Q11c Q11d Q11e Q13a Q13b Q13c
## 2 3 4 3 3 2 4 4 5 5 4 1 5 3
## 3 2 4 2 4 4 5 5 4 4 4 2 5 4
## 4 4 4 4 4 2 4 3 3 2 4 2 4 4
## 5 3 4 2 4 3 4 4 4 2 4 2 5 4
## 6 4 4 3 2 3 4 5 3 3 3 3 5 5
## 7 3 4 2 4 5 4 4 3 3 4 2 5 4
## Q13d Q13e Q13f Q13g Q13h Q13i Q13j Q14a Q14b Q14c Q14d Q14e Q14f Q14g Q14h
## 2 1 2 1 2 1 4 -1 1 0 0 0 1 1 1 0
## 3 4 4 1 3 2 3 -1 0 1 0 1 1 1 1 0
## 4 2 2 2 1 2 3 -1 1 1 0 1 1 1 1 0
## 5 4 4 1 2 1 4 -1 1 1 0 1 0 1 0 0
## 6 2 3 2 2 1 5 -1 1 0 0 1 0 0 0 0
## 7 1 3 1 1 1 4 -1 0 1 0 0 0 1 0 0
## Q16a Q16b Q16c Q16d Q16e Q16f Q16g Q17a Q17b Q17c Q17d Q17e Q17f Q17g Q17h
## 2 3 4 3 4 5 5 4 1 0 1 1 1 1 1 1
## 3 4 4 4 5 4 5 4 0 0 1 0 1 0 1 1
## 4 5 5 5 5 4 5 4 1 0 1 0 1 0 1 1
## 5 3 4 4 3 5 5 4 1 0 0 1 1 0 1 1
## 6 2 1 2 2 5 5 1 1 0 0 0 0 0 0 0
## 7 3 3 2 3 5 4 4 0 1 0 0 0 0 1 0
## Q17i Q18a Q18b Q18c Q18d Q18e Q19 Q20 Q21 Q22 Q23 Q24 Q25 Q26 Q27 Q28 Q29a
## 2 0 4 3 4 4 4 2 5 4 3 3 2 7 -2 6 1 0
## 3 0 4 2 4 2 4 2 5 5 -2 2 1 7 -2 1 1 0
## 4 0 2 2 3 2 3 1 5 4 2 2 2 7 -2 3 1 1
## 5 0 3 4 4 3 4 2 5 4 1 3 1 7 -2 3 2 -2
## 6 0 5 5 5 5 5 2 3 4 4 2 2 7 -2 1 2 -2
## 7 0 4 4 4 4 4 2 5 5 -2 1 3 7 -2 1 1 0
## Q29b Q29c Q29d Q29e Q29f Q29g Q29h Q29i Q29j Q29k Q29l Q29m
## 2 0 0 0 0 0 0 0 0 1 0 0 0
## 3 0 0 0 0 0 0 0 0 1 0 0 0
## 4 0 0 0 0 0 0 0 0 1 0 0 0
## 5 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
## 6 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
## 7 0 0 0 0 0 0 0 0 1 0 0 0
#install.packages("naniar")
library(dplyr)
library(naniar)
mydata <- replace(mydata, mydata == -2, NA)
mydata <- replace(mydata, mydata == -1, NA)
head(mydata)
## ID Q1 Q3 Q4a Q4b Q4c Q4d Q4e Q4f Q4g Q4h Q4i Q4j Q5 Q6a Q6b Q6c
## 2 2 23 1 5 3 4 5 3 3 4 5 5 5 2 <NA> <NA> <NA>
## 3 3 23 1 4 2 5 4 4 4 5 5 4 4 2 <NA> <NA> <NA>
## 4 4 22 1 5 5 5 5 5 5 5 5 4 4 2 <NA> <NA> <NA>
## 5 5 23 1 4 5 4 5 2 4 5 5 3 4 1 0 0 0
## 6 6 22 1 5 4 5 5 3 5 5 5 4 4 2 <NA> <NA> <NA>
## 7 7 23 3 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 2 <NA> <NA> <NA>
## Q6d Q6e Q6f Q6g Q8a Q8b Q8c Q8d Q8e Q8f Q8g Q8h Q8i Q32_2a Q32_2b Q32_2c
## 2 <NA> <NA> <NA> <NA> 5 5 5 5 3 4 5 5 <NA> 4 4 4
## 3 <NA> <NA> <NA> <NA> 5 4 5 5 2 2 4 4 <NA> 6 6 5
## 4 <NA> <NA> <NA> <NA> 5 5 5 5 4 5 5 5 <NA> 3 4 4
## 5 0 0 0 1 4 5 5 5 3 3 4 5 <NA> 6 5 6
## 6 <NA> <NA> <NA> <NA> 5 5 5 5 4 4 4 5 <NA> 6 6 4
## 7 <NA> <NA> <NA> <NA> 5 5 5 5 4 4 4 5 <NA> 6 6 4
## Q32_2d Q32_2e Q32_2f Q9a Q9b Q9c Q9d Q9e Q9f Q32_3a Q32_3b Q32_3c Q32_3d
## 2 3 5 6 5 5 5 5 4 6 4 4 4 3
## 3 6 5 6 4 6 6 6 4 6 4 6 6 6
## 4 3 5 4 5 5 5 5 5 5 3 3 2 6
## 5 6 5 6 6 4 6 6 4 6 6 6 4 6
## 6 6 6 6 4 6 6 6 6 6 3 6 6 6
## 7 6 5 6 5 6 6 6 3 6 2 6 6 6
## Q32_3e Q32_3f Q31_2a Q31_2b Q31_2c Q31_2d Q31_2e Q11a Q11b Q11c Q11d Q11e
## 2 5 6 3 4 3 3 2 4 4 5 5 4
## 3 5 6 2 4 2 4 4 5 5 4 4 4
## 4 5 4 4 4 4 4 2 4 3 3 2 4
## 5 4 6 3 4 2 4 3 4 4 4 2 4
## 6 6 6 4 4 3 2 3 4 5 3 3 3
## 7 5 6 3 4 2 4 5 4 4 3 3 4
## Q13a Q13b Q13c Q13d Q13e Q13f Q13g Q13h Q13i Q13j Q14a Q14b Q14c Q14d Q14e
## 2 1 5 3 1 2 1 2 1 4 <NA> 1 0 0 0 1
## 3 2 5 4 4 4 1 3 2 3 <NA> 0 1 0 1 1
## 4 2 4 4 2 2 2 1 2 3 <NA> 1 1 0 1 1
## 5 2 5 4 4 4 1 2 1 4 <NA> 1 1 0 1 0
## 6 3 5 5 2 3 2 2 1 5 <NA> 1 0 0 1 0
## 7 2 5 4 1 3 1 1 1 4 <NA> 0 1 0 0 0
## Q14f Q14g Q14h Q16a Q16b Q16c Q16d Q16e Q16f Q16g Q17a Q17b Q17c Q17d Q17e
## 2 1 1 0 3 4 3 4 5 5 4 1 0 1 1 1
## 3 1 1 0 4 4 4 5 4 5 4 0 0 1 0 1
## 4 1 1 0 5 5 5 5 4 5 4 1 0 1 0 1
## 5 1 0 0 3 4 4 3 5 5 4 1 0 0 1 1
## 6 0 0 0 2 1 2 2 5 5 1 1 0 0 0 0
## 7 1 0 0 3 3 2 3 5 4 4 0 1 0 0 0
## Q17f Q17g Q17h Q17i Q18a Q18b Q18c Q18d Q18e Q19 Q20 Q21 Q22 Q23 Q24 Q25
## 2 1 1 1 0 4 3 4 4 4 2 5 4 3 3 2 7
## 3 0 1 1 0 4 2 4 2 4 2 5 5 <NA> 2 1 7
## 4 0 1 1 0 2 2 3 2 3 1 5 4 2 2 2 7
## 5 0 1 1 0 3 4 4 3 4 2 5 4 1 3 1 7
## 6 0 0 0 0 5 5 5 5 5 2 3 4 4 2 2 7
## 7 0 1 0 0 4 4 4 4 4 2 5 5 <NA> 1 3 7
## Q26 Q27 Q28 Q29a Q29b Q29c Q29d Q29e Q29f Q29g Q29h Q29i Q29j Q29k Q29l Q29m
## 2 <NA> 6 1 0 0 0 0 0 0 0 0 0 1 0 0 0
## 3 <NA> 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0
## 4 <NA> 3 1 1 0 0 0 0 0 0 0 0 1 0 0 0
## 5 <NA> 3 2 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 6 <NA> 1 2 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 7 <NA> 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0
likert <- mydata %>%
select(ID, Q4a, Q4b, Q4c, Q4d, Q4e, Q4f, Q4g, Q4h, Q4i, Q4j, Q8a, Q8b, Q8c, Q8d, Q8e, Q8f, Q8g, Q8h, Q31_2a, Q31_2b, Q31_2c, Q31_2d, Q31_2e, Q11a, Q11b, Q11c, Q11d, Q11e, Q13a, Q13b, Q13c, Q13d, Q13e, Q13f, Q13g, Q13h, Q13i, Q16a, Q16b, Q16c, Q16d, Q16e, Q16f, Q16g, Q18a, Q18b, Q18c, Q18d, Q18e) #Creating a new data frame with only likert variables (non positioning)
head(likert)
## ID Q4a Q4b Q4c Q4d Q4e Q4f Q4g Q4h Q4i Q4j Q8a Q8b Q8c Q8d Q8e Q8f
## 2 2 5 3 4 5 3 3 4 5 5 5 5 5 5 5 3 4
## 3 3 4 2 5 4 4 4 5 5 4 4 5 4 5 5 2 2
## 4 4 5 5 5 5 5 5 5 5 4 4 5 5 5 5 4 5
## 5 5 4 5 4 5 2 4 5 5 3 4 4 5 5 5 3 3
## 6 6 5 4 5 5 3 5 5 5 4 4 5 5 5 5 4 4
## 7 7 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 5 5 5 5 4 4
## Q8g Q8h Q31_2a Q31_2b Q31_2c Q31_2d Q31_2e Q11a Q11b Q11c Q11d Q11e Q13a Q13b
## 2 5 5 3 4 3 3 2 4 4 5 5 4 1 5
## 3 4 4 2 4 2 4 4 5 5 4 4 4 2 5
## 4 5 5 4 4 4 4 2 4 3 3 2 4 2 4
## 5 4 5 3 4 2 4 3 4 4 4 2 4 2 5
## 6 4 5 4 4 3 2 3 4 5 3 3 3 3 5
## 7 4 5 3 4 2 4 5 4 4 3 3 4 2 5
## Q13c Q13d Q13e Q13f Q13g Q13h Q13i Q16a Q16b Q16c Q16d Q16e Q16f Q16g Q18a
## 2 3 1 2 1 2 1 4 3 4 3 4 5 5 4 4
## 3 4 4 4 1 3 2 3 4 4 4 5 4 5 4 4
## 4 4 2 2 2 1 2 3 5 5 5 5 4 5 4 2
## 5 4 4 4 1 2 1 4 3 4 4 3 5 5 4 3
## 6 5 2 3 2 2 1 5 2 1 2 2 5 5 1 5
## 7 4 1 3 1 1 1 4 3 3 2 3 5 4 4 4
## Q18b Q18c Q18d Q18e
## 2 3 4 4 4
## 3 2 4 2 4
## 4 2 3 2 3
## 5 4 4 3 4
## 6 5 5 5 5
## 7 4 4 4 4
for (col in names(likert)) {
likert[[col]] <- as.numeric(as.character(likert[[col]]))} #turning all columns into numeric
#summary(likert, na.rm = TRUE) #it does the same as below but more segregated
library(psych)
#describe(likert[,-1]) #without ID
library(pastecs)
##
## Attaching package: 'pastecs'
## The following objects are masked from 'package:dplyr':
##
## first, last
stat_desc <- stat.desc(likert)
stat_desc <- data.frame(t(stat_desc))
head(stat_desc[order(-stat_desc$coef.var), c("mean", "coef.var")],15)[-1, ] #showing units with lowest coef.var (if you wanna show the highest, remove - from stat_desc$coef.var and remove the -1 in the end)
## mean coef.var
## Q13f 2.263736 0.5348559
## Q13g 1.540984 0.4892333
## Q13h 1.524590 0.4754770
## Q13a 2.327869 0.4595994
## Q11d 2.666667 0.4091585
## Q13d 2.765027 0.4073552
## Q4e 3.053846 0.3831614
## Q13e 2.775956 0.3755609
## Q18b 3.114754 0.3566448
## Q16g 3.213115 0.3473384
## Q13i 3.196721 0.3399351
## Q8e 3.311475 0.3344526
## Q8f 3.579235 0.3291484
## Q31_2c 2.879781 0.3166675
library(tidyr)
##
## Attaching package: 'tidyr'
## The following object is masked from 'package:pastecs':
##
## extract
set2 <- likert %>%
select(ID, Q4b, Q31_2b, Q8a, Q8b)
#Saving standardized cluster variables
set2 <- replace_na(set2, list(Q4b = mean(likert$Q4b, na.rm = TRUE)))
set2_std <- as.data.frame(scale(set2[c("Q8a","Q8b","Q31_2b","Q4b")]))
library(Hmisc)
##
## Attaching package: 'Hmisc'
## The following object is masked from 'package:psych':
##
## describe
## The following objects are masked from 'package:dplyr':
##
## src, summarize
## The following objects are masked from 'package:base':
##
## format.pval, units
rcorr(as.matrix(set2[,c("Q8a","Q8b","Q31_2b","Q4b")]),
type = "pearson")
## Q8a Q8b Q31_2b Q4b
## Q8a 1.00 0.14 0.04 0.09
## Q8b 0.14 1.00 -0.02 0.07
## Q31_2b 0.04 -0.02 1.00 0.14
## Q4b 0.09 0.07 0.14 1.00
##
## n= 183
##
##
## P
## Q8a Q8b Q31_2b Q4b
## Q8a 0.0583 0.6198 0.2377
## Q8b 0.0583 0.8120 0.3682
## Q31_2b 0.6198 0.8120 0.0526
## Q4b 0.2377 0.3682 0.0526
set2$Dissimilarity <- sqrt(set2_std$Q4b^2 + set2_std$Q8a^2 + set2_std$Q8b^2 + set2_std$Q31_2b^2) #finding outliers
head(set2[order(-set2$Dissimilarity),c("ID","Dissimilarity")], 10) #Finding units with highest value of dissimilarity
## ID Dissimilarity
## 70 70 4.272065
## 138 138 4.209983
## 83 83 4.109327
## 159 159 3.992752
## 168 168 3.840493
## 169 169 3.761105
## 139 139 3.664830
## 37 37 3.573128
## 172 172 3.562610
## 28 28 3.519695
REMOVE?
#install.packages("factoextra")
library(factoextra)
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
Distances_2 <- get_dist(set2_std,
method = "euclidian") #Eucidian distances
Distances2_2 <- Distances_2^2
fviz_dist(Distances2_2,
gradient = list(low = "darkred",
mid = "grey95",
high = "blue")) #Matrix of distances
library(factoextra)
get_clust_tendency(set2_std,
n = nrow(set2_std)-1,
graph = FALSE) #Hopkins statistics
## $hopkins_stat
## [1] 0.6840727
##
## $plot
## NULL
library(dplyr)
library(factoextra)
WARD2 <- set2_std %>%
get_dist(method = "euclidean") %>%
hclust(method = "ward.D2")
fviz_dend(WARD2)
## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
## of ggplot2 3.3.4.
## ℹ The deprecated feature was likely used in the factoextra package.
## Please report the issue at <https://github.com/kassambara/factoextra/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
# Plot dendrograms for different values of k
fviz_dend(WARD2,
k = 3,
cex = 0.5,
palette = "default",
color_labels_by_k = TRUE,
rect = TRUE)
fviz_dend(WARD2,
k = 5,
cex = 0.5,
palette = "default",
color_labels_by_k = TRUE,
rect = TRUE)
set2$ClusterWard_3 <- cutree(WARD2,
k = 3) #number of groups
head(set2[c("ID","ClusterWard_3")])
## ID ClusterWard_3
## 2 2 1
## 3 3 2
## 4 4 1
## 5 5 2
## 6 6 1
## 7 7 1
Leaders_initial2_3 <- aggregate(set2_std,
by = list(set2$ClusterWard_3),
FUN = mean)
Leaders_initial2_3
## Group.1 Q8a Q8b Q31_2b Q4b
## 1 1 0.71170349 0.7509328 0.4707089 0.4946990
## 2 2 -0.47324096 0.3321268 -0.5254198 -0.4920103
## 3 3 -0.08389084 -1.2877259 0.2508997 0.1768774
library(factoextra)
kmeans_set2_3 <- hkmeans(set2_std,
k = 3,
hc.metric = "euclidean",
hc.method = "ward.D2")
kmeans_set2_3
## Hierarchical K-means clustering with 3 clusters of sizes 61, 57, 65
##
## Cluster means:
## Q8a Q8b Q31_2b Q4b
## 1 0.6363467 0.7509328 0.4815715 0.46635093
## 2 -0.5248538 0.6476089 -0.6743334 -0.52051701
## 3 -0.1369305 -1.2726247 0.1394023 0.01880096
##
## Clustering vector:
## 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
## 1 3 1 1 1 1 1 2 3 3 3 2 2 3 3 3 2 1 1 3
## 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
## 2 2 2 2 2 1 2 1 3 3 3 3 1 3 1 2 2 1 3 2
## 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62
## 2 2 1 1 1 2 1 3 2 3 1 2 3 3 1 1 3 2 3 1
## 63 64 65 66 67 68 69 70 71 72 73 75 76 77 78 79 80 81 82 83
## 2 1 3 3 3 1 3 3 1 1 3 1 1 2 3 3 1 1 3 3
## 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
## 2 3 3 3 3 1 2 2 1 1 3 1 3 1 2 1 3 3 2 3
## 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
## 1 3 2 1 3 3 1 2 3 1 3 3 1 3 1 2 2 2 1 3
## 124 125 126 127 128 129 130 132 133 134 135 136 137 138 139 140 141 142 143 144
## 3 1 3 3 2 1 1 1 2 3 2 1 3 2 2 3 1 3 2 2
## 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
## 2 1 2 2 1 1 2 3 2 1 1 2 3 1 3 1 2 1 1 3
## 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
## 1 2 3 3 2 2 2 2 2 3 2 2 3 2 3 2 1 2 1 3
## 185 186 188
## 2 1 3
##
## Within cluster sum of squares by cluster:
## [1] 80.96854 201.04776 170.72407
## (between_SS / total_SS = 37.8 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault" "data"
## [11] "hclust"
library(factoextra)
fviz_cluster(kmeans_set2_3,
palette = "Set1",
repel = TRUE,
ggtheme = theme_bw())
set2$ClusterWard_5 <- cutree(WARD2,
k = 5) #number of groups
head(set2[c("ID","ClusterWard_5")])
## ID ClusterWard_5
## 2 2 1
## 3 3 2
## 4 4 1
## 5 5 3
## 6 6 1
## 7 7 1
Leaders_initial2_5 <- aggregate(set2_std,
by = list(set2$ClusterWard_5),
FUN = mean)
Leaders_initial2_5
## Group.1 Q8a Q8b Q31_2b Q4b
## 1 1 0.71170349 0.75093277 0.470708943 0.49469899
## 2 2 0.08077465 0.05805531 0.002981867 -2.13009635
## 3 3 -1.33130418 0.57246433 0.174540851 0.01949063
## 4 4 0.28267188 0.20124998 -1.808681009 -0.05329295
## 5 5 -0.08389084 -1.28772592 0.250899704 0.17687745
library(factoextra)
kmeans_set2_5 <- hkmeans(set2_std,
k = 5,
hc.metric = "euclidean",
hc.method = "ward.D2")
kmeans_set2_5
## Hierarchical K-means clustering with 5 clusters of sizes 56, 16, 29, 27, 55
##
## Cluster means:
## Q8a Q8b Q31_2b Q4b
## 1 0.71170349 0.7509328 0.4707089 0.4946990
## 2 0.13710758 0.1374475 0.1394023 -2.1558375
## 3 -1.45458913 0.4801531 0.3793140 0.1026570
## 4 -0.02604928 0.4600953 -1.7932200 -0.1562035
## 5 0.01522360 -1.2836074 0.1604854 0.1460126
##
## Clustering vector:
## 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
## 1 2 1 3 1 1 1 4 5 5 5 3 3 5 5 5 3 1 1 5
## 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
## 2 4 4 4 4 1 4 1 5 5 5 5 2 5 1 4 3 1 4 4
## 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62
## 3 3 1 1 1 3 1 5 4 5 1 2 5 5 1 1 5 4 5 1
## 63 64 65 66 67 68 69 70 71 72 73 75 76 77 78 79 80 81 82 83
## 2 1 5 3 5 1 5 3 3 1 5 1 1 4 5 5 1 1 5 3
## 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
## 2 5 5 5 5 1 3 3 1 1 5 1 2 1 2 1 5 5 4 5
## 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
## 1 5 3 1 5 5 1 3 2 1 5 3 1 5 1 4 4 4 1 5
## 124 125 126 127 128 129 130 132 133 134 135 136 137 138 139 140 141 142 143 144
## 5 1 5 5 4 1 1 1 4 5 3 1 5 3 4 4 1 5 4 4
## 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
## 3 1 3 2 1 1 3 5 4 1 4 3 5 1 5 1 3 1 1 5
## 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
## 1 3 2 5 2 4 2 4 4 5 3 2 5 3 5 2 1 2 1 5
## 185 186 188
## 3 3 5
##
## Within cluster sum of squares by cluster:
## [1] 62.25813 37.91567 62.41125 54.32753 90.79474
## (between_SS / total_SS = 57.7 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault" "data"
## [11] "hclust"
library(factoextra)
fviz_cluster(kmeans_set2_5,
palette = "Set1",
repel = TRUE,
ggtheme = theme_bw())
set2$Clusterk_means <- kmeans_set2_5$cluster
#head(set2[c("ID","ClusterWard","Clusterk_means")])
fit2 <- aov(cbind(Q4b, Q31_2b, Q8a, Q8b) ~ as.factor(Clusterk_means),
data = set2)
summary(fit2) #Checking significance of cluster variables
## Response Q4b :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 66.242 16.5605 43.728 < 2.2e-16 ***
## Residuals 178 67.411 0.3787
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q31_2b :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 78.186 19.5465 60.86 < 2.2e-16 ***
## Residuals 178 57.169 0.3212
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q8a :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 38.358 9.5894 43.586 < 2.2e-16 ***
## Residuals 178 39.162 0.2200
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q8b :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 35.004 8.7509 127.46 < 2.2e-16 ***
## Residuals 178 12.220 0.0687
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(ggplot2)
library(tidyr)
Centroids <- kmeans_set2_5$centers
Figure <- as.data.frame(Centroids)
Figure$id <- 1:nrow(Figure)
Figure <- pivot_longer(Figure, cols = c(Q4b, Q31_2b, Q8a, Q8b))
Figure$Groups <- factor(Figure$id,
levels = c(1, 2, 3, 4, 5),
labels = c("1", "2", "3", "4", "5"))
Figure$nameFactor <- factor(Figure$name,
levels = c("Q4b", "Q31_2b","Q8a", "Q8b"),
labels = c("Q4b", "Q31_2b","Q8a", "Q8b"))
ggplot(Figure, aes(x = nameFactor, y = value)) +
geom_hline(yintercept = 0) +
theme_bw() +
geom_point(aes(shape = Groups, col = Groups), size = 5) +
geom_line(aes(group = id), linewidth = 1) +
ylab("Averages") +
xlab("Cluster variables") +
ylim(-2.5, 2.5)
# Descriptive statistics:
set2 <- set2 %>%
mutate(Q1=mydata$Q1, Q11a=mydata$Q11a, Q13b=mydata$Q13b, Q13c=mydata$Q13c, Q13i=mydata$Q13i, Q14a=mydata$Q14a, Q14b=mydata$Q14b, Q14d=mydata$Q14d, Q14e=mydata$Q14e, Q14f=mydata$Q14f, Q14g=mydata$Q14g, Q16a=mydata$Q16a, Q16g=mydata$Q16g, Q18c=mydata$Q18c, Q18d=mydata$Q18d, Q19=mydata$Q19, Q20=mydata$Q20, Q21=mydata$Q21, Q23=mydata$Q23, Q24=mydata$Q24, Q25=mydata$Q25, Q27=mydata$Q27, Q28=mydata$Q28) #Creating a new data frame with only descriptive variables
#AGE
set2$Q1 <- as.numeric(as.character(set2$Q1))
aggregate(set2$Q1,
by = list(set2$Clusterk_means),
FUN = "mean") #mean ali median?
## Group.1 x
## 1 1 23.14286
## 2 2 24.18750
## 3 3 22.48276
## 4 4 22.55556
## 5 5 22.18182
fit_Q1 <- aov(Q1 ~ as.factor(Clusterk_means),
data = set2)
summary(fit_Q1)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 62.5 15.637 2.302 0.0604 .
## Residuals 178 1209.4 6.794
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Vizualna podoba oglasov vpliva na moje prepoznavanje blagovne znamke (almost good)
set2$Q11a <- as.numeric(as.character(set2$Q11a))
aggregate(set2$Q11a,
by = list(set2$Clusterk_means),
FUN = "mean") #mean ali median?
## Group.1 x
## 1 1 4.125000
## 2 2 3.875000
## 3 3 4.034483
## 4 4 3.703704
## 5 5 3.763636
fit_Q11a <- aov(Q11a ~ as.factor(Clusterk_means),
data = set2)
summary(fit_Q11a)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 5.37 1.3433 2.166 0.0747 .
## Residuals 178 110.40 0.6202
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Kako pogosto uporabljam socialna omrežja (no good)
set2$Q13b <- as.numeric(as.character(set2$Q13b))
aggregate(set2$Q13b,
by = list(set2$Clusterk_means),
FUN = "mean")
## Group.1 x
## 1 1 4.482143
## 2 2 4.187500
## 3 3 4.482759
## 4 4 4.444444
## 5 5 4.345455
fit_Q13b <- aov(Q13b ~ as.factor(Clusterk_means),
data = set2)
summary(fit_Q13b)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 1.50 0.3746 0.999 0.41
## Residuals 178 66.76 0.3751
#Kako pogosto uporabljam Youtube (no good)
set2$Q13c <- as.numeric(as.character(set2$Q13c))
aggregate(set2$Q13c,
by = list(set2$Clusterk_means),
FUN = "mean")
## Group.1 x
## 1 1 3.428571
## 2 2 3.437500
## 3 3 3.482759
## 4 4 3.629630
## 5 5 3.436364
fit_Q13c <- aov(Q13c ~ as.factor(Clusterk_means),
data = set2)
summary(fit_Q13c)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 0.87 0.217 0.207 0.934
## Residuals 178 186.72 1.049
#Kako pogosto uporabljam Email (no good)
set2$Q13i <- as.numeric(as.character(set2$Q13i))
aggregate(set2$Q13i,
by = list(set2$Clusterk_means),
FUN = "mean")
## Group.1 x
## 1 1 3.250000
## 2 2 3.312500
## 3 3 2.931034
## 4 4 3.333333
## 5 5 3.181818
fit_Q13i <- aov(Q13i ~ as.factor(Clusterk_means),
data = set2)
summary(fit_Q13i)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 2.94 0.7342 0.616 0.651
## Residuals 178 211.98 1.1909
#I think i'm financially literate (almost good)
set2$Q16a <- as.numeric(as.character(set2$Q16a))
aggregate(set2$Q16a,
by = list(set2$Clusterk_means),
FUN = "mean")
## Group.1 x
## 1 1 3.535714
## 2 2 3.562500
## 3 3 3.068966
## 4 4 3.555556
## 5 5 3.163636
fit_Q16a <- aov(Q16a ~ as.factor(Clusterk_means),
data = set2)
summary(fit_Q16a)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 7.99 1.9976 2.118 0.0805 .
## Residuals 178 167.92 0.9434
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#I like to look at or listen to educational content on the topic of personal finance (GOOD)
set2$Q16g <- as.numeric(as.character(set2$Q16g))
aggregate(set2$Q16g,
by = list(set2$Clusterk_means),
FUN = "mean")
## Group.1 x
## 1 1 3.589286
## 2 2 3.062500
## 3 3 3.068966
## 4 4 2.851852
## 5 5 3.127273
fit_Q16g <- aov(Q16g ~ as.factor(Clusterk_means),
data = set2)
summary(fit_Q16g)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(Clusterk_means) 4 12.82 3.205 2.667 0.0339 *
## Residuals 178 213.87 1.202
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Who would I listen to: Family (GOOD)
set2$Q14aF <- factor(set2$Q14a,
levels = c(1, 0),
labels = c("Yes", "No"))
chisq_results_Q14a <- fisher.test(set2$Q14aF,
as.factor(set2$Clusterk_means))
chisq_results_Q14a
##
## Fisher's Exact Test for Count Data
##
## data: set2$Q14aF and as.factor(set2$Clusterk_means)
## p-value = 0.005069
## alternative hypothesis: two.sided
#Who would I listen to: Family (GOOD)
set2$Q14aF <- factor(set2$Q14a,
levels = c(1, 0),
labels = c("Yes", "No"))
chisq_results_Q14a <- chisq.test(set2$Q14aF,
as.factor(set2$Clusterk_means))
## Warning in chisq.test(set2$Q14aF, as.factor(set2$Clusterk_means)): Chi-squared
## approximation may be incorrect
chisq_results_Q14a
##
## Pearson's Chi-squared test
##
## data: set2$Q14aF and as.factor(set2$Clusterk_means)
## X-squared = 13.94, df = 4, p-value = 0.007489
addmargins(chisq_results_Q14a$observed)
## as.factor(set2$Clusterk_means)
## set2$Q14aF 1 2 3 4 5 Sum
## Yes 49 10 24 21 53 157
## No 7 6 5 6 2 26
## Sum 56 16 29 27 55 183
round(chisq_results_Q14a$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14aF 1 2 3 4 5
## Yes 48.04 13.73 24.88 23.16 47.19
## No 7.96 2.27 4.12 3.84 7.81
round(chisq_results_Q14a$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14aF 1 2 3 4 5
## Yes 0.14 -1.01 -0.18 -0.45 0.85
## No -0.34 2.47 0.43 1.10 -2.08
#Who would I listen to: Finančno izobraženi posamezniki (npr. profesorji, predavatelji) (NO GOOD)
set2$Q14bF <- factor(set2$Q14b,
levels = c(1, 0),
labels = c("Yes", "No"))
chisq_results_Q14b <- chisq.test(set2$Q14bF,
as.factor(set2$Clusterk_means))
chisq_results_Q14b
##
## Pearson's Chi-squared test
##
## data: set2$Q14bF and as.factor(set2$Clusterk_means)
## X-squared = 1.6694, df = 4, p-value = 0.7963
addmargins(chisq_results_Q14b$observed)
## as.factor(set2$Clusterk_means)
## set2$Q14bF 1 2 3 4 5 Sum
## Yes 32 8 18 13 28 99
## No 24 8 11 14 27 84
## Sum 56 16 29 27 55 183
round(chisq_results_Q14b$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14bF 1 2 3 4 5
## Yes 30.3 8.66 15.69 14.61 29.75
## No 25.7 7.34 13.31 12.39 25.25
round(chisq_results_Q14b$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14bF 1 2 3 4 5
## Yes 0.31 -0.22 0.58 -0.42 -0.32
## No -0.34 0.24 -0.63 0.46 0.35
#Who would I listen to: Friends (ALMOST GOOD)
set2$Q14dF <- factor(set2$Q14d,
levels = c(1, 0),
labels = c("Yes", "No"))
chisq_results_Q14d <- chisq.test(set2$Q14dF,
as.factor(set2$Clusterk_means))
chisq_results_Q14d
##
## Pearson's Chi-squared test
##
## data: set2$Q14dF and as.factor(set2$Clusterk_means)
## X-squared = 9.3814, df = 4, p-value = 0.05224
addmargins(chisq_results_Q14d$observed)
## as.factor(set2$Clusterk_means)
## set2$Q14dF 1 2 3 4 5 Sum
## Yes 31 7 14 7 33 92
## No 25 9 15 20 22 91
## Sum 56 16 29 27 55 183
round(chisq_results_Q14d$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14dF 1 2 3 4 5
## Yes 28.15 8.04 14.58 13.57 27.65
## No 27.85 7.96 14.42 13.43 27.35
round(chisq_results_Q14d$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14dF 1 2 3 4 5
## Yes 0.54 -0.37 -0.15 -1.78 1.02
## No -0.54 0.37 0.15 1.79 -1.02
#Who would I listen to: Banks (NO GOOD)
set2$Q14eF <- factor(set2$Q14e,
levels = c(1, 0),
labels = c("Yes", "No"))
chisq_results_Q14e <- chisq.test(set2$Q14eF,
as.factor(set2$Clusterk_means))
chisq_results_Q14e
##
## Pearson's Chi-squared test
##
## data: set2$Q14eF and as.factor(set2$Clusterk_means)
## X-squared = 1.6371, df = 4, p-value = 0.8021
addmargins(chisq_results_Q14e$observed)
## as.factor(set2$Clusterk_means)
## set2$Q14eF 1 2 3 4 5 Sum
## Yes 16 4 9 11 18 58
## No 40 12 20 16 37 125
## Sum 56 16 29 27 55 183
round(chisq_results_Q14e$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14eF 1 2 3 4 5
## Yes 17.75 5.07 9.19 8.56 17.43
## No 38.25 10.93 19.81 18.44 37.57
round(chisq_results_Q14e$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14eF 1 2 3 4 5
## Yes -0.42 -0.48 -0.06 0.83 0.14
## No 0.28 0.32 0.04 -0.57 -0.09
#Who would I listen to: Peers with knowledge (ALMOST GOOD)
set2$Q14fF <- factor(set2$Q14f,
levels = c(1, 0),
labels = c("Yes", "No"))
chisq_results_Q14f <- chisq.test(set2$Q14fF,
as.factor(set2$Clusterk_means))
chisq_results_Q14f
##
## Pearson's Chi-squared test
##
## data: set2$Q14fF and as.factor(set2$Clusterk_means)
## X-squared = 8.6161, df = 4, p-value = 0.07144
addmargins(chisq_results_Q14f$observed)
## as.factor(set2$Clusterk_means)
## set2$Q14fF 1 2 3 4 5 Sum
## Yes 25 4 18 9 29 85
## No 31 12 11 18 26 98
## Sum 56 16 29 27 55 183
round(chisq_results_Q14f$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14fF 1 2 3 4 5
## Yes 26.01 7.43 13.47 12.54 25.55
## No 29.99 8.57 15.53 14.46 29.45
round(chisq_results_Q14f$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14fF 1 2 3 4 5
## Yes -0.20 -1.26 1.23 -1.00 0.68
## No 0.18 1.17 -1.15 0.93 -0.64
#Who would I listen to: I would research on my own (no GOOD)
set2$Q14gF <- factor(set2$Q14g,
levels = c(1, 0),
labels = c("Yes", "No"))
chisq_results_Q14g <- chisq.test(set2$Q14gF,
as.factor(set2$Clusterk_means))
chisq_results_Q14g
##
## Pearson's Chi-squared test
##
## data: set2$Q14gF and as.factor(set2$Clusterk_means)
## X-squared = 1.6795, df = 4, p-value = 0.7944
addmargins(chisq_results_Q14g$observed)
## as.factor(set2$Clusterk_means)
## set2$Q14gF 1 2 3 4 5 Sum
## Yes 24 8 13 13 30 88
## No 32 8 16 14 25 95
## Sum 56 16 29 27 55 183
round(chisq_results_Q14g$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14gF 1 2 3 4 5
## Yes 26.93 7.69 13.95 12.98 26.45
## No 29.07 8.31 15.05 14.02 28.55
round(chisq_results_Q14g$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q14gF 1 2 3 4 5
## Yes -0.56 0.11 -0.25 0.00 0.69
## No 0.54 -0.11 0.24 0.00 -0.66
#Gender (NO GOOD)
set2$Q19F <- factor(set2$Q19,
levels = c(1, 2),
labels = c("Male", "Female"))
chisq_results_Q19 <- chisq.test(set2$Q19F,
as.factor(set2$Clusterk_means))
chisq_results_Q19
##
## Pearson's Chi-squared test
##
## data: set2$Q19F and as.factor(set2$Clusterk_means)
## X-squared = 3.0043, df = 4, p-value = 0.5571
addmargins(chisq_results_Q19$observed)
## as.factor(set2$Clusterk_means)
## set2$Q19F 1 2 3 4 5 Sum
## Male 18 6 11 14 21 70
## Female 38 10 18 13 34 113
## Sum 56 16 29 27 55 183
round(chisq_results_Q19$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q19F 1 2 3 4 5
## Male 21.42 6.12 11.09 10.33 21.04
## Female 34.58 9.88 17.91 16.67 33.96
round(chisq_results_Q19$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q19F 1 2 3 4 5
## Male -0.74 -0.05 -0.03 1.14 -0.01
## Female 0.58 0.04 0.02 -0.90 0.01
#Education (NO GOOD)
set2$Q20F <- factor(set2$Q20,
levels = c(1, 2, 3, 4, 5, 6),
labels = c("osnovka", "sredna", "gimnazija", "vš", "uni", "mag/dr"))
chisq_results_Q20 <- chisq.test(set2$Q20F,
as.factor(set2$Clusterk_means),
simulate.p.value = TRUE)
chisq_results_Q20
##
## Pearson's Chi-squared test with simulated p-value (based on 2000
## replicates)
##
## data: set2$Q20F and as.factor(set2$Clusterk_means)
## X-squared = 19.065, df = NA, p-value = 0.5162
addmargins(chisq_results_Q20$observed)
## as.factor(set2$Clusterk_means)
## set2$Q20F 1 2 3 4 5 Sum
## osnovka 3 0 5 1 7 16
## sredna 5 0 2 2 7 16
## gimnazija 14 4 4 9 14 45
## vš 4 0 1 1 1 7
## uni 24 8 15 11 18 76
## mag/dr 6 4 2 3 8 23
## Sum 56 16 29 27 55 183
round(chisq_results_Q20$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q20F 1 2 3 4 5
## osnovka 4.90 1.40 2.54 2.36 4.81
## sredna 4.90 1.40 2.54 2.36 4.81
## gimnazija 13.77 3.93 7.13 6.64 13.52
## vš 2.14 0.61 1.11 1.03 2.10
## uni 23.26 6.64 12.04 11.21 22.84
## mag/dr 7.04 2.01 3.64 3.39 6.91
round(chisq_results_Q20$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q20F 1 2 3 4 5
## osnovka -0.86 -1.18 1.55 -0.89 1.00
## sredna 0.05 -1.18 -0.34 -0.23 1.00
## gimnazija 0.06 0.03 -1.17 0.92 0.13
## vš 1.27 -0.78 -0.10 -0.03 -0.76
## uni 0.15 0.53 0.85 -0.06 -1.01
## mag/dr -0.39 1.40 -0.86 -0.21 0.41
#Employment (NO GOOD)
set2$Q21F <- factor(set2$Q21,
levels = c(1, 2, 3, 4, 5),
labels = c("Redno", "Redno", "Redno", "Študentsko", "Nezaposlen"))
chisq_results_Q21 <- chisq.test(set2$Q21F,
as.factor(set2$Clusterk_means),
simulate.p.value = TRUE)
chisq_results_Q21
##
## Pearson's Chi-squared test with simulated p-value (based on 2000
## replicates)
##
## data: set2$Q21F and as.factor(set2$Clusterk_means)
## X-squared = 9.5107, df = NA, p-value = 0.3118
addmargins(chisq_results_Q21$observed)
## as.factor(set2$Clusterk_means)
## set2$Q21F 1 2 3 4 5 Sum
## Redno 17 7 8 7 14 53
## Študentsko 30 7 18 12 24 91
## Nezaposlen 9 2 3 8 17 39
## Sum 56 16 29 27 55 183
round(chisq_results_Q21$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q21F 1 2 3 4 5
## Redno 16.22 4.63 8.40 7.82 15.93
## Študentsko 27.85 7.96 14.42 13.43 27.35
## Nezaposlen 11.93 3.41 6.18 5.75 11.72
round(chisq_results_Q21$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q21F 1 2 3 4 5
## Redno 0.19 1.10 -0.14 -0.29 -0.48
## Študentsko 0.41 -0.34 0.94 -0.39 -0.64
## Nezaposlen -0.85 -0.76 -1.28 0.94 1.54
#Employment (NO GOOD)
set2$Q21F <- factor(set2$Q21,
levels = c(1, 2, 3, 4, 5),
labels = c("Redno", "Krajši čs", "Samozaposlen", "Študentsko", "Nezaposlen"))
chisq_results_Q21 <- fisher.test(set2$Q21F,
as.factor(set2$Clusterk_means),
simulate.p.value = TRUE)
chisq_results_Q21
##
## Fisher's Exact Test for Count Data with simulated p-value (based on
## 2000 replicates)
##
## data: set2$Q21F and as.factor(set2$Clusterk_means)
## p-value = 0.3918
## alternative hypothesis: two.sided
#addmargins(chisq_results_Q19$observed)
#round(chisq_results_Q19$expected, 2)
#round(chisq_results_Q19$res, 2)
#Monthly income (NO GOOD)
set2$Q23F <- factor(set2$Q23,
levels = c(1, 2, 3, 4, 5, 6),
labels = c("0-199", "200-499", "500-999", "", 5, 6))
chisq_results_Q23 <- fisher.test(set2$Q23F,
as.factor(set2$Clusterk_means),
simulate.p.value = TRUE)
chisq_results_Q23
##
## Fisher's Exact Test for Count Data with simulated p-value (based on
## 2000 replicates)
##
## data: set2$Q23F and as.factor(set2$Clusterk_means)
## p-value = 0.1914
## alternative hypothesis: two.sided
#addmargins(chisq_results_Q23$observed)
#round(chisq_results_Q23$expected, 2)
#round(chisq_results_Q23$res, 2)
#Monthly available (GOOD)
set2$Q24F <- factor(set2$Q24,
levels = c(1, 2, 3, 4, 5, 6),
labels = c(1, 2, 3, 4, 5, 6))
chisq_results_Q24 <- fisher.test(set2$Q24F,
as.factor(set2$Clusterk_means),
simulate.p.value = TRUE)
chisq_results_Q24
##
## Fisher's Exact Test for Count Data with simulated p-value (based on
## 2000 replicates)
##
## data: set2$Q24F and as.factor(set2$Clusterk_means)
## p-value = 0.03598
## alternative hypothesis: two.sided
#addmargins(chisq_results_Q24$observed)
#round(chisq_results_Q24$expected, 2)
#round(chisq_results_Q24$res, 2)
#Monthly available (GOOD)
set2$Q24F <- factor(set2$Q24,
levels = c(1, 2, 3, 4, 5, 6),
labels = c("0", "<500", "<1000", "<1500", "<2000", ">2000"))
chisq_results_Q24 <- chisq.test(set2$Q24F,
as.factor(set2$Clusterk_means),
simulate.p.value = TRUE)
chisq_results_Q24
##
## Pearson's Chi-squared test with simulated p-value (based on 2000
## replicates)
##
## data: set2$Q24F and as.factor(set2$Clusterk_means)
## X-squared = 30.208, df = NA, p-value = 0.01899
addmargins(chisq_results_Q24$observed)
## as.factor(set2$Clusterk_means)
## set2$Q24F 1 2 3 4 5 Sum
## 0 9 4 9 7 18 47
## <500 22 4 8 11 23 68
## <1000 17 3 8 9 7 44
## <1500 5 2 4 0 7 18
## <2000 3 3 0 0 0 6
## Sum 56 16 29 27 55 183
round(chisq_results_Q24$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q24F 1 2 3 4 5
## 0 14.38 4.11 7.45 6.93 14.13
## <500 20.81 5.95 10.78 10.03 20.44
## <1000 13.46 3.85 6.97 6.49 13.22
## <1500 5.51 1.57 2.85 2.66 5.41
## <2000 1.84 0.52 0.95 0.89 1.80
round(chisq_results_Q24$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q24F 1 2 3 4 5
## 0 -1.42 -0.05 0.57 0.02 1.03
## <500 0.26 -0.80 -0.85 0.31 0.57
## <1000 0.96 -0.43 0.39 0.98 -1.71
## <1500 -0.22 0.34 0.68 -1.63 0.68
## <2000 0.86 3.42 -0.98 -0.94 -1.34
#Region (GOOD)
set2$Q25F <- factor(set2$Q25,
levels = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
labels = c("No LJ", "No LJ", "No LJ", "No LJ", "No LJ", "No LJ", "LJ", "No LJ", "No LJ", "No LJ", "No LJ", "No LJ", "No LJ"))
chisq_results_Q25 <- fisher.test(set2$Q25F,
as.factor(set2$Clusterk_means),
simulate.p.value = TRUE)
chisq_results_Q25
##
## Fisher's Exact Test for Count Data with simulated p-value (based on
## 2000 replicates)
##
## data: set2$Q25F and as.factor(set2$Clusterk_means)
## p-value = 0.01749
## alternative hypothesis: two.sided
#Region (GOOD)
set2$Q25F <- factor(set2$Q25,
levels = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
labels = c("No LJ", "No LJ", "No LJ", "No LJ", "No LJ", "No LJ", "LJ", "No LJ", "No LJ", "No LJ", "No LJ", "No LJ", "No LJ"))
chisq_results_Q25 <- chisq.test(set2$Q25F,
as.factor(set2$Clusterk_means),
simulate.p.value = TRUE)
chisq_results_Q25
##
## Pearson's Chi-squared test with simulated p-value (based on 2000
## replicates)
##
## data: set2$Q25F and as.factor(set2$Clusterk_means)
## X-squared = 11.33, df = NA, p-value = 0.02649
addmargins(chisq_results_Q25$observed)
## as.factor(set2$Clusterk_means)
## set2$Q25F 1 2 3 4 5 Sum
## No LJ 8 5 4 10 20 47
## LJ 48 11 25 17 35 136
## Sum 56 16 29 27 55 183
round(chisq_results_Q25$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q25F 1 2 3 4 5
## No LJ 14.38 4.11 7.45 6.93 14.13
## LJ 41.62 11.89 21.55 20.07 40.87
round(chisq_results_Q25$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q25F 1 2 3 4 5
## No LJ -1.68 0.44 -1.26 1.16 1.56
## LJ 0.99 -0.26 0.74 -0.68 -0.92
#Primary bank (almost GOOD)
set2$Q27F <- factor(set2$Q27,
levels = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14),
labels = c("NLB", "No NLB", "No NLB", "No NLB", "No NLB", "No NLB", "No NLB", "No NLB", "No NLB", "No NLB", "No NLB", "No NLB"))
chisq_results_Q27 <- chisq.test(set2$Q27F,
as.factor(set2$Clusterk_means))
chisq_results_Q27
##
## Pearson's Chi-squared test
##
## data: set2$Q27F and as.factor(set2$Clusterk_means)
## X-squared = 7.5535, df = 4, p-value = 0.1094
addmargins(chisq_results_Q27$observed)
## as.factor(set2$Clusterk_means)
## set2$Q27F 1 2 3 4 5 Sum
## NLB 34 5 11 11 29 90
## No NLB 22 11 18 16 26 93
## Sum 56 16 29 27 55 183
round(chisq_results_Q27$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q27F 1 2 3 4 5
## NLB 27.54 7.87 14.26 13.28 27.05
## No NLB 28.46 8.13 14.74 13.72 27.95
round(chisq_results_Q27$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q27F 1 2 3 4 5
## NLB 1.23 -1.02 -0.86 -0.63 0.38
## No NLB -1.21 1.01 0.85 0.62 -0.37
#Another bank account? (NO GOOD)
set2$Q28F <- factor(set2$Q28,
levels = c(1, 2),
labels = c("Yes", "No"))
chisq_results_Q28 <- chisq.test(set2$Q28F,
as.factor(set2$Clusterk_means))
chisq_results_Q28
##
## Pearson's Chi-squared test
##
## data: set2$Q28F and as.factor(set2$Clusterk_means)
## X-squared = 2.8776, df = 4, p-value = 0.5785
addmargins(chisq_results_Q28$observed)
## as.factor(set2$Clusterk_means)
## set2$Q28F 1 2 3 4 5 Sum
## Yes 21 9 13 11 19 73
## No 35 7 16 16 36 110
## Sum 56 16 29 27 55 183
round(chisq_results_Q28$expected, 2)
## as.factor(set2$Clusterk_means)
## set2$Q28F 1 2 3 4 5
## Yes 22.34 6.38 11.57 10.77 21.94
## No 33.66 9.62 17.43 16.23 33.06
round(chisq_results_Q28$res, 2)
## as.factor(set2$Clusterk_means)
## set2$Q28F 1 2 3 4 5
## Yes -0.28 1.04 0.42 0.07 -0.63
## No 0.23 -0.84 -0.34 -0.06 0.51