Another usage of package corrplot is that we can visualize the confidence interval of the correlation coefficients.Continuing with the example discussed in the previous analytics lab, let us see how to plot the confidence interval.
per_i<-read.csv("performance index data.csv",header=TRUE)
head(per_i)
jpi apt tol tech gen
1 47.12 45.18 56.18 52.18 45.45
2 41.89 33.12 34.47 51.68 52.10
3 51.12 56.92 56.28 53.87 53.61
4 40.10 53.43 60.51 47.88 47.71
5 43.54 52.68 52.28 48.34 47.10
6 40.36 41.31 43.75 48.91 42.47
library(corrplot)
res1 <- cor.mtest(per_i, conf.level = .95)
We know that cor.mtest
produces p-values and confidence intervals for each pair of input features.
cor_per_i<-cor(per_i)
corrplot(cor_per_i, low = res1$lowCI, upp = res1$uppCI,
plotC = "rect")
low=
reads the lowerbound of the confidence interval
upp=
reads the upperbound of the confidence interval
plotC=
defines the method of plotting the confidence interval plotC="rect"
plots rectangles whose upper sides means upper bound and lower side means lower bound respectively. The correlation coefficients are also added on the rectangles.
Other options for plotC=
are circle,square.
cor_per_i<-cor(per_i)
corrplot(cor_per_i, low = res1$lowCI, upp = res1$uppCI,
plotC = "circle", cl.pos = "n")
circle first plots a circle with the bigger absolute bound, and then plots the smaller. If the two bounds are of the same sign, the smaller circle will be wiped away, thus forming a ring. Method square is similar to circle.
cl.pos="n"
prohibits drawing of coloured labels.
corrplot(cor_per_i, p.mat = res1$p, low = res1$lowCI, upp = res1$uppCI,
order = "hclust", pch.col = "red", sig.level = 0.05,
plotC = "rect", cl.pos = "n")
We can visualize the insignifican/significant variables along with the confidence interval by specifying the sig.level=
.We can customise the plot according to our need. The order of the correlation matrix may be specified by including order=
.
pch.col=
is used to define the colour of insig
.