Description
Please refer to the attached file.
Some of questions are required to writing down the codes to calculate some values; some other questions are analysis tasks
Please closely read assigned questions
Unformatted Attachment Preview
Purchase answer to see full attachment
Explanation & Answer
Hi, here is your assignment, kindly see attached ;)
1
1 Homework 6: Multivariate Regression
1.1 Purpose
Homework 6 is meant to give you some practice on understanding what can go wrong with multivariate
regression.
1.2 What needs to be returned?
• Please upload a typed out solution for the following questions to CourseWorks before class starts.
1.3 Math to Code
1.3.1 Q1
Define a random vector with 3 random variables:
R code solution:
•
X ~ Normal(0, 10)
X ~ Normal(0, 10)
> X X
[1] 1.1901502 1.2200305 0.3301327 -1.2165371 -1.3769804 -0.8329006
[7] 1.0076789 0.6001681 -0.5144466 -0.1612686
•
Y ∼ Exp(λ = 0.1)
> Y = exp(0.1)
> Y
[1] 1.105171
•
Z = Y + 2 ∗ X + ϵ, where ϵ ∼ Unif[−5, 5]
> ϵ ϵ
[1] 3.412053
> Z=y Z
[1] 6.897524 6.957285 5.177489 2.084149 1.763263 2.851422 6.532581 5.717560
[9] 3.488330 4.194686
Definition of vectors: It is given that X, Y, Z have normal distribution, both are independent.
Matrix:
> (xy Z cov.wt(xy, wt = w1) # i.e. method = "unbiased"
$cov
X Y
X 1.195985 0
Y 0.000000 0
$center
X
-0.3637142
Y
1.1051709
$n.obs
[1] 10
$wt
[1] 0.0 0.0 0.0 0.2 0.2 0.2 0.2 0.2 0.0 0.0
> cov.wt(xy, wt = w1, method = "ML", cor = TRUE)
$cov
X Y
X 0.9567879 0
Y 0.0000000 0
$center
X
-0.3637142
Y
1.1051709
$n.obs
[1] 10
$wt
[1] 0.0 0.0 0.0 0.2 0.2 0.2 0.2 0.2 0.0 0.0
$cor
X
Y
X
1 NaN
Y NaN NaN
3
1.3.2 Q2, numerically approximating covariances:
> require(ggplot2)
> sampa=rnorm(100,0,10)
> sampb=rnorm(1000,0,10)
> combined = c(sampa, sampb)
> plt = ggplot(data.frame(combined), aes(x=combined)) +
stat_bin(binwidth=0.25, position="identity")
> plt
> trans=matrix(c(1.2, 1.2, 0.33, -1.38, -0.83, 1.01, 0.60, -0.51, -0.16,
+
1.50),nrow=4)
> dimnames = list(c("A", "C", "G", "T"), c("A", "C", "G", "T"))
> trans
[,1] [,2] [,3]
[1,] 1.20 -0.83 -0.16
[2,] 1.20 1.01 1.50
[3,] 0.33 0.60 1.20
[4,] -1.38 -0.51 1.20
4
1.3.3
Q3, a common abuse of the word ”sample size”
> # Generating data for 20 sample of size 20
>
> sdata
>
>
>
>
>
>
>
>
+
+
+
>
>
>
>
>
>
>
>
crit X5 = 1 − X1
> X5
[1] 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0
X0 defines the y function that would be equal to 0.
> eigen(cbind(X1, X2, X3, X4), only.values = TRUE)
> eigen(cbind(-1, 2:1)) # complex values
eigen() decomposition
$values
[1] 0+1i 0-1i
$vectors
[,1]
[,2]
[1,] 0.8164966+0.0000000i 0.8164966+0.0000000i
[2,] 0.4082483+0.4082483i 0.4082483-0.4082483i
> eigen(print(cbind(c(0, 1i), c(-1i, 0)))) # Hermite ==> real Eigenvalues
[,1] [,2]
[1,] 0+0i 0-1i
[2,] 0+1i 0+0i
eigen()...