How to find covariance, correlation coefficient, spearman's coefficient, regression line, estimated value, residual value for data stored in x, y.
> x=scan() [enter x data]
1: 56
2: 47
3: 33
4: 39
5: 42
6: 38
7: 46
8: 47
9: 38
10: 32
11:
Read 10 items
> y=scan() []enter y data]
1: 56
2: 83
3: 49
4: 52
5: 65
6: 52
7: 56
8: 48
9: 59
10: 70
11:
Read 10 items
> cov(x,y) [to get covariance of x, y]
[1] 4.444444
> cor(x,y) [to get correlation coefficient]
[1] 0.05560642
> cor(x,y,method="spearman") [to get spearman's coefficient]
[1] -0.003067485
> model=lm(y~x) [to fit regression equation]
> model
Call: [result output]
lm(formula = y ~ x)
Coefficients:
(Intercept) x
55.54260 0.08271
> plot(x,y,col="red") [plot x, y points]
> abline(model,h=0,v=0,col="blue") [plot regression line]
> model$fitted[6] [to get fitted value]
6
58.68569
> model$residuals[6] [to get residual value]
6
-6.685691
> x=scan() [enter x data]
1: 56
2: 47
3: 33
4: 39
5: 42
6: 38
7: 46
8: 47
9: 38
10: 32
11:
Read 10 items
> y=scan() []enter y data]
1: 56
2: 83
3: 49
4: 52
5: 65
6: 52
7: 56
8: 48
9: 59
10: 70
11:
Read 10 items
> cov(x,y) [to get covariance of x, y]
[1] 4.444444
> cor(x,y) [to get correlation coefficient]
[1] 0.05560642
> cor(x,y,method="spearman") [to get spearman's coefficient]
[1] -0.003067485
> model=lm(y~x) [to fit regression equation]
> model
Call: [result output]
lm(formula = y ~ x)
Coefficients:
(Intercept) x
55.54260 0.08271
> plot(x,y,col="red") [plot x, y points]
> abline(model,h=0,v=0,col="blue") [plot regression line]
> model$fitted[6] [to get fitted value]
6
58.68569
> model$residuals[6] [to get residual value]
6
-6.685691
No comments:
Post a Comment