a)
x<-rnorm(3, mean=2, sd=5) #a normal random sample of size 3 >x
xbar<-mean(x);xbar
## [1] 6.875829
y<-sum(x*c(1/6,1/3,1/2));y
## [1] 6.335921
xvec<-rep(0,1000)
yvec<-rep(0,1000)
for(i in 1:1000){x<-rnorm(3, mean=2, sd=5)
xvec[i]<-mean(x)
yvec[i]<-sum(x*c(1/6,1/3,1/2))}
MSEx<-var(xvec) #estimated MSE for X bar
MSEy<-var(yvec) #estimated MSE for Y
efficiency<-MSEy/MSEx
efficiency
## [1] 1.159835
data<-scan("/Users/Leland/Desktop/Stat 200/Datasets/Lab11data.txt")
logdata<-log(data)
coefficient<-sum(logdata)
Lp<-function(theta){100*log(theta) + (theta-1)*coefficient}
curve(Lp, from =1.5, to = 2.5)
estimatetheta<-mean(data)/(1-mean(data))
abline(v = estimatetheta, col = 'red', lty = 2)
f<-expression(100*log(theta) + (theta-1)*coefficient, 'theta')
D(f,'theta')
## 100 * (1/theta) + coefficient
f1<-function(theta){100 * (1/theta) + coefficient}
uniroot(f1,c(1.5,2.5))$root
## [1] 2.183815
curve(f1, from = 0, to =5)
abline(v = uniroot(f1,c(1.5,2.5))$root, col = 'red', lty =2)