Consider the following data matrix and the following three linear combinations:
ID: 3043386 • Letter: C
Question
Consider the following data matrix
and the following three linear combinations: X1 +X2 +X3, X1 +2X2 3X3, and X3
(a) Read the matrix X as a data frame in R (software)
(b) Calculate the mean vector and the variance-covariance matrix corresponding to the
data frame in (a)
(c) Find the sample mean for each of the three linear combinations
(d) Find the sample variance for each of the three linear combinations
(e) Find the covariance between all possible pairs of linear combinations
PLEASE POST THE CODE USED IN R FOR THE ANSWERS
168Explanation / Answer
a)
> x1=c(1,6,8)
> x2=c(4,2,3)
> x3=c(3,6,3)
> x=data.frame(x1,x2,x3)
> x
x1 x2 x3
1 1 4 3
2 6 2 6
3 8 3 3
b)
> m=apply(x,2,mean)
> m # mean vector
x1 x2 x3
5 3 4
> v=var(x)
> v # v gives variance covariance matrix of data frame x.
x1 x2 x3
x1 13.0 -2.5 1.5
x2 -2.5 1.0 -1.5
x3 1.5 -1.5 3.0
c) y1, y2 and y3 repre4sent the given 3 linear combinations
> y1=x1+x2+x3
> y1
[1] 8 14 14
> y2=x1+2*x2-3*x3
> y2
[1] 0 -8 5
> y3=x3
> y3
[1] 3 6 3
Sample means for linear combinations are,
> mean(y1)
[1] 12
> mean(y2)
[1] -1
> mean(y3)
[1] 4
d)
Sample variances for linear combinations are,
> var(y1)
[1] 12
> var(y2)
[1] 43
> var(y3)
[1] 3
e) Covariance between all possible pairs of linear combinations are,
> cov(y1,y2)
[1] -3
> cov(y1,y3)
[1] 3
> cov(y2,y3)
[1] -10.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.