beer | rating | origin | avail | price | cost | calories | sodium | alcohol | light |
---|---|---|---|---|---|---|---|---|---|
Olympia Gold Light | Fair | USA | Regional | 2.75 | 0.46 | 72 | 6 | 2.9 | LIGHT |
Pabst Extra Light | Fair | USA | National | 2.29 | 0.38 | 68 | 15 | 2.3 | LIGHT |
Schlitz Light | Fair | USA | National | 2.79 | 0.47 | 97 | 7 | 4.2 | LIGHT |
Blatz | Fair | USA | Regional | 1.79 | 0.30 | 144 | 13 | 4.6 | NONLIGHT |
Hamms | Fair | USA | Regional | 2.59 | 0.43 | 136 | 19 | 4.4 | NONLIGHT |
Heilmans Old Style | Fair | USA | Regional | 2.59 | 0.43 | 144 | 24 | 4.9 | NONLIGHT |
Rolling Rock | Fair | USA | Regional | 2.15 | 0.36 | 144 | 8 | 4.7 | NONLIGHT |
Scotch Buy (Safeway) | Fair | USA | Regional | 1.59 | 0.27 | 145 | 18 | 4.5 | NONLIGHT |
St Pauli Girl | Fair | Germany | Regional | 4.59 | 0.77 | 144 | 21 | 4.7 | NONLIGHT |
Tuborg | Fair | USA | Regional | 2.59 | 0.43 | 155 | 13 | 5.0 | NONLIGHT |
δ(Blatz,Tbrg)= ⎷5∑h=1(Blatzh−Tbrgh)2 Both the notation δij and δ(i,j) will be used interchangeably
To obtain the distance matrix in R
filter(Beer,rating=='Fair')%>% #Only fair beers select_if(is.numeric)%>% #Only metric data scale%>% #Standardise dist->delta #Distancefilter(Beer,rating=='Fair')%>% #Only fair beers pull(beer)%>% #Get beer names abbreviate(6)-> #Abbreviate attributes(delta)$Labels #Assign to d
We can do what is known as classical MDS in R using the cmdscale
function
mdsout<-cmdscale(delta)
OlymGL | -1.9758212 | -1.6276821 |
PbstEL | -2.1860282 | -1.1600914 |
SchltL | -0.7420968 | -0.7994497 |
Blatz | -0.3386684 | 1.4929936 |
Hamms | 0.6053483 | 0.2720245 |
HlmnOS | 1.3641181 | 0.6556403 |
RllngR | -0.2932490 | 0.9661501 |
SB(Sf) | -0.2067650 | 1.7951323 |
StPlGr | 2.9648884 | -2.2976842 |
Tuborg | 0.8082737 | 0.7029665 |
d(Blatz,Tbrg)=√(−0.339−0.808)2+(1.493−0.703)2
d(Blatz,Tuborg)≠δ(Blatz,Tuborg)
mdsout%>% as_tibble%>% ggplot(aes(x=V1,y=V2))+geom_point()
mdsout%>% as_tibble(rownames='BeerName')%>% ggplot(aes(x=V1,y=V2,label=BeerName))+geom_text()
Strain=n−1∑i=1∑j>i(δ2ij−d2ij)
Strain=n−1∑i=1∑j>i(δ2ij−d2ij)
Cairns | Brisbane | Sydney | Melbourne | Adelaide | Perth | Darwin | Alice Springs | |
---|---|---|---|---|---|---|---|---|
Cairns | 0 | 1717 | 2546 | 3054 | 3143 | 5954 | 2727 | 2324 |
Brisbane | 1717 | 0 | 996 | 1674 | 2063 | 4348 | 3415 | 3012 |
Sydney | 2546 | 996 | 0 | 868 | 1420 | 4144 | 4000 | 2644 |
Melbourne | 3054 | 1674 | 868 | 0 | 728 | 3452 | 3781 | 2270 |
Adelaide | 3143 | 2063 | 1420 | 728 | 0 | 2724 | 3053 | 1542 |
Perth | 5954 | 4348 | 4144 | 3452 | 2724 | 0 | 4045 | 3630 |
Darwin | 2727 | 3415 | 4000 | 3781 | 3053 | 4045 | 0 | 1511 |
Alice Springs | 2324 | 3012 | 2644 | 2270 | 1542 | 3630 | 1511 | 0 |
eig=TRUE
in the cmdscale
functioneig=TRUE
in the cmdscale
functionmdsout<-cmdscale(delta,eig=TRUE)str(mdsout$GOF)
## num [1:2] 0.854 0.854
cmdscale(doz,eig=TRUE)->dozoutstr(dozout$eig)
## num [1:8] 1.97e+07 1.25e+07 2.62e+06 5.96e+04 -3.26e-09 ...
str(dozout$eig[6:8])
## num [1:3] -311786 -1083294 -2179888
str(dozout$GOF)
## num [1:2] 0.837 0.923
The following example comes from ‘Multidimensional Scaling of Sorting Data Applied to Cheese Perception’, Food Quality and Preference,6, pp.91-98. The purpose of this study was to visualise the difference between types of cheese.
Stress=n−1∑i=1∑j>i(δij−dij)2δij
Stress=n−1∑i=1∑j>i(δij−dij)2δij
Stress=n−1∑i=1∑j>i(δij−dij)2δij
isoMDS
function from the MASS
package.library(MASS)isoMDS(d)->kBeer
## initial value 9.127089 ## iter 5 value 5.688460## final value 5.611143 ## converged
kBeer$points%>% as_tibble()%>% ggplot(aes(x=V1,y=V2))+ geom_point(size=10)
isoMDS(d^2)->kBeer2
## initial value 11.274285 ## iter 5 value 6.447929## iter 10 value 5.697285## final value 5.603035 ## converged
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |