关键词 > STAT3064/STAT5061

STAT3064/STAT5061 Statistical Learning/Statistical Data Science Computer Lab 5

发布时间:2022-09-06

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

STAT3064/STAT5061 Statistical Learning/Statistical Data Science

Computer Lab 5, Semester 2 2022

Things you may need to know/do.

●  Reed and study the separate material, called Notes on Lecture 5 and Lab 5 – More on Canonical Correlations’ before you start the lab. You can nd this material in the Lecture Slides and Chapters folder on LMS. The notes describe how we calculate the Canonical Correlation Matrix C, which is introduced in the Lecture 5 Slides. This matrix and its decomposition shown in Box 7.2 will be relevant in Lab 5 and Lab 6 and also in the next assignment.

  Relates to lecture 5.

●  Libraries ggplot2, MASS, tidyverse, GGally may be useful.  Others may be mentioned below in the hints.

● You might like to set up a project for each lab if you are using RStudio. Then you can copy a .Rmd file into that directory and write your answers in that le.

Q1

Consider the aircraft data with the variables Period, Year and the six logged variables logPower, logSpan, logLength, logWeight, logSpeed, logRange .  We split the six logged variables into two parts and then perform a Canonical Correlation Analysis in order to nd the strongest correlation between the two parts of the data.

Before doing anything else, centre the logged variables in a new dataframe. Continue with the centred data in the calculations in Q1 and Q2 below. Keep the names of the variables the same, though .  (Hint: to centre the data you can make use of the following shown selectively only)

aircraft .centred  =  mutate(  aircraft,

logSpan  =  logSpan  - mean (  logSpan  )

)

(Hint: you may want to rearrange your centred data so you can split it more easily into the two parts as follows)

air .rearranged  =  dplyr ::select  (aircraft .centred,

logSpan,

logLength,

logWeight,

logPower,

logSpeed,

logRange  )

#  need  dplyr::  because  otherwise  MASS  hides  this  function

(a)  Let X [1]   be all observations with variables  logSpan,  logLength,  logWeight,  and let X [2]   be all observations with variables logPower, logSpeed, logRange . What aspect of the data does this split of the variables correspond to?  (Hint: you can adjust the above expression to get X [1]  and X [2] .)

(b)  Calculate and show the between sample covariance matrix for these data.

(c) Which single variable from X [1]  and which single variables from X [2]  results in the highest absolute correlation and what is this value? Show a scatter plot of the best’ (that is highest absolute correlation) single pair.  (Hint: we do not want comparisons as produced by pairs, but only want to compare each variable of X [1]  with each variable of X [2] .)

(d)  For this part you will need the additional material provided with this lab and the code

 = S1(−)1/2S12 S1/2

Use the spectral decomposition from Chapter 2 to calculate S1(−)1/2  and nally calculate  as the product of the three matrices.

(e)  Calculate the singular values of  and list them.

(f)  Calculate and display the CC score plots of all three pairs of CC scores. Use cancor for the calculations,

create a dataframe of the CC scores then plot them. Comment on the plots.  (Hint: the code chunk below is an example only and is not complete)

CCA  =  cancor (  X1,  X2  )

CCA

X1mat  =  as .matrix (  X1,  ncol  =  3  )  #  change  the  class  to  matrix

U  =  X1mat  %*%  CCA$xcoef

dimnames (  U  )[[2]]  =  paste0(  "CCx . " ,  1 :3  )

Q2

We consider the aircraft data of Q1, but now split the variables in the following way. Take X [1]  to be the variables logSpan, logLength, logWeight, logPower, and take the variables logSpeed, logRange as X [2] . Repeat parts (b) – (e ) for this combination of X [1]  and X [2]  and compare the strength of the correlations

obtained in Q2 with those obtained in Q1.

Q3

Consider the Boston Housing data which is available in the Data Set folder. Beware that the data are tsv (and not csv) despite the name. Use the split of the variables into X [1]  and X [2]  as in Table 6.3 of Chapter 6.

(a)  Repeat the calculations shown in Example 6.6, list the values of the correlations and show the four CC score plots. Why is the correlation in the rst plot so high?

(b)  Calculate a PCA of the X [1]  data. Use the rst 5-dimensional PC-data as the new X [1]  data, and the X [2]  of part (a). Repeat (a) for these data.

(c)  Compare the results of part (a) and (b) and comment.