Starting from:

$30

MAST30025: Linear Statistical Models: Lab 3 Solved

Let X be a 10 × 5 matrix of full rank and let H = X(XTX)−1XT.
Find tr(H) and r(H).

Let
.

Let z = yTAy. Write out z in full, then find ∂∂zy directly and using the matrix formula.

Let y be a random vector with mean µ, and assume that
Varyi = 4 and Cov(yi,yj) = 0.

Write down Vary.
Let
and find VarAy and E[yTAy]

Prove corollaries 3.6 and 3.7 from the lectures.
Let y be a normal random vector with mean and variance
µ and.

Let

 .

Find the distributions of yTAy and yTBy.
Are yTAy and yTBy independent?
What is the distribution of yTAy + yTBy? 6. Let y1,...,yn be an i.i.d. normal sample. Show that
and

are independent. (Hint: Express them as a random “vector” and quadratic form respectively.)

R exercises
The following are taken from Chapter 3 of spuRs (Introduction to Scientific Programming and Simulation Using R).

Consider the function y = f(x) defined by
x
≤ 0
∈ (0,1]
> 1 √
f(x)
−x3
x2
x
Supposing that you are given x, write an R expression for y using if statements.

Add your expression for y to the following program, then run it to plot the function f.

# input

x.values <- seq(-2, 2, by = 0.1)

# for each x calculate y n <- length(x.values) y.values <- rep(0, n) for (i in 1:n) { x <- x.values[i]

# your expression for y goes here y.values[i] <- y

}

# output

plot(x.values, y.values, type = "l")

Your plot should look like Figure 1. Do you think f has a derivative at 1? What about at 0?

Let. Write an R program to calculate h(x,n) using a for
The function h(x,n) from Exercise 2 is the finite sum of a geometric sequence. It has the following explicit formula, for x 6= 1,
.

Test your program from Exercise 2 against this formula using the following values

You should use the computer to calculate the formula rather than doing it yourself.

First write a program that achieves the same result as in Exercise 2 but using a while Then write a program that does this using vector operations (and no loops).
If it doesn’t already, make sure your program works for the case x = 1.

To rotate a vector (x,y)T anticlockwise by θ radians, you premultiply it by the matrix
.

Write a program in R that does this for you.

Given a vector x, calculate its geometric mean using both a for loop and vector operations. (The geometric mean of
You might also like to have a go at calculating the harmonic mean, (, and then check that if the xi are all positive, the harmonic mean is always less than or equal to the geometric mean, which is always less than or equal to the arithmetic mean.

A room contains 100 toggle switches, originally all turned off. 100 people enter the room in turn.The first toggles every switch, the second toggles every second switch, the third every third switch, and so on, to the last person who toggles the last switch only.
At the end of this process, which switches are turned on?

x.values

Figure 1: The graph produced by Exercise 1

More products