asadoughi / stat-learning

Notes and exercise attempts for "An Introduction to Statistical Learning"
http://asadoughi.github.io/stat-learning
2.12k stars 1.62k forks source link

Ch10 Ex7 #105

Open actuarialcat opened 4 years ago

actuarialcat commented 4 years ago

The question require us to scale each observation to have mean 0 and SD 1, not each predictor, in order to produce the desire proportionality.

Suggested answer:

data(USArrests)

scale_data = scale(t(USArrests))

correalation = cor(scale_data) corr.1.minus.r = 1 - as.dist(correalation)

distance.squared = dist(t(scale_data), method = "euclidean") ^ 2

summary(corr.1.minus.r/distance.squared)