x<-c(2,5,3,8,2)
y<-c(4,3,0,0,4)
df<-data.frame(x,y)
df
## x y
## 1 2 4
## 2 5 3
## 3 3 0
## 4 8 0
## 5 2 4
mean(x)
## [1] 4
mean(y)
## [1] 2.2
var(x)
## [1] 6.5
var(y)
## [1] 4.2
cov(x,y)
## [1] -3.25
##correlation
cor(x,y)
## [1] -0.6220167
##Regression
model<- lm(y~x,data=df)
model
##
## Call:
## lm(formula = y ~ x, data = df)
##
## Coefficients:
## (Intercept) x
## 4.2 -0.5
plot(x,y)
abline(model)