glasses <- na.omit(glasses[,-1])
n <- nrow(glasses)
p <- ncol(glasses)
col <- rep("black",n)
col[glasses[,1] == 2] <- "red"
col[glasses[,1] == 3] <- "green"
lab <- rep("M",n)
lab[glasses[,1] == 1] <- "V"
lab[glasses[,1] == 2] <- "R"
lab1 <- paste(lab,1:n,sep="")
pc <- princomp(glasses[,-1],cor=TRUE)
summary(pc)
plot(scale(pc$scores[,1]), scale(pc$scores[,2]), pch=20, xlab="PC1 (36)",
ylab="PC2 (28)", main="Roman Venetian Glasses Data")
text(scale(pc$scores[,1]), scale(pc$scores[,2]), labels=lab1, cex=0.6,
pos=3, col=col)
abline(h=0, v=0, lty="dashed", col="grey")
plot(scale(pc$scores[,1]), scale(pc$scores[,3]), pch=20, xlab="PC1 (36)",
ylab="PC3 (11)", main="Roman Venetian Glasses Data")
text(scale(pc$scores[,1]), scale(pc$scores[,3]), labels=lab1, cex=0.6,
pos=3, col=col)
abline(h=0, v=0, lty="dashed", col="grey")
plot(scale(pc$scores[,2]), scale(pc$scores[,3]), pch=20, xlab="PC2 (28)",
ylab="PC3 (11)", main="Roman Venetian Glasses Data")
text(scale(pc$scores[,2]), scale(pc$scores[,3]), labels=lab1, cex=0.6,
pos=3, col=col)
abline(h=0, v=0, lty="dashed", col="grey")
set.seed(1234)
err1 <- rnorm(n,0,sd(glasses[,2])/100)
err2 <- rnorm(n,0,sd(glasses[,3])/100)
err3 <- rnorm(n,0,sd(glasses[,4])/100)
err4 <- rnorm(n,0,sd(glasses[,5])/100)
err5 <- rnorm(n,0,sd(glasses[,6])/100)
err6 <- rnorm(n,0,sd(glasses[,7])/100)
err7 <- rnorm(n,0,sd(glasses[,8])/100)
err8 <- rnorm(n,0,sd(glasses[,9])/100)
err9 <- rnorm(n,0,sd(glasses[,10])/100)
err10 <- rnorm(n,0,sd(glasses[,11])/100)
err11 <- rnorm(n,0,sd(glasses[,12])/100)
err12 <- rnorm(n,0,sd(glasses[,13])/100)
glasses <- glasses[,-1] + data.frame(err1,err2,err3,err4,err5,err6,err7,
err8,err9, err10,err11,err12)
tau <- quantile.localdepth(glasses, probs=c(0.1, 0.9), method='mahalanobis')
gla10 <- localdepth(glasses, tau=tau[1], method='mahalanobis')
gla90 <- localdepth(glasses, tau=tau[2], method='mahalanobis')
plot(gla10)
abline(0, 1, lty=2)
plot(gla90)
abline(0, 1, lty=2)
Run the code above in your browser using DataLab