# Newton Raphson method for Example 1.6.5 y=c(6,5,4,6,6,3,12,7,4,2,6,7,4) ybar=mean(y) n=length(y) sy=sum(y) # no of iterations iter=10 theta=rep(NA,iter) U=rep(NA,iter) Uprime=rep(NA,iter) # newton raphson iterations theta[1]=1.0 for (i in 2:iter) { U[i]= -n + (sy/theta[i-1]) Uprime[i]= -sy/(theta[i-1])^2 theta[i]= theta[i-1]- (U[i]/Uprime[i]) } # Lets look at theta, U, Uprime theta U Uprime U/Uprime # and approximate Standard error for the estimate is se1=1/sqrt(-Uprime[iter]) # Due to the form of U and U' in this example # the Newton Raphson can also be obtained by theta=rep(NA,iter) theta[1]=0.5 for(i in 2:iter){theta[i]=2*theta[i-1]- (n/sum(y))*(theta[i-1]^2) } # The same as before but now using E(U') instead of U' theta=rep(NA,iter) U=rep(NA,iter) Uprime=rep(NA,iter) theta[1]=1.0 for (i in 2:iter) { U[i]= -n + (sy/theta[i-1]) Uprime[i]= -n/theta[i-1] theta[i]= theta[i-1]- (U[i]/Uprime[i]) } # Lets look again at theta, U, Uprime and se theta U Uprime U/Uprime se2=1/sqrt(-Uprime[iter]) # why did it work so great with E(U')?