In: Statistics and Probability
Rstudio Coding Homework (submmite the pdf file to Canvas)
Let X be a Possion(λ) random variable. We have seen in class
that
E(X) = Var(X) = λ.
Suppose that we do not know the true value of λ and want to
estimate it from observed data {x1, x2, . . . , xn}.
There are two possible ways to do estimate λ:
• use the sample mean x¯ =
1
n
Pn
i=1 xi
• use the sample variance S
2 =
1
n−1
Pn
i=1(xi − x¯)
2
Please note that in sample variance, the denominator is n − 1
instead of n.
In this assignment, you will compare the two estimators. In the
following questions, we assume that
λ = 10.
1. Generate n = 10 independent Poisson(λ) random variables,
calculate the sample mean (you can use
rpois(n = ,lambda = ) function in R, where n is the total number of
random varables generated and
lambda is the parameter λ). Do the above 1000 times, then you have
1000 observations of the sample
mean (each of them is calculated from n = 10 independent Poisson
(λ) random variables.) Generate
the boxplot and histogram of the 1000 observation of sample
means.
2. For n = 10, repeat Part 1 with the sample variance.
3. Compare the boxplot and histogram you obtained from Part 1 and
2. Comment on the difference
between them. (Hint: measure of dispersion)
---
title: "MATH 2411 Homework 2"
author: "yu wai man 20600375"
date: "2020/3/26"
output: pdf_document
#output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Coding Howework (submmite the pdf file to Canvas)
Let $X$ be a Possion$(\lambda)$ random variable. We have seen in
class that $$\mathbb E(X) = \mathrm{Var}(X) = \lambda.$$ Suppose
that we do not know the true value of $\lambda$ and want to
estimate it from observed data $\{x_1,x_2, \dots, x_n\}$. There are
two possible ways to do estimate $\lambda$:
\begin{itemize}
\item use the sample mean $\bar{x} = \frac{1}{n}\sum_{i = 1}^{n}
x_i$
\item use the sample variance $S^2 = \frac{1}{n-1} \sum_{i = 1}^{n}
(x_i - \bar{x})^2$
\end{itemize}
**Please note that in sample variance, the denominator is $n-1$
instead of $n$.**
In this assignment, you will compare the two estimators. **In the following questions, we assume that $\lambda = 10$.**
1. Generate $n = 10$ independent Poisson$(\lambda)$ random variables, calculate the sample mean (you can use \verb+rpois(n = ,lambda = )+ function in \verb+R+, where \verb+n+ is the total number of random varables generated and \verb+\lambda+ is the parameter $\lambda$). Do the above $1000$ times, then you have $1000$ observations of the _sample mean_ (each of them is calculated from $n=10$ independent Poisson $(\lambda)$ random variables.) **Generate the boxplot and histogram of the $1000$ observation of sample means.**
```{r sample mean}
# input your r code here
```
2. For $n = 10$, **repeat Part 1 with the _sample variance_.**
```{r sample variance}
# input your r code here
```
3. Compare the boxplot and histogram you obtained from Part 1 and 2. **Comment on the difference between them.** (Hint: measure of dispersion)
```{r boxplot and histogram}
# input your r code here
```
**Write down your comments here**
samp_mean = c() samp_var = c() x= c() for(i in 1:1000){ x = rpois(n = 10 , lambda = 10) samp_mean[i] = mean(x) samp_var[i] = var(x) } boxplot(samp_mean) hist(samp_mean) boxplot(samp_var) hist(samp_var)
Both the plots sample mean and sample variance have measure of centre around 10 which is our parameter lambda =10.
but if we observe variablity in data which is measure of spread,we will conclude that distribution of sample variance have more of extreme observation than distribution of sample mean.
also distribution of sampe mean is quite symmetric .ie normal while distribution of sample variance is right skewed.
plz like)
7 8 9 10 11 12 13 sample mean
Histogram of samp_mean 200 150 Frequency 100 50 0 samp mean
0 5 10 15 20 25 30 35 sample variance
Histogram of samp_var 400 300 Frequency 200 100 0 T T 1 5 10 15 20 25 30 35 samp_var