STA261: Assignment
Shahriar Shams Winter 2021
Submission deadline: April 07, 2021, 10.00am (Local Toronto time) (Late submis- sions will not be accepted)
Submitting this assingment is mandatory for every student in order to pass the course. There is not any minimum score that you have to achieve, but submission is mandatory.
Instructions on creating documents for submission
• We will use crowdmark for submission and grading which only accepts PDF, JPG and PNG files.
• I recommend using R-markdown(if you are familiar with it). If you are not familiar with R-markdown, you can write your answers using Microsoft Word and in the end save them as pdfs. Handwritten answers will not be accepted.
• Crowdmark link to upload your documents will be emailed to you later.
• The numerical calculations involved in this assignment are simple and you are already familiar with them (hopefully). Calculations are mostly repetitive in nature! I suggest using R.
• If you are a Python user, feel free to use Python in place of R to answer any of the questions. You can also use Microsoft Excel (for Q1-Q3) if you want.
• For each answer, make sure you have provided your codes and outputs. If you use Excel, take screen shots of the worksheet showing formula used and outputs and submit them as part of your answer(as appendix for example).
• Make sure your answers are easy to read and nicely presented.
1
Question 1 (3 points)
Suppose you have a population of size 7 [i.e. N=7]. You measure some quantity (X) and the corresponding numbers are:
21, 22, 23, 24, 25, 26, 27
a) Calculate the population mean (μ) and print/show the value.
b) Calculate the population variance (‡2) using the formula ‡2 = qNj=1(Xj≠μ)2 and
N
c) Imagine you are taking samples (of size n = 4) from this population with replacement. Imagine every possible way that you could have a sample of size 4 with replacement from this population. (hint: there will be 7 ú 7 ú 7 ú 7 = 2401 possible combinations)
R code to get all possible combinations
d) For each of these samples of size 4, calculate the sample mean and record it (either as a new object in R or as a new column if you are using excel). Lets call this new column X_bar. So you should have 2401 values in this column.
e) You should have noticed that the values in the X_bar column are repetitive. Construct a frequency table based on the column X_bar. [i.e. write down which values showed up how many times]. Now using the frequencies (also known as counts) calculate proportion of each of those repeated values.
f) Plot these proportions against the values and connect the points to form a curve. Does the shape of this plot look like any known distribution? Name the distribution.
g) Using the table of proportions[from part(e)] or otherwise, calculate the mean of these 2401 numbers (values under X_bar) and compare it to your answer of 1(a).
h) Using the table of proportions[from part(e)] or otherwise, calculate the variance of these 2401 numbers. Use the population variance formula (i.e. divide by 2401, not 2400). What is the relationship of this answer to your answer of 1(b)?
i) Which theorem did you demonstrate empirically in part f, g and h?
print/show the value.
X=c(21, 22, 23, 24, 25, 26, 27)
d=expand.grid(X,X,X,X) #You can continue your calculations using this “d”
# For excel users, this following line will create a csv file for you.
write.csv(d,file=”Question1.csv”,row.names = F)
3
Question 2 (3 points)
This question continues from question 1(c). For each of these sample of size 4, calculate the sample variance using the following two formulas
S2= 1 ÿ(X≠X ̄)2 n≠1 i
and 2 1ÿ ̄2 ‡ˆ=n (Xi≠X)
Assume the population variance, ‡2 = 4. (you should get 2401 di erent values of S2 and and 2401 di erent values of ‡ˆ2)
a. By calculating (numerically, using the 2401 di erent values) Bias[S2] and Bias[‡ˆ2] check the unbiasedness of these two estimators.
b. By calculating all three components separately, show that the following identity is true MSE[‡ˆ2] = var[‡ˆ2] + (Bias[‡ˆ2])2
4
Question 3 (3 points)
Even though we need sample size n to be large to apply central limit theorem, but let’s apply it anyway. Suppose you know that the population variance, ‡2 = 4.
a. For each of these 2401 cases, calculate a 95% confidence interval for μ and finally calculate the proportion of the intervals that includes μ = 24.
b. Suppose, someone observes only one of these 2401 combinations (24,25,26,27). If that person is testing the null hypothesis H0 : μ = 24 at level of significance, – = 0.05, based on this observed set of four numbers, calculate the p-value that the person will get using central limit theorem.
c. Calculate the p-value numerically using the 2401 X ̄ values that you calculated in part 1(d) (do not use CLT here).
d. Why do you see a di erence in your calculation in part(b) and part(c)? And under what condition you expect these two numbers to be similar?
5
Question 4 (3 points)
In a lecture, we demonstrated an R code that replicates the sampling distribution of X ̄. Here is the code that was used in the lecture.
sample_4m_normal=function(){ s=rnorm(30,mean=10,sd=2)
return(mean(s)) }
X_bar=replicate(10000,sample_4m_normal()) plot(density(X_bar))
Simply change the distribution and number of samples in this code to do this question. Produce the density of X ̄ = X1+X2+…+Xn
n
f) CLT says for large n, X ̄ converges(in distribution) to a Normal distribution. By comparing your graphs from parts (a) to (e), can you comment on how large n has to be in order for X ̄ to converge to a Normal distribution? What role the skewness of the original distributions (Unif[0,1], ‰2df=2 and ‰2df=50 ) play here?
a) whenn=2,X≥Unif[0,1]
b) whenn=5,X≥Unif[0,1]
c) whenn=5,X≥‰2df=2
d) whenn=30,X≥‰2df=2
e) whenn=5,X≥‰2df=50
6
Question 5 (3 points)
Likelihood ratio test has the following test statistic (lets call it W) W = ≠2log L(μ0)
L(μˆ)
The goal of this question is to “see” the limiting disribution of the test statistic, W under H0. In other words, we want to see, if H0 is really true, what will be the distribution of W. We will do this under two scenarios.
(a) Suppose X ,X ,…,X ≥ N(μ,‡2 = 16). Treat ‡2 = 16 as the known constant. 1 2 20 iid
WewanttotestH0 :μ=10vsH1 :μ”=10atlevelofsignificance,–. (i) Write a function in R that
• generates 20 samples from a N (μ = 10, ‡2 = 16) distribution
• evaluates the likelihood function at μ = 10 (save it under the name L_theta0)
• evaluates the likelihood function at μ = x ̄ (save it under the name L_theta1)
• calculates and returns ≠2 ú log(L_theta0/L_theta1)
(ii) Run this function using the replicate() command (or something similar) and save the output under the name LRT_vec.
(iii) Plot a density histogram using LRT_vec.
code hint: use hist() with options freq=FALSE, breaks=100.
(iv) Overlay a ‰2(df=1) density curve on top of this histogram.
code hint: generate 100000 random samples from a ‰2(df=1), use density() and lines()
7
(b) (we will repeat the process of part(a) but with a di erent distribution here) Suppose X ,X ,…,X ≥ Exp(⁄). [where, E[X] = 1]
1 2 20 iid
WewanttotestH0 :⁄=0.1vsH1 :⁄”=0.1atlevelofsignificance,–.
(i) Write a function in R that
• generates 20 samples from a Exp(⁄ = 0.1) distribution
• evaluates the likelihood function at ⁄ = 0.1 (save it under the name L_theta0)
• evaluates the likelihood function at the MLE (save it under the name L_theta1)
• calculates and returns ≠2 ú log(L_theta0/L_theta1)
(ii) Run this function (100000 times) using the replicate() command (or something similar) and save the output under the name LRT_vec.
(iii) Plot a density histogram using LRT_vec.
(iv) Overlay a ‰2(df=1) density curve on top of this histogram.
(c) In both part (a) and (b), your histograms should match(almost if not completely) with the ‰2(df=1) density. Make a brief comment on what role you expect the sample size to play in the closeness of the histograms and the ‰2(df=1) densities. (In other words, do you expect these type of closeness irrespective of the value of n?)
⁄
8