#R code for simulation to compare MLE and MOM estimator

set.seed(372)
y=(1:100)/100
n=length(y)
theta=.54

y1=(0:199)/200
y2=(1:200)/200
u=y2^(theta)
l=y1^(theta)
prob=u-l
sum(u-l)
ydist=rep(y2,round(10000*prob,0))
hist(ydist)
momvec=mlevec=rep(NA,100)

for (i in 1:200){
n=30
samp=sample(1:length(ydist),n)
#print(samp)
obsy=ydist[samp]
#print(obsy)
momvec[i]=mean(obsy)/(1-mean(obsy))
mlevec[i]=-n/(sum(log(obsy)))

}
par(mfrow=c(2,1))
hist(momvec,xlim=c(0,1),breaks=(0:17)/10)
abline(v=.54,lty=2)
mean(momvec)
var(momvec)
hist(mlevec,xlim=c(0,1),breaks=(0:17)/10)
abline(v=.54,lty=2)
mean(mlevec)
var(mlevec)