1. Multidimensional scaling, cmdscale
fit <-cmdscale(eurodist,eig=TRUE, k=2)
x<-fit$points[,1]
y<-fit$points[,2]
plot(x,y,xlab="Coordinate 1",ylab="Coordinate 2",
main="Metric MDS", type="n")
text(x, y, labels = names(x), cex=0.9)
2. Multidimensional scaling, cmdscale spiral
z=c(1:100)*0.124
x1<-LifeCycleSavings[,1]
z1<-(x1-min(x1))/(max(x1)-min(x1))
x2<-LifeCycleSavings[,2]
z2<-(x2-min(x2))/(max(x2)-min(x2))
x3<-LifeCycleSavings[,3]
z3<-(x3-min(x3))/(max(x3)-min(x3))
x4<-LifeCycleSavings[,4]
z4<-(x4-min(x4))/(max(x4)-min(x4))
z<-cbind(z1,z2,z3,z4) # standardized data form, rows are features
rownames(z)<-rownames(LifeCycleSavings)
colnames(z)<-colnames(LifeCycleSavings)[1:4]
dz<-dist(z)
fitz<-cmdscale(dz,eig=TRUE, k=2)
x<-fitz$points[,1]
y<-fitz$points[,2]
plot(x, y, xlab="Coordinate 1",ylab="Coordinate 2", main="Metric MDS", type="n")
text(x, y, labels = names(x), cex=0.7)
4. Locally linear embedding I
library("lle")
data("lle_scurve_data")
X<-lle_scurve_data
ck<-calc_k( X, 2, 1, 15 )
5. Locally linear embeding II
library("lle")
z=c(1:100)*0.124
x=cos(z)
6. Locally linear embedding III
X<-lle_scurve_data
lle1<-lle(X, m=2, k=5, reg = 2, ss = FALSE, p = 0.5, id = FALSE, v=0.99)
plot(x1,x2)
plot(x1,x3)
plot(x2,x3)
plot(lle1$Y)
7. ISOMAP I
m01=c(1,0,0,0,0,0)
m02=c(0,1,0,0,0,0)
m03=c(0,0,1,0,0,0)
m04=c(0,0,0,1,0,0)
m05=c(0,0,0,0,1,0)
m06=c(0,0,0,0,0,1)
m07=c(0,0,0,0,1,1)
m08=c(0,0,0,1,1,0)
m09=c(0,0,1,1,0,0)
m10=c(0,1,1,0,0,0)
m11=c(1,1,0,0,0,0)
m12=c(1,1,1,0,0,0)
m13=c(0,1,1,1,0,0)
m14=c(0,0,1,1,1,0)
m15=c(0,0,0,1,1,1)
mat=rbind(m01,m02,m03,m04,m05,m06,m07,m08,m09,m10,m11,m12,m13,m14,m15)
dmat<-data.frame(mat)
library(vegan)
library(calibrate)
vdis<-vegdist(dmat)
ord<-isomap(vdis, k=4, epsilon=1)
plot(ord[[1]],type="ol")
x1<-ord[[1]][,1]
x2<-ord[[1]][,2]
textxy(x1,x2,labs=labels(mat)[[1]],cex=1.2)
8. ISOMAP II
library(vegan)
library(calibrate)
X<-USArrests
X1<-X[1:30,]
vdist<-vegdist(X1)
ord<-isomap(vdist, epsilon=1)
plot(ord, main="isomap k=1")
x1<-ord[[1]][,1]
x2<-ord[[1]][,2]
textxy(x1,x2,labs=labels(X1)[[1]],cex=1.1)