############################ # Passito ############################ # import data Dataset=read.csv("Passito.csv",header=TRUE,sep=";") head(Dataset) dim(Dataset) # keep only the variables (columns) of interest X=Dataset[,17:21] head(X) summary(X) # number of units = number of dataset rows n=dim(X)[1] n # number of columns = dataset columns k=dim(X)[2] k # correlations between observed variables cor(X) # normalization of the k=5 variables (rescaling type transformation) Z=(X-min(X)+1/n)/(max(X)-min(X)+2/n) head(Z) dim(Z) class(Z) # change Z structure from data.frame into matrix Z=as.matrix(Z) class(Z) # define the vector of weights (equal importance of the variables) w=rep(1/k,times=k) w #Fisher combination as product between the matrix of transformed values and #vector of weights yF=-log(1-Z,base=2)%*%w yF summary(yF) # definition of the minimum and maximum value of the composite indicator in order to normalize it (rescaling) ymin=0 range_x=7-1 yFmax=-log(1-(range_x+1/n)/(range_x+2/n),base=2) yFmax #final index normalization yF_norm=(yF-ymin)/(yFmax-ymin) summary(yF_norm) # distribution of the composite indicator hist(yF_norm,freq=FALSE) lines(density(yF_norm), col ="blue", lty = 2, lwd = 2, add = TRUE) hist(yF_norm,freq=FALSE,ylim=c(0,6)) lines(density(yF_norm), col ="blue", lty = 2, lwd = 2, add = TRUE) #Additive combination yA=Z%*%w # graphical comparison between the distributions of the two composite indicators (Fisher combination and additive combination) hist(yA,freq=FALSE,ylim=c(0,6)) lines(density(yA), col ="red", lty = 1, lwd = 2, add = TRUE) lines(density(yF_norm), col ="blue", lty = 2, lwd = 2, add = TRUE) plot(yA,yF_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) # relationship between each partial indicator (normalized variable) and the normalized composite indicator (Fisher combination) plot(Z[,1],yF_norm) plot(Z[,2],yF_norm) plot(Z[,3],yF_norm) plot(Z[,4],yF_norm) plot(Z[,5],yF_norm) cor(Z,yF_norm) ############################ # Mall ############################ X=read.csv("Mall.csv",header=TRUE,sep=";") head(X) dim(X) head(X) summary(X) n=dim(X)[1] n k=dim(X)[2] k cor(X) #normalization of the k=5 variables Z=(X-(-100)+1/n)/(100-(-100)+2/n) head(Z) dim(Z) Z=as.matrix(Z) w=rep(1/k,times=k) w #Liptak combination as product between the matrix of transformed values and #vector of weights yL=qnorm(Z)%*%w range_x=100-(-100) summary(yL) ymin=qnorm((1/n)/(range_x+2/n)) ymin ymax=qnorm((range_x+1/n)/(range_x+2/n)) ymax #final index normalization yL_norm=(yL-ymin)/(ymax-ymin) summary(yL_norm) hist(yL_norm,freq=FALSE) lines(density(yL_norm), col ="blue", lty = 2, lwd = 2, add = TRUE) #Additive combination yA=Z%*%w hist(yA,freq=FALSE) lines(density(yA), col ="red", lty = 1, lwd = 2, add = TRUE) lines(density(yL_norm), col ="blue", lty = 2, lwd = 2, add = TRUE) plot(yA,yL_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) summary(X) hist(X[,1]) hist(X[,2]) hist(X[,3]) hist(X[,4]) hist(X[,5]) plot(Z[,1],yL_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) plot(Z[,2],yL_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) plot(Z[,3],yL_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) plot(Z[,4],yL_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) plot(Z[,5],yL_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) ############################ # Students ############################ Dataset=read.csv("Students.csv",header=TRUE,sep=";") head(Dataset) dim(Dataset) X=Dataset[,-1] head(X) summary(X) n=dim(X)[1] n k=dim(X)[2] k cor(X) #normalization of the k=3 variables Z=(X-1+1/n)/(10-1+2/n) head(Z) dim(Z) Z=as.matrix(Z) w=rep(1/k,times=k) w #Tippett combination as product between the matrix of transformed values and #vector of weights yT=matrix(0,nrow=n,ncol=1) wZ=Z%*%diag(w) for(u in 1:n){yT[u]=max(wZ[u,])} cbind(wZ,yT) range_x=10-1 summary(yL) ymin=(1/n)/(range_x+2/n)*min(w) ymin ymax=(range_x+1/n)/(range_x+2/n)*max(w) ymax #final index normalization yT_norm=(yT-ymin)/(ymax-ymin) hist(yT_norm,freq=FALSE) lines(density(yT_norm), col ="blue", lty = 2, lwd = 2, add = TRUE) #Additive combination yA=Z%*%w hist(yA,freq=FALSE) lines(density(yA), col ="red", lty = 1, lwd = 2, add = TRUE) lines(density(yT_norm), col ="blue", lty = 2, lwd = 2, add = TRUE) plot(yA,yT_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) summary(X) hist(X[,1]) hist(X[,2]) hist(X[,3]) plot(Z[,1],yT_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) plot(Z[,2],yT_norm) abline(a=0,b=1,col="green",lty=1,lwd=2) plot(Z[,3],yT_norm) abline(a=0,b=1,col="green",lty=1,lwd=2)