Part_time_job Major Commute Housing
1 Yes Business Car With family
2 No Arts Bike Off campus
3 No Arts Car Off campus
4 No Science Car On campus
5 Yes Arts Bike Off campus
6 Yes Science Car With family
Perform MCA on this data set, setting ncp= to the number of dimensions you specified in part B. Verify that the sum of the eigenvalues equal your answer to part A.
**Results of the Multiple Correspondence Analysis (MCA)**
The analysis was performed on 200 individuals, described by 4 variables
*The results are available in the following objects:
name description
1 "$eig" "eigenvalues"
2 "$var" "results for the variables"
3 "$var$coord" "coord. of the categories"
4 "$var$cos2" "cos2 for the categories"
5 "$var$contrib" "contributions of the categories"
6 "$var$v.test" "v-test for the categories"
7 "$var$eta2" "coord. of variables"
8 "$ind" "results for the individuals"
9 "$ind$coord" "coord. for the individuals"
10 "$ind$cos2" "cos2 for the individuals"
11 "$ind$contrib" "contributions of the individuals"
12 "$call" "intermediate results"
13 "$call$marge.col" "weights of columns"
14 "$call$marge.li" "weights of rows"
dim eigenvalue
1 dim 1 0.3292198
2 dim 2 0.3088978
3 dim 3 0.2884426
4 dim 4 0.2628430
5 dim 5 0.2512049
6 dim 6 0.2259281
7 dim 7 0.2073488
8 dim 8 0.2004296
9 dim 9 0.1756854
In this problem, we consider the hobbies data set which comes preloaded with the FactoMineR package. The data used here concern a questionnaire on hobbies. 8403 individuals were asked questions about their hobbies, as well as demographic information. Use the following subset of the data, called hobbies_use:
Reading Listening music Cinema Show Exhibition Computer Sport Walking
11000210 1 1 1 1 1 0 1 1
11000410 1 0 0 0 1 0 1 1
11000610 1 1 0 0 1 0 0 0
11000710 1 0 0 0 1 0 1 0
11000810 1 1 1 1 0 0 0 1
11000910 0 0 0 0 0 0 0 0
Travelling Playing music Collecting Volunteering Mechanic Gardening
11000210 1 0 0 1 1 0
11000410 0 0 1 1 1 1
11000610 1 0 0 0 0 0
11000710 1 0 0 0 0 0
11000810 0 0 0 0 0 0
11000910 0 0 0 0 1 0
Knitting Cooking Fishing Sex Age Marital status
11000210 0 0 0 F (55,65] Married
11000410 0 0 0 M (45,55] Married
11000610 0 0 0 F (25,35] Remarried
11000710 0 0 0 M (75,85] Married
11000810 0 0 0 M (55,65] Married
11000910 0 0 0 M (45,55] Married
A)
What percent of the inertia is explained by the first two dimensions?
(hobbies_mca <- hobbies_use%>%MCA(graph =FALSE))
**Results of the Multiple Correspondence Analysis (MCA)**
The analysis was performed on 8403 individuals, described by 20 variables
*The results are available in the following objects:
name description
1 "$eig" "eigenvalues"
2 "$var" "results for the variables"
3 "$var$coord" "coord. of the categories"
4 "$var$cos2" "cos2 for the categories"
5 "$var$contrib" "contributions of the categories"
6 "$var$v.test" "v-test for the categories"
7 "$var$eta2" "coord. of variables"
8 "$ind" "results for the individuals"
9 "$ind$coord" "coord. for the individuals"
10 "$ind$cos2" "cos2 for the individuals"
11 "$ind$contrib" "contributions of the individuals"
12 "$call" "intermediate results"
13 "$call$marge.col" "weights of columns"
14 "$call$marge.li" "weights of rows"
dim eigenvalue percentage.of.variance cumulative.percentage.of.variance
1 dim 1 0.1884281 12.995044 12.99504
2 dim 2 0.1073312 7.402152 20.39720
20.40%
B)
Perform MCA on this data set. For each of the first two dimensions of the MCA, find the top-10 variables contributing to these dimensions. Discuss your findings.
hobbies_mca <-MCA(hobbies_use, ncp =5, graph =FALSE)(fviz_contrib(hobbies_mca, choice ="var", axes =1, top =10)+fviz_contrib(hobbies_mca, choice ="var", axes =2, top =10))
For Dim 1, the top contributors are almost all hobbies….Cinema_1, Show_1, Computer_1, Exhibition_1, Sport_1, Travelling_1, and Playing music_1. The “no” versions (Listening music_0, Cinema_0, Computer_0) are on the other side. So Dim 1 is active vs. inactive people.
Dim 2 is mostly about age and marital status. Single and [15,25] are by far the biggest, around 15% each, which is way more than anything else. Then there’s Knitting_1, Gardening, and Walking, plus some age groups and Married. So Dim 2 splits younger single people from older married people who do more home-type hobbies like gardening and knitting.
C)
Use fviz_mca_var() with repel=TRUE to plot the coordinates of the active variables and supplementary variables. Discuss the shortcomings of this plot.
Some of the shortcomings of this graph is that there are so many labels that it is tough to disect, as well as having both the yes and no version of each variable pop up…which makes doubles the clutter.
D)
Note that the plot from C has too many labels and isn’t doing a good job repelling them even with repel = TRUE. Let’s use ggplot layers to improve this plot; unfortunately this will require some data wrangling to create the data set we need “from scratch.”
Use the MCA() output to create active_df and supp_df, containing the coordinates of the active and supplementary variables, respectively. Keep only the “top 10” levels of the active variables, as measured by the sum-of-squared coordinates. The first 6 rows of each data frame are shown:
level Dim.1 Dim.2 sum_sq_coord category
1 M -0.02387308 -0.04419050 0.002522725 Sex
2 F 0.01958565 0.03625421 0.001697965 Sex
3 [15,25] 0.37173828 -0.87241775 0.899302081 Age
4 (25,35] 0.26667450 -0.32338199 0.175691199 Age
5 (35,45] 0.20477079 -0.01052354 0.042041822 Age
6 (45,55] 0.01785855 0.22042748 0.048907200 Age
7 (55,65] -0.15470944 0.38096000 0.169065535 Age
8 (65,75] -0.44418733 0.29627493 0.285081225 Age
9 (75,85] -0.70206643 0.09105498 0.501188275 Age
10 (85,100] -1.01858200 -0.22662368 1.088867582 Age
11 Single 0.29382920 -0.52163478 0.358438448 Marital status
12 Married -0.05818755 0.21315834 0.048822269 Marital status
13 Widower -0.50773741 0.20769195 0.300933220 Marital status
14 Divorcee -0.02902247 -0.03993476 0.002437089 Marital status
15 Remarried 0.04702282 0.17788562 0.033854439 Marital status
final_plot_df <-bind_rows(active_df, supp_df)(ggplot(final_plot_df, aes(x = Dim.1, y = Dim.2, color = category, label = level))+geom_point()+geom_text_repel(size =3, show.legend =FALSE)+geom_hline(yintercept =0, linetype ="dashed")+geom_vline(xintercept =0, linetype ="dashed")+scale_color_discrete(labels =c("Active variable", "Age", "Marital status", "Sex"))+labs(x ="Dimension 1", y ="Dimension 2", color =NULL)+theme_classic())
E)
What does this plot suggest about the relationships between hobbies, age, marital status, and sex? Credit will be awarded proportional to thoroughness of response.
Dimension 1 (20.7%) mostly measures overall hobby activity, with people on the right doing more outgoing activities like music, shows, exhibitions, and movies, while people on the left tend to do fewer hobbies. Dimension 2 (8.5%) separates home-based hobbies like knitting, gardening, and fishing from entertainment hobbies like movies and computers. Age seems to have the strongest relationship, with younger people leaning toward more outgoing and entertainment hobbies, middle-aged people leaning toward home-based hobbies, and the oldest groups doing fewer hobbies overall. Marital status seems to follow a similar pattern, with single people looking more like younger groups and widowed people looking more like older groups, although this could mostly be due to age. Sex doesn’t seem to have much of a relationship with either dimension since men and women are both very close to the center
Problem 3
On the public television show The Joy of Painting Bob Ross taught people how to paint lovely scenic landscapes consisting of “snowcapped peaks” and “happy little clouds.” This dataset is a table consisting of different elements (e.g. mountain, river, waterfall, etc.) commonly found within in his paintings. Thus each painting can be thought of as survey respondent where they are asked a series of yes (1) or no (0) questions. This data set contains characteristics of paintings created in 316 of the 403 “Joy of Painting” episodes. Note that MCA requires everything to be factors (aka “categorical”) variables, hence the mutate() command below.
Our goal is to understand what elements Ross tended to use together in paintings, and to find representative paintings with various characteristics.
A)
Perform MCA on the data set, and plot the first two dimensions of the variable coordinates. How would you characterize paintings in each of the four quadrants of this plot? Where are the “summer” and “winter” paintings?
Plot the MCA scores, the coordinates of the individual paintings, filtering to paintings that are “most representative” of each quadrant using the cos2 values. From here, Google image search to find one painting that is representative of each quadrant. Include screenshots of these in your submission, along with discussion of how your selected paintings exemplify the quadrant.
# A tibble: 12 × 5
title Dim.1 Dim.2 cos2 quadrant
<chr> <dbl> <dbl> <dbl> <chr>
1 FINAL_GRACE -0.0162 -0.709 0.717 Lower left
2 DOUBLE_OVAL_FANTASY -0.0162 -0.709 0.717 Lower left
3 MOUNTAIN_WATERFALL1 -0.157 -0.719 0.532 Lower left
4 ARCTIC_WINTER_DAY 0.886 -0.359 0.801 Lower right
5 FROZEN_SOLITUDE 0.840 -0.434 0.751 Lower right
6 PERFECT_WINTERS_DAY 0.816 -0.353 0.684 Lower right
7 LAZY_RIVER -0.328 0.373 0.566 Upper left
8 HIDDEN_CREEK -0.328 0.373 0.566 Upper left
9 CYPRESS_CREEK -0.328 0.373 0.566 Upper left
10 WINTER_NIGHT 0.826 0.145 0.699 Upper right
11 SNOWY_MORN 0.826 0.145 0.699 Upper right
12 PURPLE_SPLENDOR 0.850 0.0636 0.698 Upper right
Upper left: - Hidden creek, lazy river, and cypress creek are the top 3 representative paintings. In part A I described his quadrant as summer. I think this creek encapsulates this well.
Upper right: - Snowy morning, winter night. These are close to the D2 origin but strong along D1. I kind of combined the two into a snowy winter night.
Bottom left: - Mountain waterfall. I described this in part a as the water themes.