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.
eigenvalue percentage of variance cumulative percentage of variance
dim 1 0.3292 14.6320 14.6320
dim 2 0.3089 13.7288 28.3608
dim 3 0.2884 12.8197 41.1805
dim 4 0.2628 11.6819 52.8624
dim 5 0.2512 11.1647 64.0270
dim 6 0.2259 10.0412 74.0683
dim 7 0.2073 9.2155 83.2838
dim 8 0.2004 8.9080 92.1918
dim 9 0.1757 7.8082 100.0000
sum(student_mca$eig[, 1])
[1] 2.25
Problem 2
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:
eigenvalue percentage of variance cumulative percentage of variance
dim 1 0.207 20.712 20.712
dim 2 0.085 8.477 29.189
dim 3 0.075 7.528 36.717
dim 4 0.061 6.146 42.863
dim 5 0.060 6.000 48.862
# % of inertia explained by the first two dimensionshobbies_mca$eig[2, 3]
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.
eigenvalue percentage of variance cumulative percentage of variance
dim 1 0.207 20.712 20.712
dim 2 0.085 8.477 29.189
dim 3 0.075 7.528 36.717
dim 4 0.061 6.146 42.863
dim 5 0.060 6.000 48.862
# Top 10 contribution plotsm1 <-fviz_contrib(hobbies_mca, choice ='var', axes =1, top =10) +scale_x_discrete(limits = rev) +coord_flip() +labs(x ='', title ='Dimension 1') +theme_classic(base_size =13)m2 <-fviz_contrib(hobbies_mca, choice ='var', axes =2, top =10) +scale_x_discrete(limits = rev) +coord_flip() +labs(x ='', title ='Dimension 2') +theme_classic(base_size =13)m1 + m2 +plot_annotation(title ='Top 10 category contributions')
# Top 10 contributions with coordinates (sign = side of axis)contrib_table <-function(dim) {data.frame(Category =rownames(hobbies_mca$var$contrib),ctr = hobbies_mca$var$contrib[, dim],coord = hobbies_mca$var$coord[, dim] ) %>%arrange(desc(ctr)) %>%head(10) %>%mutate(across(where(is.numeric), \(x) round(x, 3)))}contrib_table(1)
Dimension 1 measures overall hobby activity. Doing active hobbies (Exhibition, Show, Cinema, Travelling, Computer, Sport, and Playing music, all positive), against not listening to music, reading, or going to the cinema, so it separates active people from inactive ones. Dimension 2 contrasts do at home hobbies with going out. It is a lot of Gardening, followed by Knitting, Mechanics, Fishing, Cooking, and Walking on the positive side, with Cinema on the negative side. It separates people with outdoor hobbies from people whose hobby is going to the movies.
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.
The plot shows only position, not importance, so rare categories like ages 85-100 look influential despite contributing nothing to the axes, and it captures only 29% of the total inertia.
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:
What does this plot suggest about the relationships between hobbies, age, marital status, and sex? Credit will be awarded proportional to thoroughness of response.
Age follows a clear path across the plot, young (15–25) and single people sit near the going out hobbies (Cinema, Computer, Show), middle-aged people (45–65), along with married and remarried people, sit near at home based hobbies (Knitting, Gardening, Fishing), and the oldest groups (75–100) and widowers sit near inactivity (Listening music_0). Marital status therefore largely mirrors age, since being single, married, or widowed tends to go with being young, middle-aged, or older. Sex sits almost exactly at the origin, which suggests men and women differ very little in their overall hobby patterns compared with the strong differences by age and life stage.
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?
eigenvalue percentage of variance cumulative percentage of variance
dim 1 0.124 12.375 12.375
dim 2 0.102 10.215 22.590
dim 3 0.077 7.681 30.271
dim 4 0.068 6.812 37.083
dim 5 0.065 6.525 43.608
The upper-right quadrant holds cabin scenes (Cabin, Structure, Fence, Sun), and the upper-left holds summer meadow scenes (Flowers, Deciduous trees, Grass, River). The lower-left holds waterfall and rocky-stream scenes (Waterfall, Rocks, Bushes, Cumulus clouds), and the lower-right holds classic mountain-lake scenes (Snowy Mountain, Conifer, Lake, Cirrus clouds). The winter paintings (Winter, Snow) sit on the far right of Dimension 1 with the cabins and fences, while the summer paintings sit in the upper left, on the opposite side of Dimension 1.
B)
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.