Aim: To find the correlation and regression of the given data.
Problem: Find the correlation and regression of the following data and also draw the scatter
diagram.
X 10 12 13 16 17 20 25
Y 19 22 26 27 29 33 37
R - Code:-
> X=c(10,12,13,16,17,20,25)
> Y=c(19,22,26,27,29,33,37)
> r=cor(X,Y, method="pearson")
> cat("Correlation coefficient of the given data =",r,"\n")
Correlation coefficient of the given data = 0.9801983
> Rho=cor(X,Y, method="spearman")
> cat("Rank Correlation coefficient of the given data =",Rho,"\n")
Rank Correlation coefficient of the given data = 1
> plot(X,Y, main="Scatter Plot",xlab="X Data", ylab="Y Data", col="blue",pch="*"
+ )
> scatter.smooth(X,Y,main=”Scatter diagram”, col.=”blue”)