Coefficient of correlation Experiment :1 Finding the Correlation Coefficient to the given data Experiment :2 Finding the Correlation Coefficient to the data from an excel file. Experiment :3 Finding the Correlation Coefficient to the data from builtin data base. Experiment :4 Rank Correlation.

 #LAB-6

#Scatter diagram
x=c(50,50,55,60,65,65,65,60,60,50)
y=c(11,13,14,16,16,15,15,14,13,13)
plot(x,y,main="scatter plot",xlab="Sales",ylab="Expenses")
scatter.smooth(x,y,main="scatter plot",xlab="Sales",ylab="Expenses")

#Corelation Coeffient
x=c(50,50,55,60,65,65,65,60,60,50)
y=c(11,13,14,16,16,15,15,14,13,13)
result=cor(x,y,method="pearson")
cat("Pearson correlation coeffient is:",result)

#Covariance
x=c(50,50,55,60,65,65,65,60,60,50)
y=c(11,13,14,16,16,15,15,14,13,13)
print(cov(x,y,method="spearman"))

#Program 2
#Corelation Coeffient by pearson
x=c(1,2,3,4,5,6,7)
y=c(1,3,6,2,7,4,5)
result=cor(x,y,method="pearson")
cat("Pearson correlation coefficient is:",result)

#Corelation Coeffient by pearson by Excel file
df=read.csv("Auto.csv")
x=df$mpg
y=df$weight
result=cor(x,y,method = "pearson")
cat("Pearson correlation coeffient is:",result)
res=cor.test(x,y,method = "pearson")
print(res)

#Corelation Coeffient by pearson by Built-in DB
data("mtcars")
head(mtcars)
cor1=cor(mtcars$wt,mtcars$mpg)
cat("Pearson correlation coeffient is:",cor1)

#Spearman Rank Correlation
x=c(15,18,21,15,21)
y=c(25,25,27,27,27)
result=cor(x,y,method="spearson")
cat("Spearman correlation coeffient is:",result)

#Spearman Degree of agreement
x=c(1,2,3,4,5,6,7,8,9,10,11)
y=c(2,3,1,6,4,5,8,7,10,11,9)
result=cor(x,y,method="spearman")
cat("Spearman correlation coeffient is:",result)


#Student Practice
data("quakes")
head(quakes)
cor1=cor(quakes$mag,quakes$stations)
cat("Pearson correlation coeffient is:",cor1)

#Scatter diagram
x=c(25,25,35,65,65)
y=c(15,30,49,60,75)
plot(x,y,main="scatter plot",xlab="Products",ylab="Revenue")
scatter.smooth(x,y,main="scatter plot",xlab="Products",ylab="Revenue")


#Corelation Coeffient
x=c(25,25,35,65,65)
y=c(15,30,49,60,75)
result=cor(x,y,method="spearman")
cat("Pearson correlation coeffient is:",result)

#Spearman Rank Correlation
x=c(25,25,35,65,65)
y=c(15,30,49,60,75)
result=cor(x,y,method="spearman")
cat("Spearman correlation coeffient is:",result)



Comments

Popular posts from this blog

Probability distributions using R Experiment :1 Binomial Distribution Experiment :2 Poisson Distribution Experiment :3 Normal Distribution

Lines of Regression, Angle between two lines of regression and estimated values of variables. Experiment :1 Finding (a) Regression line of y on x and (b) Regression line of x on y. Experiment :2 Predicting y value for a given x. Experiment :3 Angle between two lines of regression