pois_exp=function(n,nt,theta) { x=matrix(rpois(n*nt,theta),n,nt) theta_est=apply(x,2,cumsum)/(1:n) theta_emp_var=apply(theta_est,1,var) theta_emp_bias=apply(theta_est,1, mean)-theta Theo_bias=rep(0,n) Theo_var=theta/(1:n) CRLB=theta/(1:n) emp_MSE=theta_emp_var+(theta_emp_bias)^2 Theo_MSE= Theo_var+(Theo_bias)^2 par(mfrow=c(1,3)) plot(1:n, theta_emp_bias,type='l',ylab='Bias',xlab='n') lines(1:n,Theo_bias, col='blue') legend("topright", legend = c('Emp','Theo'),lty=1, col = c('black','blue')) plot(1:n, theta_emp_var,type='l',ylab='Variance',xlab='n') lines(1:n,Theo_var, col='blue') lines(1:n,CRLB[1:n], col='red') legend("topright", legend = c('Emp','Theo','CRLB'),lty=c(1,1,2), col = c('black','blue','red')) plot(1:n,emp_MSE,type='l',ylab='MSE',xlab='n') lines(1:n,Theo_MSE, col='blue') legend("topright", legend = c('Emp','Theo'),lty=1, col = c('black','blue')) par(mfrow=c(1,1)) return(list(theta_est,theta_emp_bias,theta_emp_var,Theo_bias, Theo_var, CRLB , emp_MSE,Theo_MSE)) } exp_exp=function(n,nt,theta) { x=matrix(rexp(n*nt,theta),n,nt) theta_est=1/(apply(x,2,cumsum)/(1:n)) theta_emp_var=apply(theta_est,1,var) theta_emp_bias=apply(theta_est,1, mean)-theta Theo_bias=theta/((1:n)-1) Theo_var=theta^2*(1:n)^2/(((1:n)-1)^2*((1:n)-2)) CRLB=theta^2/(1:n) emp_MSE=theta_emp_var+(theta_emp_bias)^2 Theo_MSE= Theo_var+(Theo_bias)^2 par(mfrow=c(1,3)) plot(3:n, theta_emp_bias[3:n],type='l',ylab='Bias',xlab='n') lines(3:n,Theo_bias[3:n], col='blue') legend("topright", legend = c('Emp','Theo'),lty=1, col = c('black','blue')) plot(3:n, theta_emp_var[3:n],type='l',ylab='Variance',xlab='n') lines(3:n,Theo_var[3:n], col='blue') lines(3:n,CRLB[3:n], col='red') legend("topright", legend = c('Emp','Theo','CRLB'),lty=c(1,1,2), col = c('black','blue','red')) plot(3:n, emp_MSE[3:n],type='l',ylab='MSE',xlab='n') lines(3:n,Theo_MSE[3:n], col='blue') legend("topright", legend = c('Emp','Theo'),lty=1, col = c('black','blue')) par(mfrow=c(1,1)) return(list(theta_est,theta_emp_bias,theta_emp_var,Theo_bias, Theo_var, CRLB , emp_MSE,Theo_MSE)) }