Going beyond two variables, exploring high dimensions
Author
Prof. Di Cook
🎯 Objectives
These are exercises in plots to make to explore relationships between multiple variables. You will use interactive scatterplot matrices, interactive parallel coordinate plots and tours to explore the world beyond 2D.
Open your RStudio Project for this unit, (the one you created in week 1, ETC5521). Create a .qmd document for this weeks activities.
📥 Exercises
Exercise 1: Melbourne housing
Read in a copy of the Melbourne housing data from Nick Tierney’s github repo which is a collation from the version at kaggle. Its fairly large, so let’s start simply, and choose two suburbs to focus on. I recommend “South Yarra” and “Brighton”.
There are a substantial number of missing values. These need to be handled first because examining multiple variables, with almost every method, requires complete data.
Make a scatterplot matrix of price, rooms, bedroom2, bathroom, suburb, type. The order of variables can affect the readability. I advise that the plot will be easier to read if you order them with the numerical variables first, and then the categorical variables. Think about what associations can be seen?
Solution
ggpairs(mel_houses_knn, columns=c(4,2,10,11,1,3))
Except for price the continuous variables are all discrete. We can still examine the associations. It could be useful to use a jittered scatterplot, but that would require making a special plot function to use in the ggpairs function.
There is positive linear association between price, rooms, bedroom2, bathroom, which indicates the bigger the house the higher the price
From the boxplots: houses in Brighton tend to be higher priced and bigger than South Yarra, and houses tend to be worth more than apartments or units.
From the fluctuation diagram, Brighton tends to have more houses, and South Yarra has more apartments.
From the density plot, price has a skewed distribution.
There is one big outlier, one house sold for a much higher price. There are a few bivariate outliers, houses with a large number of bathrooms but relatively low price.
# To add jitterggpairs(mel_houses_knn, columns=c(4,2,10,11,1,3),lower=list(continuous=wrap("points",position=position_jitter(height=0.3, width=0.3))))
Subset the data to Brighton only. Make an interactive scatterplot matrix of rooms, bedroom2, bathroom and price, coloured by type of property. There are some high price properties. Select these cases, and determine what’s special about them – if anything.
For each of the data sets, c1, …, c7 from the mulgar package, use the grand tour to view and try to identify structure (outliers, clusters, non-linear relationships).
Solution
library(mulgar)animate_xy(c1)# four small clusters, two big clusters# linear dependenceanimate_xy(c2) # Six spherical clustersanimate_xy(c3)# tetrahedron with lots of smaller triangles,# barriers, linear dependenceanimate_xy(c4) # Four linear connected piecesanimate_xy(c5)# Spiral in lower dimensional space# Non-linear and linear dependenceanimate_xy(c6)# Two curved clustersanimate_xy(c7)# spherical cluster, curve cluster and a lot of noise points
👌 Finishing up
Make sure you say thanks and good-bye to your tutor. This is a time to also report what you enjoyed and what you found difficult.