Grouping of American families in 1975 on the basis of education levels of the husband and wife, working experience in years of wife. Further looking at the demographic characteristics of such groups along with validating them with income and whether they reside in a city
library(ggplot2)
mydataM <- read.csv("C:/Users/ACER/Downloads/Mroz.csv")
head(mydataM)
## ID work Children educw educh income unemprate city experience
## 1 1 yes 1 12 12 16310 5.0 no 14
## 2 2 yes 2 12 9 21800 11.0 yes 5
## 3 3 yes 4 12 12 21040 5.0 no 15
## 4 4 yes 3 12 10 7300 5.0 no 6
## 5 5 yes 3 14 12 27300 9.5 yes 7
## 6 6 yes 0 12 11 19495 7.5 yes 33
Sample size: 753
Unit of observation: 1 family
Variables:
Source: https://www.kaggle.com/datasets/utkarshx27/labor-supply-data?resource=download
library(tidyr)
mydataM <- drop_na(mydataM)
summary(mydataM[ , c(3,4,5,6,9)])
## Children educw educh income
## Min. :0.000 Min. : 5.00 Min. : 3.00 Min. : 1500
## 1st Qu.:0.000 1st Qu.:12.00 1st Qu.:11.00 1st Qu.:15428
## Median :1.000 Median :12.00 Median :12.00 Median :20880
## Mean :1.591 Mean :12.29 Mean :12.49 Mean :23081
## 3rd Qu.:3.000 3rd Qu.:13.00 3rd Qu.:15.00 3rd Qu.:28200
## Max. :8.000 Max. :17.00 Max. :17.00 Max. :96000
## experience
## Min. : 0.00
## 1st Qu.: 4.00
## Median : 9.00
## Mean :10.63
## 3rd Qu.:15.00
## Max. :45.00
min educw: minimum education level in years of a woman observed in the sample is 6 years
mean income: average family income of the observations is $23178
mydataM$exp_z <- scale(mydataM$experience)
mydataM$educw_z <- scale(mydataM$educw)
mydataM$educh_z <- scale(mydataM$educh)
library(Hmisc)
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, units
rcorr(as.matrix(mydataM[ , c("exp_z", "educw_z", "educh_z")]),
type = "pearson")
## exp_z educw_z educh_z
## exp_z 1.00 0.07 -0.04
## educw_z 0.07 1.00 0.61
## educh_z -0.04 0.61 1.00
##
## n= 753
##
##
## P
## exp_z educw_z educh_z
## exp_z 0.0692 0.3198
## educw_z 0.0692 0.0000
## educh_z 0.3198 0.0000
Based on this there is a high positive correlation between the education level in years of husband and wife
mydataM$Dissimilarity <- sqrt(mydataM$exp_z^2 + mydataM$educw_z^2 + mydataM$educh_z^2)
head(mydataM[order(-mydataM$Dissimilarity), ], 10)
## ID work Children educw educh income unemprate city experience exp_z
## 397 397 yes 0 6 8 15428 7.5 no 37 3.2679099
## 725 725 no 2 5 3 6531 7.5 no 7 -0.4499630
## 598 598 no 0 11 11 18500 7.5 yes 45 4.2593427
## 586 586 no 0 5 5 6340 14.0 no 0 -1.3174667
## 55 55 yes 0 10 4 11000 7.5 no 34 2.8961226
## 640 640 no 3 6 4 3777 11.0 no 0 -1.3174667
## 176 176 yes 0 5 5 16400 14.0 yes 9 -0.2021048
## 631 631 no 0 5 6 9380 14.0 yes 20 1.1611153
## 552 552 no 1 6 5 22159 7.5 no 2 -1.0696085
## 312 312 yes 0 17 17 24717 11.0 yes 33 2.7721935
## educw_z educh_z Dissimilarity
## 397 -2.7570942 -1.486812 4.526744
## 725 -3.1956434 -3.142000 4.504084
## 598 -0.5643482 -0.493699 4.324838
## 586 -3.1956434 -2.479925 4.254161
## 55 -1.0028974 -2.810963 4.158707
## 640 -2.7570942 -2.810963 4.151963
## 176 -3.1956434 -2.479925 4.050063
## 631 -3.1956434 -2.148887 4.022194
## 552 -2.7570942 -2.479925 3.859489
## 312 2.0669471 1.492527 3.766293
remove_ids <- c(397, 725, 598, 586, 55, 640, 176, 631)
mydataM <- mydataM[!mydataM$ID %in% remove_ids, ]
head(mydataM[order(-mydataM$Dissimilarity), ], 10)
## ID work Children educw educh income unemprate city experience exp_z
## 552 552 no 1 6 5 22159 7.5 no 2 -1.0696085
## 312 312 yes 0 17 17 24717 11.0 yes 33 2.7721935
## 391 391 yes 0 6 6 13300 7.5 no 14 0.4175407
## 271 271 yes 0 14 14 32011 7.5 no 38 3.3918390
## 57 57 yes 0 14 15 32500 14.0 yes 37 3.2679099
## 86 86 yes 1 17 17 32950 5.0 yes 29 2.2764771
## 295 295 yes 1 9 4 9400 7.5 no 21 1.2850444
## 677 677 no 0 8 5 37700 7.5 no 0 -1.3174667
## 8 8 yes 0 12 8 18900 5.0 no 35 3.0200517
## 314 314 yes 0 12 8 19600 7.5 yes 35 3.0200517
## educw_z educh_z Dissimilarity
## 552 -2.7570942 -2.4799250 3.859489
## 312 2.0669471 1.4925271 3.766293
## 391 -2.7570942 -2.1488873 3.520458
## 271 0.7512994 0.4994141 3.509763
## 57 0.7512994 0.8304518 3.454466
## 86 2.0669471 1.4925271 3.417931
## 295 -1.4414466 -2.8109627 3.410369
## 677 -1.8799958 -2.4799250 3.379368
## 8 -0.1257990 -1.4868120 3.368553
## 314 -0.1257990 -1.4868120 3.368553
mydataM$exp_z <- scale(mydataM$experience)
mydataM$educw_z <- scale(mydataM$educw)
mydataM$educh_z <- scale(mydataM$educh)
mydataM$Dissimilarity <- sqrt(mydataM$exp_z^2 + mydataM$educw_z^2 + mydataM$educh_z^2)
head(mydataM[order(-mydataM$Dissimilarity), ], 10)
## ID work Children educw educh income unemprate city experience exp_z
## 552 552 no 1 6 5 22159 7.5 no 2 -1.0837962
## 312 312 yes 0 17 17 24717 11.0 yes 33 2.8499258
## 391 391 yes 0 6 6 13300 7.5 no 14 0.4389349
## 271 271 yes 0 14 14 32011 7.5 no 38 3.4843971
## 295 295 yes 1 9 4 9400 7.5 no 21 1.3271947
## 57 57 yes 0 14 15 32500 14.0 yes 37 3.3575029
## 677 677 no 0 8 5 37700 7.5 no 0 -1.3375847
## 86 86 yes 1 17 17 32950 5.0 yes 29 2.3423488
## 8 8 yes 0 12 8 18900 5.0 no 35 3.1037143
## 314 314 yes 0 12 8 19600 7.5 yes 35 3.1037143
## educw_z educh_z Dissimilarity
## 552 -2.882097 -2.5694361 4.010374
## 312 2.112359 1.5070073 3.854246
## 391 -2.882097 -2.2297325 3.670266
## 271 0.750235 0.4878965 3.597488
## 295 -1.519972 -2.9091397 3.540460
## 57 0.750235 0.8276001 3.538446
## 677 -1.974014 -2.5694361 3.505405
## 86 2.112359 1.5070073 3.495673
## 8 -0.157848 -1.5503252 3.472962
## 314 -0.157848 -1.5503252 3.472962
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
distance <- get_dist(mydataM[c("exp_z", "educw_z", "educh_z")],
method = "euclidian")
distance2 <- distance^2
fviz_dist(distance2,
gradient = list(low = "lightblue", mid = "pink", high = "purple"))
get_clust_tendency(mydataM[c("exp_z", "educw_z", "educh_z")],
n = nrow(mydataM) - 1,
graph = FALSE)
## $hopkins_stat
## [1] 0.7284986
##
## $plot
## NULL
As its above 0.5 we can say the data is clusterable
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
##
## src, summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
WARD <- mydataM[c("exp_z", "educw_z", "educh_z")] %>%
get_dist(method = "euclidian") %>%
hclust(method = "ward.D2")
WARD
##
## Call:
## hclust(d = ., method = "ward.D2")
##
## Cluster method : ward.D2
## Distance : euclidean
## Number of objects: 745
fviz_dend(WARD)
## 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.
fviz_dend(WARD,
k = 3,
cex = 0.5,
palette = "jama",
color_labels_by_k = TRUE,
rect = TRUE)
Based on the dendrogram we can say three clusters are appropriate for this dataset
mydataM$ClusterWard <- cutree(WARD,
k = 3)
head(mydataM[c(1,14)])
## ID ClusterWard
## 1 1 1
## 2 2 1
## 3 3 1
## 4 4 1
## 5 5 2
## 6 6 3
Initial_leaders <- aggregate(mydataM[ , c("exp_z", "educw_z", "educh_z")],
by = list(mydataM$ClusterWard),
FUN = mean)
Initial_leaders
## Group.1 exp_z educw_z educh_z
## 1 1 -0.3217697 -0.5480399 -0.5550998
## 2 2 -0.1554154 0.8203443 0.9874606
## 3 3 1.8632873 -0.1425432 -0.6228199
K_MEANS <- hkmeans(mydataM[c("exp_z", "educw_z", "educh_z")],
k = 3,
hc.metric = "euclidean",
hc.method = "ward.D2")
K_MEANS
## Hierarchical K-means clustering with 3 clusters of sizes 315, 242, 188
##
## Cluster means:
## exp_z educw_z educh_z
## 1 -0.6306024 -0.5225226 -0.5765082
## 2 -0.1562097 0.9134648 1.0943095
## 3 1.2576729 -0.3003397 -0.4426746
##
## Clustering vector:
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
## 3 1 3 1 2 3 2 3 3 3 3 3 2 3 2 1 3 1 3 1
## 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
## 2 1 2 2 1 2 3 1 2 1 3 2 3 3 2 1 2 3 3 2
## 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61
## 2 3 2 1 1 1 2 3 3 1 1 3 3 3 2 3 2 3 1 3
## 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
## 1 1 3 1 1 2 1 1 3 2 3 3 1 3 3 1 2 2 2 3
## 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
## 3 1 2 3 2 3 3 2 1 3 1 2 1 2 3 3 2 2 1 1
## 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
## 3 1 2 1 2 3 3 3 2 2 3 2 2 3 3 3 1 2 1 2
## 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
## 3 1 2 2 3 2 3 2 1 1 1 1 1 1 1 1 3 1 3 3
## 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
## 3 2 3 1 1 1 3 2 2 2 2 1 2 2 2 1 2 3 1 3
## 162 163 164 165 166 167 168 169 170 171 172 173 174 175 177 178 179 180 181 182
## 2 2 2 3 1 2 2 1 1 1 3 1 3 2 2 3 1 1 2 1
## 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
## 3 2 1 2 2 1 2 2 3 1 1 1 2 1 3 3 3 2 1 2
## 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
## 2 3 3 3 3 3 1 1 3 1 1 1 3 2 2 3 3 1 3 1
## 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
## 1 2 2 2 2 2 3 1 1 3 2 1 3 2 1 3 2 2 3 1
## 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
## 2 2 1 1 1 1 3 2 2 1 2 1 1 2 2 3 2 1 2 1
## 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
## 2 2 3 1 2 1 2 2 3 3 1 1 1 3 1 1 3 3 2 1
## 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
## 2 2 3 3 1 3 2 2 3 2 2 3 3 3 3 3 3 2 3 2
## 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
## 1 2 1 1 3 1 1 1 1 2 3 3 2 2 3 1 2 3 3 1
## 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
## 1 3 1 1 2 1 1 2 3 2 3 1 2 3 1 1 3 3 2 3
## 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
## 2 3 2 2 3 2 1 2 3 2 1 3 2 2 2 2 1 3 1 2
## 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
## 2 1 3 1 1 2 2 2 2 1 2 3 1 1 1 2 2 3 2 2
## 383 384 385 386 387 388 389 390 391 392 393 394 395 396 398 399 400 401 402 403
## 3 3 3 2 1 1 2 3 1 2 1 2 3 2 2 2 3 2 1 2
## 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
## 1 3 3 3 1 3 1 3 2 3 3 2 1 2 1 3 1 2 1 2
## 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
## 1 3 3 3 1 2 2 2 2 2 1 2 1 1 1 1 1 1 1 1
## 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
## 1 1 2 1 1 1 2 3 2 2 2 1 1 3 1 1 1 1 1 1
## 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
## 1 1 2 2 2 2 1 1 1 1 1 3 1 1 1 1 2 1 1 2
## 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
## 2 1 1 1 1 1 2 2 2 1 3 3 1 1 1 2 3 1 2 2
## 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
## 2 1 2 2 1 2 3 1 1 2 1 1 1 3 3 1 3 3 1 2
## 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
## 1 1 1 1 2 1 1 1 2 2 1 2 3 1 3 1 1 3 1 2
## 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
## 1 1 2 1 1 1 1 1 1 1 1 2 2 3 2 1 1 3 1 2
## 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
## 2 3 1 1 1 2 1 3 1 1 2 2 3 1 1 1 1 2 2 3
## 584 585 587 588 589 590 591 592 593 594 595 596 597 599 600 601 602 603 604 605
## 3 2 1 2 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2
## 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
## 1 1 1 1 2 1 1 1 3 1 3 1 1 3 1 1 3 2 1 1
## 626 627 628 629 630 632 633 634 635 636 637 638 639 641 642 643 644 645 646 647
## 2 1 2 1 1 1 2 1 1 1 2 3 1 2 2 1 2 2 1 2
## 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
## 1 3 1 1 1 1 2 1 3 2 1 1 1 2 2 3 1 1 1 3
## 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
## 1 1 2 1 2 3 3 2 1 1 2 1 2 1 1 2 1 1 1 2
## 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
## 1 1 1 3 3 1 2 2 1 2 3 2 1 1 3 3 3 3 1 1
## 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 726 727 728
## 2 2 1 1 3 1 1 2 1 2 1 1 1 2 2 2 3 3 2 2
## 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
## 1 2 2 2 3 2 2 1 3 3 2 1 2 1 1 1 3 1 1 1
## 749 750 751 752 753
## 2 3 1 3 1
##
## Within cluster sum of squares by cluster:
## [1] 385.7294 385.2719 296.2389
## (between_SS / total_SS = 52.2 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault" "data"
## [11] "hclust"
As we can see the ratio of between SS and total SS is 52.2% which means there is a sufficient difference between the clusters
fviz_cluster(K_MEANS,
palette = "jama",
repel = FALSE,
ggtheme = theme_classic())
mydataM$ClusterK_Means <- K_MEANS$cluster
head(mydataM[c("exp_z", "educw_z", "educh_z")])
## exp_z educw_z educh_z
## 1 0.4389349 -0.157848 -0.1915108
## 2 -0.7031134 -0.157848 -1.2106216
## 3 0.5658292 -0.157848 -0.1915108
## 4 -0.5762192 -0.157848 -0.8709180
## 5 -0.4493249 0.750235 -0.1915108
## 6 2.8499258 -0.157848 -0.5312144
table(mydataM$ClusterWard)
##
## 1 2 3
## 384 272 89
table(mydataM$ClusterK_Means)
##
## 1 2 3
## 315 242 188
table(mydataM$ClusterWard, mydataM$ClusterK_Means)
##
## 1 2 3
## 1 289 7 88
## 2 26 234 12
## 3 0 1 88
Interpretation of the second row and the second column: The number of observations in the second cluster according to hierarchical method was 234 but it received 7 observations from Cluster 1 as a part of reclassification in the K Means method and 1 observation from cluster 3, now it has 242 observations
Centroids <- K_MEANS$centers
Centroids
## exp_z educw_z educh_z
## 1 -0.6306024 -0.5225226 -0.5765082
## 2 -0.1562097 0.9134648 1.0943095
## 3 1.2576729 -0.3003397 -0.4426746
library(ggplot2)
library(tidyr)
Figure <- as.data.frame(Centroids)
Figure$id <- 1:nrow(Figure)
Figure <- pivot_longer(Figure, cols = c("exp_z", "educw_z", "educh_z"))
Figure$Groups <- factor(Figure$id,
levels = c(1, 2, 3),
labels = c("1", "2", "3"))
Figure$nameFactor <- factor(Figure$name,
levels = c("exp_z", "educw_z", "educh_z"),
labels = c("exp_z", "educw_z", "educh_z"))
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(-3, 3)
H1: At least one mean is different
We reject H0(p<0.001) and can say at least one mean is significantly different
H1: At least one mean is different
We reject H0(p<0.001) and can say at least one mean is significantly different
H1: At least one mean is different
We reject H0(p<0.001) and can say at least one mean is significantly different
fit <- aov(cbind(exp_z, educw_z, educh_z) ~ as.factor(ClusterK_Means),
data = mydataM)
summary(fit)
## Response 1 :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 2 428.54 214.268 503.98 < 2.2e-16 ***
## Residuals 742 315.46 0.425
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response 2 :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 2 304.89 152.446 257.6 < 2.2e-16 ***
## Residuals 742 439.11 0.592
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response 3 :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 2 431.33 215.666 511.8 < 2.2e-16 ***
## Residuals 742 312.67 0.421
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
aggregate(mydataM$income,
by = list(mydataM$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 19671.37
## 2 2 29865.62
## 3 3 20576.43
fit <- aov(income ~ as.factor(ClusterK_Means),
data = mydataM)
summary(fit)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 2 1.597e+10 7.984e+09 62.77 <2e-16 ***
## Residuals 742 9.438e+10 1.272e+08
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
H0: Mean(income Cluster 1) = Mean(income Cluster 2) = Mean(income Cluster 3)
H1: At least one mean is different
We reject H0(p<0.001) and can say at least one mean is significantly different and as a result, we are able to validate our analysis using income
aggregate(mydataM$Children,
by = list(mydataM$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 1.8761905
## 2 2 1.7479339
## 3 3 0.9521277
fit <- aov(Children ~ as.factor(ClusterK_Means),
data = mydataM)
summary(fit)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 2 108.2 54.12 27.16 4.13e-12 ***
## Residuals 742 1478.4 1.99
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
H0: Mean(children Cluster 1) = Mean(children Cluster 2) = Mean(children Cluster 3)
H1: At least one mean is different
We reject H0(p<0.001) and can say at least one mean is significantly different and as a result, we are able to validate our analysis using income
chisq_results <- chisq.test(mydataM$city, as.factor(mydataM$ClusterK_Means))
chisq_results
##
## Pearson's Chi-squared test
##
## data: mydataM$city and as.factor(mydataM$ClusterK_Means)
## X-squared = 19.155, df = 2, p-value = 6.926e-05
H0: There is no association between between whether the family stays in a city and cluster
H1: There is an association
We reject H0(p<0.001) and can say there is an association between whether the family stays in a city and cluster and as a result, we are able to validate our analysis using whether the family stays in a city
round(chisq_results$expected, 2)
##
## mydataM$city 1 2 3
## no 111.62 85.76 66.62
## yes 203.38 156.24 121.38
round(chisq_results$res, 2)
##
## mydataM$city 1 2 3
## no 1.55 -2.89 1.27
## yes -1.15 2.14 -0.94
The number of families not staying in a city in Cluster 2 is significantly less than expected while the number of families staying in the city is significantly more than expected
Opposite for Clusters1, 3
Group 1(315/745=42%): Largest group, Having lowest education levels of husband and wife along with lowest years of wife’s work experience, hence having the lowest income
Group 2(242/745=32.5%): Second largest group, having about average number of years of wife’s work experience, but highest educational levels of husband and wife, hence having the highest income
Group 3(188/745=25.5%): Smallest group, having highest years of wife’s work experience but below average education levels of husband and wife, hence having more income than group 1 but less than group 2