Question

R Code Directions: All work has to be your own, you may not work in groups....

R Code

Directions: All work has to be your own, you may not work in groups. Show all work. Submit your solutions in a pdf document on Moodle. Include your R code (which must be commented and properly indented) in the pdf file. Name this pdf file ‘your last name’-HW5.pdf. Also submit one text file with your R code, which must be commented and properly indented. You may only use ‘runif’ to generate random numbers; other random number generating functions have to be your own.

You will need to generate from the Gamma distribution in this homework. To do that, you may use the fact that if Z1, . . . , Zm are i.i.d. exponential with mean µ, then the sum of Zi (from i=1 to m) ~ Gamma(m, µ).

1. Let X be the yet-to-be measured diastolic blood pressure of a randomly selected person that takes a particular vitamin. Let Y be the yet-to-be measured diastolic blood pressure for a randomly selected person that does not take this particular vitamin. Suppose that X ~ Gamma(η = 79, ν = 1) and Y ~ Gamma(η = 80, ν = 1).

(a) Use R to graph the densities for X and Y in the same plot. Use dots for the density of Y.

(b) It can be shown that E(X) = 79 and var(X) = 79. Produce a simulation-based 99.5% approximate confidence interval for E((X− 79)2 ) = var(X). Use 500,000 replications. Is 79 in this interval?

(c) It can be shown that E(Y ) = 80 and var(Y ) = 80. Produce a simulation-based 99.5% approximate confidence interval for E((Y − 80)2 ) = var(Y ). Use 500,000 replications. Is 80 in this interval?

(d) Researchers plan to design an experiment to study the association between taking this vitamin and diastolic blood pressure. They plan to use a two-independent-samples model. Let the yet-tobe observed diastolic blood pressures for individuals that take this vitamin be X1, . . . , Xn1 , which are independent copies of X. Let the yet-to-be observed diastolic blood pressures for individuals that do not take this vitamin be Y1, . . . , Yn2 , which are independent copies of Y. Assume that X1, . . . , Xn1, Y1, . . . , Yn2 are independent. Use simulation to find the value of n1 = n2 such that the power of the two-independent-samples t-test of H0 : E(X) = E(Y ), HA : E(Y ) does not equal E(X), is roughly 90 % when the 5 % significance level is used.

Homework Answers

Answer #1

1) x_seq = seq(from=20, t0 = 110 length_out = 1e3)

X_den.vals = dgamma(x=x.seq, shape = 79, scale = 1)

plot(x.seq, X_den.vals, type = "1", xlab = "x", ylab = "Density")

Y.den.vals = dgamma(x=x.seq, shape = 80, scale=1)

lines(x.seq,Y.den.vals,lty = 3)

2) set_seed(3701); reps = 5e5

x_list = rgamma(n = reps, shape=79,scale =1)

## CI for var(X) = E[(X-79)*2]

t.test((x.list-79)^2,conf.level=0.995)

$conf.int[1:2]

[1]78.67027 79.57529

the true value of 79 is in this interval

c) set_seed(3701); reps = 5e5

x_list = rgamma(n = reps, shape=80,scale =1)

## CI for var(X) = E[(X-79)*2]

t.test((x.list-80)^2,conf.level=0.995)

$conf.int[1:2]

[1]78.66698 80.58333

the true value of 80 is in this interval

d) Researchers plan to design an experiment to study the association between taking this vitamin and diastolic blood pressure. They plan to use a two-independent-samples model. Let the yet-to-be observed diastolic blood pressures for individuals thattake this vitamin be X1,...,Xn1, which are independent copies of X. Let the yet-to-be observed diastolic blood pressures for individuals that do not take this vitamin beY1,...,Yn2, which are independent copies of Y. Assume that X1n1,Y1n2are independent. Use simulation to find the value of n1=n2 such that the power of thetwo-independent-samples t-test of

H0:E(X)-E(Y) = 0,

Ha:E(X)-E(Y)6= 0,

is roughly 85% when a 1% significance level is used.

Please don't forget to rate my answer...!!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions