data = read.table("vinho.txt",header=TRUE) attach(data) summary(data) boxplot(data) plot(Aroma,Corpo) plot(Aroma,Sabor) plot(Corpo,Sabor) corAC = round(cor(Aroma,Corpo),4) corAS = round(cor(Aroma,Sabor),4) corCS = round(cor(Corpo,Sabor),4) L=min(data) U=max(data) par(mfrow=c(1,3)) plot(Aroma,Corpo,main=corAC,xlim=c(L,U),ylim=c(L,U)) plot(Aroma,Sabor,main=corAS,xlim=c(L,U),ylim=c(L,U)) plot(Corpo,Sabor,main=corCS,xlim=c(L,U),ylim=c(L,U)) # calculando distancias de Mahalanobis # ------------------------------------ pairs(data) x = cbind(Aroma,Corpo,Sabor) n = nrow(x) xbar = apply(x,2,mean) S = var(x) iS = solve(S) dist = x-matrix(xbar,n,3,byrow=TRUE) Dm = diag(dist%*%iS%*%t(dist)) pval = round(1-pchisq(Dm,3),4) rDm = round(sqrt(Dm),2) par(mfrow=c(1,1)) plot(Dm,xlab="Observation",ylab="Mahalanobis distance") abline(h=qchisq(0.95,3),col=2,lwd=2) abline(h=qchisq(0.99,3),col=4,lwd=2) abline(h=qchisq(0.999,3),col=6,lwd=2) legend(10,20,c("Cut-off for 5% level","Cut-off for 1% level","Cut-off for 0.1% level"), col=c(2,4,6),bty="n",lwd=2) data[c(6,38,39),] # Aroma Corpo Sabor #6 4.3 5.5 3.5 #38 7.7 6.6 6.7 #39 7.7 2.6 2.5