Obtaining the the Bernoulli distrubtion parameter theta using MME and MLE estimator. Then plotting the log(x,theta) and L(x,theta) estimator on the same graph #First generate 1000 random sample from the bernoulli distrubtion #Then select theta

n=1000;n
## [1] 1000
size=1;size
## [1] 1
thet1=0.56;thet1
## [1] 0.56
b=rbinom(n,size,thet1)
r=sum(b)

Obtain the MME of theta

MLE=r/1000
l=function(n,b,theta){return((theta^r)*(1-theta)^(n-r))}
theta=seq(0,1,0.001)

Obtaining the MLE

ll=function(n,b,theta){return(r*log(theta)+(n-r)*log(1-theta))}
likelihood=l(1000,r,theta)
loglikelihood=ll(1000,r,theta)

##Plotting the L(X,theta) and log(x,theta) graph

par(mar=c(5,5,5,5))
plot(theta,likelihood,main="Graph of the Bernoulli Distribution Likelihood and the Loglikelihood",pch=17,col="red",type="l")
abline(v=0.56)
par(new=TRUE)
plot(theta,loglikelihood,pch=17,col="purple",axes=FALSE,xlab="",ylab="",type="l")
legend("topleft",legend=c("likelihood","loglikelihood"),col=c("red","black"),lty=1,cex=0.8)
mtext("Loglikelihood",side=4,line=3)