# Aufgabe 1 o<-read.table("Desktop/olives.txt",TRUE) attach(o) m<-data.frame(stearic=min(stearic),oleic=min(oleic)) for (i in min(stearic)+0:30/30*(max(stearic)-min(stearic))) for (j in min(oleic)+0:30/30*(max(oleic)-min(oleic))) m<-rbind(m,c(i,j)) l<-lda(Region~stearic+oleic) pc<-predict(l,m)$class plot(stearic,oleic,col=unclass(Region)) points(m,col=as.integer(pc),pch=3) # Aufgabe 2 q<-qda(Region~stearic+oleic) table(predict(l)$class, Region) table(predict(q)$class, Region) plot(stearic,oleic,col=unclass(Region)) points(m,col=as.integer(predict(q,m)$class),pch=3) ccr.lda<-sum(predict(l)$class==Region)/length(Region) ccr.qda<-sum(predict(q)$class==Region)/length(Region) #Aufgabe 3 x <- c(0,1,1,0,0,1,1,0) y <- c(0,0,1,1,0,0,1,1) z <- c(0,0,0,0,1,1,1,1) m <- matrix(c(x,y,z),,3) e<-c(1:4,1,5:8,4,8,5,6,2,6,7,3) cs<-cmdscale(dist(m)) plot(cs) lines(cs[e,]) cs<-sammon(dist(m))$points plot(cs) lines(cs[e,]) cs<-isoMDS(dist(m))$points plot(cs) lines(cs[e,]) ###xtra: # cs<-isoMDS(dist(m),cbind(runif(8),runif(8)))$points # plot(cs) # lines(cs[e,]) m<-as.matrix(o[3:10]) cs<-sammon(dist(t(m))) plot(cs$points) text(cs$points,names(o[3:10])) nd <- function(x) (x-mean(x))/sd(x) # Aufgabe 4 crabs <- read.table("Desktop/crabs.txt",TRUE) attach(crabs) nc<-crabs for (i in 4:8) nc[i]<-nd(nc[i]) m<-nc[4:8] cs<-isoMDS(dist(m))$points plot(cs,col=sp-1+2*(sex-1)+1) cs<-isoMDS(dist(m),cbind(runif(200),runif(200)),maxit=100)$points plot(cs,col=sp-1+2*(sex-1)+1) cs<-isoMDS(dist(m),cbind(runif(200)+c(rep(-5,100),rep(5,100)),runif(200)+c(rep(-5,50),rep(5,50),rep(-5,50),rep(1,50))))$points plot(cs,col=sp-1+2*(sex-1)+1) # Aufgabe 5 km<-kmeans(crabs[4:8], 4) pairs(crabs[4:8], col=km$cluster, pch=sp-1+2*(sex-1)+1) pc<-as.data.frame(predict(princomp(crabs[4:8]))) km<-kmeans(pc[2:3],4) pairs(crabs[4:8], col=km$cluster, pch=sp-1+2*(sex-1)+1) pairs(pc[1:3], col=km$cluster, pch=sp-1+2*(sex-1)+1)