Assignment Y1: (I) Median
Assignment Y1: (I) Median
Assignment Y1: (I) Median
Question 1
(i) Median
n<-1000
p<-0.05
qbinom(0.5,n,p)
## [1] 50
## [1] 0.6523035
## [1] 0.6408685
## [1] 0.6701195
Question 2
(i) (b)
Rearranging u=F ( x ) to get x=F−1 (u)
1 1
u=1− becomes x= −1
1+ x 1−u
x<- (1-u)^(-1)-1
x
(ii) (a)
plot(density(x),xlim=c(0,200), main="Empirical PDF of the simulations",
xlab="x", col="blue")
(ii) (a)
mean(x)
## [1] 14.54969
sd(x)
## [1] 199.7557
skew<-sum((x-mean(x))^3)/length(x)
skew/(sd(x)^3)
## [1] 27.72327
The huge standard deviation for such a small mean indicates that we have a very long tail
(as the values must be greater than zero).
This is confirmed by the very large positive coefficient of skewness.
Question 3
## [1] 0.4560843
(ii) Showing that the greatest width occurs when there are 10
successes
width<-rep(0,20)
for (i in 1:20)
{test<-binom.test(i,20); width[i]<-test$conf[2]-test$conf[1]}
width
max(width)
## [1] 0.4560843
By examining the widths, we see that the greatest width (0.4560843) occurs for 10
successes.
Question 4
set.seed(17)
for (i in 1:1000)
{y<-sample(data,replace=TRUE);bm[i]<-mean(y)}
ci<-quantile(bm,c(0.005,0.995))
## 0.5% 99.5%
## 0.37043897 0.07517949
## [1] 0.183
(iii) Gamma
Using X ∼ Gamma(n , nλ), we have X ∼ Gamma(10,1.45)
xvals<-seq(0,20,by=0.01)
hist(xbar, prob=TRUE, main="Densities of the sample means from Exp(0.145)",
xlab="Sample means")
lines(xvals, dgamma(xvals, 10, 1.45), type="l", col="blue")
The histogram has
a similar shape to the gamma distribution.
## [1] 0.1957324
This gives an answer of 0.19573. There is about a 7% difference in the answers so they’re
not that close. # (v) (a) Simulation
set.seed(21)
sim<-rgamma(1000,10,1.45)