To do this week.

Tuesday. –  MDS o análisis multidimensional en  R.

I´m gonna let you the scrip for classical multidimensional analysis (MDS).

We are going to work with the classic data of euro distances and the data of the euro cities.

data(eurodist)
library(stats)
datos<-ciudad
Xfull<-cmdscale(datos, k=10, eig=TRUE, add=FALSE, x.ret=FALSE) #we make sure that B is not a positive semi define
X<-cmdscale(datos, k=2, eig=TRUE, add=FALSE, x.ret=FALSE)
X
x=X$points[,1]
y=X$points[,2]
plot(x, -y, type=”n”, xlab=””, ylab=””, main=”cmdscale(ciudad)”)
text(x, y, rownames(X$points), cex=0.8)

# Results

X
$points
[,1] [,2]
Athens 2290.274680 1798.80293
Barcelona -825.382790 546.81148
Brussels 59.183341 -367.08135
Calais -82.845973 -429.91466
Cherbourg -352.499435 -290.90843
Cologne 293.689633 -405.31194
Copenhagen 681.931545 -1108.64478
Geneva -9.423364 240.40600
Gibraltar -2048.449113 642.45854
Hamburg 561.108970 -773.36929
Hook of Holland 164.921799 -549.36704
Lisbon -1935.040811 49.12514
Lyons -226.423236 187.08779
Madrid -1423.353697 305.87513
Marseilles -299.498710 388.80726
Milan 260.878046 416.67381
Munich 587.675679 81.18224
Paris -156.836257 -211.13911
Rome 709.413282 1109.36665
Stockholm 839.445911 -1836.79055
Vienna 911.230500 205.93020

$eig
[1] 1.953838e+07 1.185656e+07 1.528844e+06 1.118742e+06 7.893472e+05 5.816552e+05
[7] 2.623192e+05 1.925976e+05 1.450845e+05 1.079673e+05 5.139484e+04 -3.259629e-09
[13] -9.496124e+03 -5.305820e+04 -1.322166e+05 -2.573360e+05 -3.326719e+05 -5.162523e+05
[19] -9.191491e+05 -1.006504e+06 -2.251844e+06

$x
NULL

$ac
[1] 0

$GOF
[1] 0.7537543 0.8679134 (the 2 dimensions explain the 86% of the distances)

Here is the plot

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s