关键词 > STA437H1S/2005H1S

Assignment #2 STA437H1S/2005H1S

发布时间:2023-02-18

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

Assignment #2 STA437H1S/2005H1S

due Friday February 17, 2023

Instructions: Solutions to problems 1–3 are to be submitted on Quercus (PDF les only).

1. Andrews curves (conceived the University of Toronto’s own David Andrews) represent an interesting approach to multivariate visualization. The idea is to represent each multivariate observation (xi1 , . . . , xip ) (which is possibly normalized) by a sinusoidal function on [0, 1]:

gi (t) =  + xi2 sin(2πt) + xi3 cos(2πt) + xi4 sin(4πt) + xi5 cos(4πt) + . . .

Observations that are similar will have similar Andrews curves while outlying observations will often have curves that are distinctively different.

On Quercus, there is a le andrews .txt, which contains a function andrews that computes Andrews curves for a data matrix whose columns are variables and rows are observations; for example,

>  source("andrews .txt")   #  read  the  function  into  R

>  x  <-  cbind(rnorm(100),rnorm(100),rnorm(100),rnorm(100),rnorm(100))        >  r  <-  andrews(x,scale=T)  #  scales  columns  to have mean  0  and  variance  1

The file testdata .txt contains 100 _ k observations from a 10-variate normal distribution and k outliers generated from another distribution (where k s 15).

(a) Look at the data using Andrews curves. How many clear outliers do there seem to be?

(b) Using the information from the Andrews curves as well as pairwise scatterplots, principal components etc, give an estimate of how many outliers are in the data.

2. (a) If {gi (t)} are the Andrews curves defined in question 1, show that

1                                                  p

2     [gi (t) _ gj (t)]2 dt =      (xik  _ xjk )2 .

0

1  n

(b) If  = n      αi , what is the Andrews curve of ?

(c) Suppose that αk  lies on a line between αi  and αj , that is, αk  = λαi + (1 _ λ)αj  for some 0 < λ < 1. What can you say about the Andrews curve of αk  relative to those of αi  and αj ?

3. In Assignment #1, you looked at two dimensional scatterplots of data on two species of rock crabs; here, you will do a principal components analysis of these data.

As before, the data are in a le crabs .txt on Quercus; the columns of the le are species (B or O), sex (M or F), index (1-50 within each species-sex combination), width of the frontal lip (LP), the rear width of the shell (RW), length along the midline of the shell (CL), the

maximum width of the shell (CW), and the body depth (BD).

The data can be read into R using the following code:

>  x  <-  scan("crabs .txt",skip=1,what=list("c","c",0,0,0,0,0,0))        >  colour1  <-  ifelse(x[[1]]=="B","blue","orange")  #  species  colours >  colour2  <-  ifelse(x[[2]]=="M","black","red")  #  sex  colours

>  sex  <-  x[[2]]

>  FL  <-  x[[4]]

>  RW  <-  x[[5]]

>  CL  <-  x[[6]]

>  CW  <-  x[[7]]

>  BD  <-  x[[8]]

(a) Using the correlation matrix, do a principal component analysis of the 5 variables.

>  r  <- princomp(~FL+RW+CL+CW+BD,cor=T)

>  summary(r,loadings=T)

Give an interpretation of the rst two principal components based on their loadings.

(b) Look at pairwise scatterplots of the 5 principal components using colour1 to distinguish the two species:

> pairs(r$scores,col=colour1)

Which pairs of principal components seem to separate the two species?

(c) Now look at pairwise scatterplots of the 5 principal components using colour2 to dis- tinguish the two sexes:

> pairs(r$scores,col=colour2)

Which pairs of principal components seem to separate the two sexes?

(d) Suppose you are given the following measurements for the 5 variables:  FL  =  18 .7, RW = 15.0, CL = 35.0, CW = 40.3, BD = 16.6. What is your prediction of the species and sex of this crab?