##################################################################################### # # The sales performance data # # Source: David Hitchcock's Applied Multivariate Statistics course. # David is Associate Professor of Statistics, Department of Statistics # University of South Carolina, Columbia, SC. # http://www.stat.sc.edu/~hitchcock/stat530.html # http://www.stat.sc.edu/~hitchcock/chapter8_R_examples.txt # # Variables: # X1 = Sales growth # X2 = Sales profitability # X3 = New account sales # X4 = Creativity Test # X5 = Mechanical Reasoning Test # X6 = Abstract Reasoning Test # X7 = Mathematics Test # X8 = Historical Facts Test # X9 = Sports Trivia Test # X10 = Music Trivia Test # ##################################################################################### install.packages("GGally") install.packages("CCA") library(GGally) library(CCA) salesdata = read.table("http://www.stat.sc.edu/~hitchcock/salesmat.txt", header=T) attach(salesdata) X = cbind(x1,x2,x3) Y = cbind(x4,x5,x6,x7,x8,x9,x10) # scatterplot Y ggpairs(Y) # scatterplot X ggpairs(X) # correlations matcor(X,Y) # Ajustando modelo de correlacoes canonicas # ----------------------------------------- fit = cc(X,Y) # correlacoes canonicas fit$cor # pesos canonicos fit$ycoef fit$xcoef # Variaveis canonicas A = X%*%fit$xcoef B = Y%*%fit$ycoef par(mfrow=c(1,3)) plot(A[,1],B[,1],xlab="1a variavel canonica (X)",ylab="1a variavel canonica (Y)") title(paste("1a correlacao canonica=",round(fit$cor[1],4),sep="")) plot(A[,2],B[,2],xlab="2a variavel canonica (X)",ylab="2a variavel canonica (Y)") title(paste("2a correlacao canonica=",round(fit$cor[2],4),sep="")) plot(A[,3],B[,3],xlab="3a variavel canonica (X)",ylab="3a variavel canonica (Y)") title(paste("3a correlacao canonica=",round(fit$cor[3],4),sep="")) # Cargas canonicas CCXA=cor(X,A) CCYB=cor(Y,B) round(CCXA,3) round(CCYB,3) # Determinação da % da variância explicada pelas componentes CCYB^2 CCXA^2 # Determinação das cargas cruzadas cor(Y,A) cor(X,B)