IN R-Studio 1. The command X=rbinom(1000,5,0.7) generates a sample of size 1000
ID: 3241740 • Letter: I
Question
IN R-Studio
1. The command X=rbinom(1000,5,0.7) generates a sample of size 1000 from the Bin(5,0.7) distribution.
(a) Try mean(X).
i. Give the outcome.
ii. What you achieved in part (i) is an empirical outcome. Find the value that this empirical outcome is supposed to get close to. Find the value without using any computer or calculator.
iii. Explain what you observed in part (i) and (ii) .
(b) The command table(X)/1000 will return the proportions of 0,...,5 in your sample.
i. Give the outcome.
ii. What you achieved in part (i) is an empirical outcome. Use one line of R command to achieve what this empirical outcome is supposed to get close to.
iii. Explain what you would do if you want to make the outcome in part (i) get further closer to the outcome in part (ii)?
(20 points)
2. Now, we want to repeat what we did in Problem 1-(a)-i multiple times – say 10,000 times. In other words, we will calculate the sample mean from an iid Bin(5,0.7) sample of size 1,000, and repeat this 10,000 times.
(a) Write a code to store the sample means in a vector M. The size(length) of the vector should be 10,000. You can use some iteration commands like for.
(b) Show histogram for M. Which distribution does M seem to follow?
(c) Name this phenomena you observed in part (b).
(d) Report var(M).
(e) The command mean(X) in Problem 1-(a) is an estimator. Find the MSE of this estimator numerically (using the vector M).
(20 points)
3. Load the dataset mtcars.
(a) Filter out observations whose weight is more than 5,000 lbs.
(b) Using the remaining observations, t a simple linear regression model using MPG as the response variable and weight as the explanatory variable.
(c) Report the estimated regression coecient and interpret its meaning.
(d) Report predicted value of MPG when weights are 3000 lbs and 5260 lbs?
(e) Now t a simple linear regression model using all 32 values of MPG and weight. Report the predicted value of MPG when weights are 3000 lbs and 5260 lbs.
Explanation / Answer
1(a)
Try mean(X).
i. Give the outcome.
3.539
ii. What you achieved in part (i) is an empirical outcome. Find the value that this empirical outcome is supposed to get close to. Find the value without using any computer or calculator.
The value that this empirical outcome is supposed to get close to is the mean of Bin(5,0.7). The mean of binomial distribution is 5*0.7 = 3.5
iii. Explain what you observed in part (i) and (ii) .
The output in part (i) (3.539) and (ii) (5) are not same. The difference between the outpur of part (a) and (b) is 0.039
(b) The command table(X)/1000 will return the proportions of 0,...,5 in your sample.
i. Give the outcome.
0 1 2 3 4 5
0.002 0.029 0.136 0.295 0.337 0.201
ii. What you achieved in part (i) is an empirical outcome. Use one line of R command to achieve what this empirical outcome is supposed to get close to.
> dbinom(1:5,5,0.7)
[1] 0.02835 0.13230 0.30870 0.36015 0.16807
iii. Explain what you would do if you want to make the outcome in part (i) get further closer to the outcome in part (ii)?
To make the outcome in part (i) get further closer to the outcome in part (ii), we need to increase the first argument (1000) of rbinom(1000,5,0.7). With large value of n (first argument of rbinom), the the outcome in part (i) will be closer to the outcome in part (ii).