You are on page 1of 3

1.

A morning newspaper lists the following used-car prices for a foreign


compact with age x1 measured in years and selling price x2 measured in
thousands of dollar.
X1
1
2
3
3
4
5
6
8
9
11
X2
18,95 19,00
17,95
15,54
14.00 12,95
8,94
7,49
6,00
3,99
a. Construct a scatter plot of the data
b. Compute the sample mean, covariance matrix S, correlation matrix R.
*JAWAB*
a. Scatter plot of data

b.
> X1=c(1,2,3,3,4,5,6,8,9,11)
> X2=c(18.95,19.00,17.95,15.54,14.00,12.95,8.94,7.49,6.00,3.99)
> plot(X1,X2)
> abline(lm(X2~X1))

> f=matrix(c(X1,X2),10,2)
>f
[,1] [,2]
[1,] 1 18.95
[2,] 2 19.00
[3,] 3 17.95
[4,] 3 15.54
[5,] 4 14.00
[6,] 5 12.95
[7,] 6 8.94
[8,] 8 7.49
[9,] 9 6.00
[10,] 11 3.99
> mean(f)
[1] 8.8405
> cov(f)
[,1]
[,2]
[1,] 10.62222 -17.71022
[2,] -17.71022 30.85437
> cor(f)
[,1]
[,2]
[1,] 1.0000000 -0.9782684
[2,] -0.9782684 1.0000000

2.
> A=c(1,2,3,4,5,6,7)
> Sales=c(108,152,95,65,250,165,265)
> Profit=c(17,16,10,14,25,11,18)
> Assets=c(1200,750,766,1000,195,213,150)
> r=data.frame(Sales,Profit,Assets)
> r=as.matrix(r)
>r
Sales Profit Assets
[1,] 108
17 1200
[2,] 152
16 750
[3,] 95
10 766
[4,] 65
14 1000
[5,] 250
25 195
[6,] 165
11 213
[7,] 265
18 150
> summary(r)
Sales
Profit
Assets
Min. : 65.0 Min. :10.00 Min. : 150.0
1st Qu.:101.5 1st Qu.:12.50 1st Qu.: 204.0
Median :152.0 Median :16.00 Median : 750.0
Mean :157.1 Mean :15.86 Mean : 610.6
3rd Qu.:207.5 3rd Qu.:17.50 3rd Qu.: 883.0
Max. :265.0 Max. :25.00 Max. :1200.0
> mean(r)
[1] 261.1905
> cov(r)
Sales
Profit
Assets

Sales 5851.8095 253.35714 -27768.9286


Profit 253.3571 25.14286 -632.5714
Assets -27768.9286 -632.57143 180927.9524
> cor(r)
Sales
Profit
Assets
Sales 1.0000000 0.6605121 -0.8534168
Profit 0.6605121 1.0000000 -0.2965852
Assets -0.8534168 -0.2965852 1.0000000
> plot(Sales,Profit)
> abline(lm(Profit~Sales))
> plot(Profit,Assets)
> abline(lm(Assets~Profit))

You might also like