# import an excel file
mydata <- read_excel("C:/Users/Eneja/Desktop/anketa10.xlsx")
# delete first row in which the questions are written
mydata <- mydata[-1,]
# add an ID variable
mydata$ID <- 1:nrow(mydata)
mydata <- mydata[,c(93, 1:92)]
head(mydata)
## # A tibble: 6 × 93
## ID Q1 Q2 Q3 Q4 Q5 Q6a Q6b Q6c Q6d Q7a_1 Q7b_1 Q7c_1 Q7d_1 Q7e_1 Q7f_1 Q8a Q8b Q8c Q8d Q9a
## <int> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr>
## 1 1 7 2 -2 -2 -2 1 5 5 5 7 10 16 16 16 80 3 5 2 4 5
## 2 2 6 2 -2 -2 -2 3 4 5 3 0 22 59 0 23 57 4 4 1 4 5
## 3 3 5 2 -2 -2 -2 4 4 3 3 0 26 63 17 0 100 4 2 2 4 4
## 4 4 7 1 3 4 2 5 4 3 2 82 0 85 63 85 100 5 4 1 4 5
## 5 5 7 2 -2 -2 -2 4 2 4 5 0 0 0 0 25 50 5 1 1 1 5
## 6 6 7 1 3 4 2 4 4 4 2 0 0 -1 0 0 70 4 4 1 2 5
## # … with 72 more variables: Q9b <chr>, Q9c <chr>, Q9d <chr>, Q10a <chr>, Q10b <chr>, Q10c <chr>, Q10d <chr>, Q10e <chr>,
## # Q10f <chr>, Q10g <chr>, Q10h <chr>, Q11 <chr>, Q11_9_text <chr>, Q12a <chr>, Q12b <chr>, Q12c <chr>, Q12d <chr>, Q12e <chr>,
## # Q12f <chr>, Q13a <chr>, Q13b <chr>, Q13c <chr>, Q13d <chr>, Q13e <chr>, Q14a <chr>, Q14b <chr>, Q14c <chr>, Q14d <chr>,
## # Q14e <chr>, Q15a <chr>, Q15b <chr>, Q15c <chr>, Q15d <chr>, Q15e <chr>, Q16a <chr>, Q16b <chr>, Q16c <chr>, Q16d <chr>,
## # Q16e <chr>, Q17a <chr>, Q17b <chr>, Q17c <chr>, Q17d <chr>, Q17e <chr>, Q18a <chr>, Q18b <chr>, Q18c <chr>, Q18d <chr>,
## # Q18e <chr>, Q19 <chr>, Q20 <chr>, Q21 <chr>, Q22 <chr>, Q22_4_text <chr>, Q23 <chr>, Q24a <chr>, Q24b <chr>, Q24c <chr>,
## # Q24d <chr>, Q24e <chr>, Q24f <chr>, Q24g <chr>, Q24h <chr>, Q24i <chr>, Q24j <chr>, Q24k <chr>, Q24l <chr>, …
Description:
#For those who did not move only one slider for question 7, insert 50 (midpoint - half savings, half loans) as the selected value
mydata$Q7a_1 <- ifelse((mydata$Q7a_1==-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1!=-1),50, mydata$Q7a_1)
mydata$Q7b_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1==-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1!=-1),50,mydata$Q7b_1)
mydata$Q7c_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1==-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1!=-1),50,mydata$Q7c_1)
mydata$Q7d_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1==-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1!=-1),50,mydata$Q7d_1)
mydata$Q7e_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1==-1)&(mydata$Q7f_1!=-1),50,mydata$Q7e_1)
mydata$Q7f_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1==-1),50,mydata$Q7f_1)
#Identify values -1,-3 and replace them with NA. Identify also the -2
# -1 means: The person has not answered the specific question
# -2 means: Person did not respond because it did not satisfy if sentence
# -3 means: Person stopped answering questionnaire before coming to this sentence
mydata[mydata == -1] <- NA
mydata[mydata == -3] <- NA
# Get rid of those that are under 18 and over 27
mydata_t1<-mydata[!(mydata$Q2=="-2"),]
#solve some problems with 1ka (illogical -2 values)
mydata_t1 <- mydata_t1[!(mydata_t1$Q13a=="-2"),]
mydata_dropNA<-mydata_t1
mydata_dropNA <- na.omit(mydata_dropNA)
# convert character to integer, except the variables where Other was typed in
mydata_dropNA <- mydata_dropNA %>%
mutate_at(c(2:33), as.integer)
mydata_dropNA <- mydata_dropNA %>%
mutate_at(c(35:74), as.integer)
mydata_dropNA <- mydata_dropNA %>%
mutate_at(c(76:88), as.integer)
mydata_dropNA <- mydata_dropNA %>%
mutate_at(c(89:93), as.integer)
## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion
mydata_dropNA$Q1 <- mydata_dropNA$Q1 + 16
Transform fo factors
mydata_dropNA$Sex_F <- factor(mydata_dropNA$Q19,
levels = c(1, 2,3),
labels = c("Female", "Male", "Other"))
mydata_dropNA$Region_F <- factor(mydata_dropNA$Q20,
levels = c(1,2, 3, 4, 5, 6, 7, 8, 9),
labels = c("Ljubljana z okolico","Štajerska","Prekmurje", "Dolenjska","Primorska" , "Gorenjska" , "Goriška", "Koroška" , "Notranjska"))
mydata_dropNA$Status_F <- factor(mydata_dropNA$Q22,
levels = c(1,2, 3),
labels = c("Single","In a relationship","Married"))
mydata_dropNA$Children_F <- factor(mydata_dropNA$Q23,
levels = c(2, 1),
labels = c("No", "Yes"))
mydata_dropNA$Education_F <- factor(mydata_dropNA$Q25,
levels = c(1,2,3,4,5),
labels = c("Primary school", "High school", "Vocational School", "Undergraduate", "Post-Graduate"))
mydata_dropNA$Employed_F <- factor(mydata_dropNA$Q26,
levels = c(2, 1),
labels = c("No", "Yes"))
head(mydata_dropNA)
## # A tibble: 6 × 99
## ID Q1 Q2 Q3 Q4 Q5 Q6a Q6b Q6c Q6d Q7a_1 Q7b_1 Q7c_1 Q7d_1 Q7e_1 Q7f_1 Q8a Q8b Q8c Q8d Q9a
## <int> <dbl> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
## 1 1 23 2 -2 -2 -2 1 5 5 5 7 10 16 16 16 80 3 5 2 4 5
## 2 2 22 2 -2 -2 -2 3 4 5 3 0 22 59 0 23 57 4 4 1 4 5
## 3 3 21 2 -2 -2 -2 4 4 3 3 0 26 63 17 0 100 4 2 2 4 4
## 4 4 23 1 3 4 2 5 4 3 2 82 0 85 63 85 100 5 4 1 4 5
## 5 5 23 2 -2 -2 -2 4 2 4 5 0 0 0 0 25 50 5 1 1 1 5
## 6 6 23 1 3 4 2 4 4 4 2 0 0 50 0 0 70 4 4 1 2 5
## # … with 78 more variables: Q9b <int>, Q9c <int>, Q9d <int>, Q10a <int>, Q10b <int>, Q10c <int>, Q10d <int>, Q10e <int>,
## # Q10f <int>, Q10g <int>, Q10h <int>, Q11 <int>, Q11_9_text <chr>, Q12a <int>, Q12b <int>, Q12c <int>, Q12d <int>, Q12e <int>,
## # Q12f <int>, Q13a <int>, Q13b <int>, Q13c <int>, Q13d <int>, Q13e <int>, Q14a <int>, Q14b <int>, Q14c <int>, Q14d <int>,
## # Q14e <int>, Q15a <int>, Q15b <int>, Q15c <int>, Q15d <int>, Q15e <int>, Q16a <int>, Q16b <int>, Q16c <int>, Q16d <int>,
## # Q16e <int>, Q17a <int>, Q17b <int>, Q17c <int>, Q17d <int>, Q17e <int>, Q18a <int>, Q18b <int>, Q18c <int>, Q18d <int>,
## # Q18e <int>, Q19 <int>, Q20 <int>, Q21 <int>, Q22 <int>, Q22_4_text <chr>, Q23 <int>, Q24a <int>, Q24b <int>, Q24c <int>,
## # Q24d <int>, Q24e <int>, Q24f <int>, Q24g <int>, Q24h <int>, Q24i <int>, Q24j <int>, Q24k <int>, Q24l <int>, …
mydata_dropNA <- mydata_dropNA[-c(255, 231, 107),]
summary(mydata_dropNA[c("Q12a", "Q6a", "Q6c", "Q12d","Q12f")])
## Q12a Q6a Q6c Q12d Q12f
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:2.000 1st Qu.:2.000 1st Qu.:4.000 1st Qu.:4.000 1st Qu.:3.000
## Median :3.000 Median :3.000 Median :4.000 Median :4.000 Median :3.000
## Mean :2.709 Mean :2.997 Mean :4.206 Mean :3.977 Mean :3.268
## 3rd Qu.:3.000 3rd Qu.:4.000 3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:4.000
## Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
library(Hmisc)
rcorr(as.matrix(mydata_dropNA[ , c("Q12a", "Q6a", "Q6c", "Q12d","Q12f")]),
type = "pearson")
## Q12a Q6a Q6c Q12d Q12f
## Q12a 1.00 -0.01 -0.05 -0.07 0.34
## Q6a -0.01 1.00 -0.24 0.17 0.08
## Q6c -0.05 -0.24 1.00 -0.02 -0.02
## Q12d -0.07 0.17 -0.02 1.00 0.10
## Q12f 0.34 0.08 -0.02 0.10 1.00
##
## n= 306
##
##
## P
## Q12a Q6a Q6c Q12d Q12f
## Q12a 0.8613 0.3605 0.2169 0.0000
## Q6a 0.8613 0.0000 0.0034 0.1847
## Q6c 0.3605 0.0000 0.7478 0.6755
## Q12d 0.2169 0.0034 0.7478 0.0849
## Q12f 0.0000 0.1847 0.6755 0.0849
“Q12a”, “Q6a”, “Q6c”, “Q12d”,“Q12f” najboljšiii
mydata_std <- as.data.frame(scale(mydata_dropNA[c("Q12a", "Q6a", "Q6c", "Q12d","Q12f")]))
mydata_std$Dissimilarity <- sqrt(mydata_std$Q12a^2 + mydata_std$Q6a^2 + mydata_std$Q6c^2 + mydata_std$Q12d^2 + mydata_std$Q12f^2 )
head(mydata_std[order(-mydata_std$Dissimilarity), ], 5) #Finding top 5 objects with highest value of dissimilarity
## Q12a Q6a Q6c Q12d Q12f Dissimilarity
## 270 2.466461 -1.724287915 0.9307424 -3.136223 -1.3475885 4.644865
## 179 -1.840170 -0.860732920 0.9307424 -3.136223 -2.4103775 4.543037
## 123 -1.840170 0.002822075 0.9307424 -3.136223 -2.4103775 4.460755
## 293 1.389803 -0.860732920 -3.7574417 1.077539 -0.2847996 4.246526
## 187 -1.840170 -1.724287915 0.9307424 -2.082783 -2.4103775 4.168163
mydata1 <- mydata_std
library(factoextra)
#Finding Eudlidean distances, based on 6 Cluster variables, then saving them into object Distances
Distances <- get_dist(mydata1,
method = "euclidian")
Distances2 <- Distances^2
fviz_dist(Distances2) #Showing matrix of distances
library(factoextra)
get_clust_tendency(mydata1, #Hopkins statistics
n = nrow(mydata1) - 1,
graph = FALSE)
## $hopkins_stat
## [1] 0.6249463
##
## $plot
## NULL
library(dplyr)
WARD <- mydata1 %>% #Selecting variables
get_dist(method = "euclidean") %>% #Selecting distance
hclust(method = "ward.D2") #Selecting algorithm
WARD
##
## Call:
## hclust(d = ., method = "ward.D2")
##
## Cluster method : ward.D2
## Distance : euclidean
## Number of objects: 306
library(factoextra)
fviz_dend(WARD) #Dendrogram
## 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 <]8;;https://github.com/kassambara/factoextra/issueshttps://github.com/kassambara/factoextra/issues]8;;>.
set.seed(1)
#install.packages("NbClust")
library(NbClust)
OptNumber <- mydata1[c("Q12a", "Q6a", "Q6c", "Q12d")] %>%
#scale() %>%
NbClust(distance = "euclidean",
min.nc = 2, max.nc = 10,
method = "ward.D2",
index = "all")
## *** : The Hubert index is a graphical method of determining the number of clusters.
## In the plot of Hubert index, we seek a significant knee that corresponds to a
## significant increase of the value of the measure i.e the significant peak in Hubert
## index second differences plot.
##
## *** : The D index is a graphical method of determining the number of clusters.
## In the plot of D index, we seek a significant knee (the significant peak in Dindex
## second differences plot) that corresponds to a significant increase of the value of
## the measure.
##
## *******************************************************************
## * Among all indices:
## * 4 proposed 2 as the best number of clusters
## * 3 proposed 3 as the best number of clusters
## * 6 proposed 5 as the best number of clusters
## * 2 proposed 6 as the best number of clusters
## * 2 proposed 7 as the best number of clusters
## * 1 proposed 9 as the best number of clusters
## * 5 proposed 10 as the best number of clusters
##
## ***** Conclusion *****
##
## * According to the majority rule, the best number of clusters is 5
##
##
## *******************************************************************
mydata1$ClusterWard <- cutree(WARD,
k = 5) #Number of groups
head(mydata1[c( "ClusterWard")])
## ClusterWard
## 1 1
## 2 2
## 3 3
## 4 1
## 5 1
## 6 1
#Calculating positions of initial leaders
Initial_leaders <- aggregate(mydata1[, c("Q12a", "Q6a", "Q6c", "Q12d","Q12f")],
by = list(mydata1$ClusterWard),
FUN = mean)
Initial_leaders
## Group.1 Q12a Q6a Q6c Q12d Q12f
## 1 1 -0.2217545 -0.03568038 0.2737994 0.25223195 0.2364408
## 2 2 0.5054058 -0.64484417 0.7633073 -1.74417698 0.1706813
## 3 3 1.3115008 0.42674907 -0.4117830 0.36886069 0.5461080
## 4 4 -0.3908229 0.26853130 -2.1796874 -0.38107115 -0.2439231
## 5 5 -1.0326765 -0.16988892 0.3740206 -0.02857372 -1.6398555
library(factoextra)
kmeans_clu <- hkmeans(mydata1, #Data
k = 5, #Number of groups
hc.metric = "euclidean", #Distance for hierar. clus.
hc.method = "ward.D2") #Algorithm for hierar. clus.
kmeans_clu
## Hierarchical K-means clustering with 5 clusters of sizes 155, 30, 49, 31, 41
##
## Cluster means:
## Q12a Q6a Q6c Q12d Q12f Dissimilarity ClusterWard
## 1 -0.2356026 -0.01946322 0.2653228 0.26197200 0.23630976 1.645791 1.000000
## 2 0.5284771 -0.68802192 0.7744696 -1.66140665 0.17574222 2.568938 1.933333
## 3 1.3678306 0.37291707 -0.1934650 0.41107649 0.51771443 2.215680 3.000000
## 4 -0.1383561 0.42067127 -2.2073163 -0.31572123 -0.01053154 2.979714 3.806452
## 5 -1.0261115 -0.18673878 0.3304262 -0.02728903 -1.63272704 2.587330 4.975610
##
## Clustering vector:
## [1] 2 2 3 1 1 1 1 3 1 3 4 1 3 4 1 5 5 1 1 3 1 3 1 1 1 1 3 2 1 5 2 1 3 2 3 1 3 1 2 3 1 5 3 1 1 1 1 4 3 1 1 2 3 4 5 1 4 2 1 1 1 5
## [63] 1 4 4 4 2 3 3 1 3 4 1 1 2 3 3 1 1 2 1 1 1 4 3 1 2 3 3 1 3 1 3 3 1 3 2 1 1 1 1 4 1 5 1 3 3 1 1 1 3 1 4 1 5 2 4 3 1 3 1 1 5 1
## [125] 3 3 1 1 1 1 1 1 1 4 4 1 1 5 1 1 5 2 1 1 1 2 1 3 4 1 5 1 2 1 2 1 1 4 3 2 1 1 1 2 1 1 1 1 1 5 1 2 1 1 2 1 3 5 5 5 2 5 3 2 1 1
## [187] 5 3 1 1 3 2 3 5 1 1 4 1 1 1 1 5 3 3 1 1 2 1 1 1 1 1 1 4 1 4 1 1 1 5 1 3 1 1 5 1 1 1 3 5 1 5 1 1 2 1 5 3 1 1 5 1 5 5 5 4 1 4
## [249] 1 1 1 1 1 1 1 1 1 4 1 1 3 5 1 1 4 1 2 5 1 2 5 4 4 3 1 1 1 5 1 5 1 1 4 3 5 5 5 2 1 4 1 1 4 5 5 5 4 4 1 3 1 1 1 1 5 1
##
## Within cluster sum of squares by cluster:
## [1] 482.6643 100.2068 145.7184 151.3022 166.1804
## (between_SS / total_SS = 56.0 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss" "betweenss" "size" "iter"
## [9] "ifault" "data" "hclust"
library(factoextra)
fviz_cluster(kmeans_clu,
palette = "Set1",
repel = FALSE,
ggtheme = theme_bw())
mydata1$ClusterK_Means <- kmeans_clu$cluster
head(mydata1[c( "ClusterWard", "ClusterK_Means")])
## ClusterWard ClusterK_Means
## 1 1 2
## 2 2 2
## 3 3 3
## 4 1 1
## 5 1 1
## 6 1 1
#Checking for reclassifications
table(mydata1$ClusterWard)
##
## 1 2 3 4 5
## 157 28 55 26 40
table(mydata1$ClusterK_Means)
##
## 1 2 3 4 5
## 155 30 49 31 41
table(mydata1$ClusterWard, mydata1$ClusterK_Means)
##
## 1 2 3 4 5
## 1 155 2 0 0 0
## 2 0 28 0 0 0
## 3 0 0 49 6 0
## 4 0 0 0 25 1
## 5 0 0 0 0 40
Centroids <- kmeans_clu$centers
Centroids
## Q12a Q6a Q6c Q12d Q12f Dissimilarity ClusterWard
## 1 -0.2356026 -0.01946322 0.2653228 0.26197200 0.23630976 1.645791 1.000000
## 2 0.5284771 -0.68802192 0.7744696 -1.66140665 0.17574222 2.568938 1.933333
## 3 1.3678306 0.37291707 -0.1934650 0.41107649 0.51771443 2.215680 3.000000
## 4 -0.1383561 0.42067127 -2.2073163 -0.31572123 -0.01053154 2.979714 3.806452
## 5 -1.0261115 -0.18673878 0.3304262 -0.02728903 -1.63272704 2.587330 4.975610
library(ggplot2)
library(tidyr)
##
## Attaching package: 'tidyr'
## The following object is masked from 'package:magrittr':
##
## extract
Figure <- as.data.frame(Centroids)
Figure$id <- 1:nrow(Figure)
Figure <- pivot_longer(Figure, cols = c(Q12a, Q6a, Q6c, Q12d,Q12f))
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("Q12a", "Q6a", "Q6c", "Q12d","Q12f"),
labels = c("reputation", "necessity", "postponing", "willingness to switch ","transparency"))
ggplot(Figure, aes(x = nameFactor, y = value)) +
geom_hline(yintercept = 0) +
theme_bw() +
geom_point(aes(shape = Groups, col = Groups), size = 3) +
geom_line(aes(group = id), linewidth = 1) +
ylab("Averages") +
xlab("Cluster variables")+
ylim(-2.2, 2.2)
## Warning: Removed 1 rows containing missing values (`geom_point()`).
#Checking if clustering variables successfully differentiate between groups
fit <- aov(cbind(Q12a, Q6a, Q6c, Q12d,Q12f) ~ as.factor(ClusterK_Means),
data = mydata1)
summary(fit)
## Response Q12a :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 4 152.42 38.106 75.173 < 2.2e-16 ***
## Residuals 301 152.58 0.507
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q6a :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 4 27.99 6.9975 7.6035 7.57e-06 ***
## Residuals 301 277.01 0.9203
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q6c :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 4 186.26 46.564 118.03 < 2.2e-16 ***
## Residuals 301 118.74 0.394
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q12d :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 4 104.85 26.212 39.418 < 2.2e-16 ***
## Residuals 301 200.15 0.665
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q12f :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 4 132.02 33.004 57.429 < 2.2e-16 ***
## Residuals 301 172.98 0.575
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
aggregate(mydata_dropNA$Q28,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 2.161290
## 2 2 3.300000
## 3 3 1.918367
## 4 4 1.838710
## 5 5 1.829268
fit <- aov(mydata_dropNA$Q28 ~ as.factor(ClusterK_Means),
data = mydata1)
summary(fit)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 4 49.5 12.383 6.574 4.39e-05 ***
## Residuals 301 566.9 1.884
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
chi_square <- chisq.test(mydata_dropNA$Sex_F, as.factor(mydata1$ClusterK_Means))
## Warning in chisq.test(mydata_dropNA$Sex_F, as.factor(mydata1$ClusterK_Means)): Chi-squared approximation may be incorrect
chi_square
##
## Pearson's Chi-squared test
##
## data: mydata_dropNA$Sex_F and as.factor(mydata1$ClusterK_Means)
## X-squared = 19.859, df = 8, p-value = 0.01088
addmargins(chi_square$observed)
##
## mydata_dropNA$Sex_F 1 2 3 4 5 Sum
## Female 102 24 22 12 21 181
## Male 52 6 27 19 19 123
## Other 1 0 0 0 0 1
## Sum 155 30 49 31 40 305
addmargins(round(chi_square$expected, 2))
##
## mydata_dropNA$Sex_F 1 2 3 4 5 Sum
## Female 91.98 17.8 29.08 18.4 23.74 181
## Male 62.51 12.1 19.76 12.5 16.13 123
## Other 0.51 0.1 0.16 0.1 0.13 1
## Sum 155.00 30.0 49.00 31.0 40.00 305
round(chi_square$res, 2)
##
## mydata_dropNA$Sex_F 1 2 3 4 5
## Female 1.04 1.47 -1.31 -1.49 -0.56
## Male -1.33 -1.75 1.63 1.84 0.71
## Other 0.69 -0.31 -0.40 -0.32 -0.36
library(effectsize)
effectsize::cramers_v(mydata_dropNA$Sex_F, mydata1$ClusterK_Means)
## Cramer's V (adj.) | 95% CI
## --------------------------------
## 0.14 | [0.00, 1.00]
##
## - One-sided CIs: upper bound fixed at [1.00].
aggregate(mydata_dropNA$Q24b,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 0.4451613
## 2 2 0.4000000
## 3 3 0.4489796
## 4 4 0.4516129
## 5 5 0.3902439
aggregate(mydata_dropNA$Q25,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 3.367742
## 2 2 3.133333
## 3 3 3.367347
## 4 4 3.290323
## 5 5 3.073171
aggregate(mydata_dropNA$Q9a,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 4.445161
## 2 2 4.033333
## 3 3 4.693878
## 4 4 4.322581
## 5 5 4.048780
aggregate(mydata_dropNA$Q22,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 1.516129
## 2 2 1.600000
## 3 3 1.571429
## 4 4 1.387097
## 5 5 1.658537
aggregate(mydata_dropNA$Q10h,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 3.858065
## 2 2 3.700000
## 3 3 4.040816
## 4 4 4.032258
## 5 5 4.048780