Starting from:

$35

AMS597 - Homework/Exam #5 Solved


1.   Using only random uniform generator, generate a random sample of size 1000 from the F distribution with 5 and 10 degrees of freedom. (Hint: If X ∼ χ2a and Y ∼ χ2b, X and Y are independent, then  follows F distribution with a and b degrees of freedom.)

2.   One disadvantage of Box-Muller algorithm is that it requires computing sine and cosine functions. By some transformation, one can show that the following closely related algorithm also generates independent standard normal random variables X and Y .

(a)   Generate U1 ∼ U(0,1) and U2 ∼ U(0,1)

(b)   Set V1 = 2U1 − 1 and .

(c)    If S 1, return to (a).

(d)   Otherwise,

 

This method is called the polar method. Use this method to generate 10000 standard normal random variables.

3.   A t-distributed random variable of k degrees of freedom is defined as

 

where Z ∼ N(0,1) and W ∼ χ2k, Z and W are independent. Using only the uniform number generator in R (runif), generate 100 random samples X, where X is a mixture t distribution, i.e., X ∼ 0.3t3 + 0.35t5 + 0.35t7.

4.   Write your function rmultivarNorm(n,mu,Sigma) which will generate n multivariate normal random variables using only runif.

5.   Write your own function my.ls() which performs the least square estimation for a continuous response variable y regressed on two predictors x1 which is a numeric predictor and x2 which is a categorical predictor. You may assume that your model contains an intercept. Test your function on the ChickWeight dataset in R, where y is weight, x1 is


Time (assumed to be continuous) and x2 is Diet, i.e., check if your function can reproduce the estimated beta coefficients from

data(ChickWeight) fit <- lm(ChickWeight$weight~ChickWeight$Time+ChickWeight$Diet) fit$coef

6. Use the mcycle data in the MASS package for this problem (see Homework 3 Qn 5).

Instead of fitting polynomial regression, fit an additive model using splines to this dataset.

Compare the MSE of the spline model to the polynomial regression model, where MSE =   is the observed response variable and Yˆi is the predicted response

variable.




More products