[Solved] MAST30025 Lab 3

$25

File Name: MAST30025_Lab_3.zip
File Size: 141.3 KB

SKU: [Solved] MAST30025 Lab 3 Category: Tag:
5/5 - (1 vote)

MAST30025: Linear Statistical Models

Week 3 Lab

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

Find tr(H) and r(H).

  1. Let

.

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

  1. 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]

  1. Prove corollaries 3.6 and 3.7 from the lectures.
  2. 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).

  1. 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?

  1. Let. Write an R program to calculate h(x,n) using a for
  2. 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.

  1. 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 doesnt already, make sure your program works for the case x = 1.

  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.

  1. 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.

  1. 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.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] MAST30025 Lab 3
$25