Вы находитесь на странице: 1из 2

Lab 5

Correlation and Regression

Problem 1

x=c(15,25,35,45,55,65)
> y=c(302.38,193.63,185.46,198.49,224.30,288.71)
> plot(x,y,main="Average age vs Time spent in library",xlab="Age",ylab="Time spent in
library",col="red")

Problem 2:

x=c(25,30,28,29,32,24,36,28,27,21)
y=c(18,20,21,16,14,13,22,15,19,12)

> var(x)
[1] 17.77778
> var(y)
[1] 12.22222
> sqrt(var(x)*var(y))
[1] 14.74055
> cov(x,y)
[1] 8.777778
> r=cov(x,y)/sqrt(var(x)*var(y))
>r
[1] 0.5954849

Direct function :
cor(x,y)

[1] 0.5954849

Problem 3 :

weight=c(15,26,27,25,25.5,27,32,18,22,20)
BMI=c(13.35,16.12,16.74,16,13.59,15.73,15.65,13.85,16.07,12.8)
model=lm(BMI~weight)
model

Call:
lm(formula = BMI ~ weight)

Coefficients:
(Intercept) weight
10.5563 0.1867

Вам также может понравиться