title: Newton Raphson for logistic regression
body: <p>I did code for Newton Raphson for logistic regression. Unfortunately  I tried many data there is no convergence. there is a mistake I do not know where is it. Can anyone help to figure out what is the problem.</p>
  
  <p>First the data is as following; y indicate the response (0,1) , Z is 115*30  matrix which is the exploratory variables. I need to estimate the 30 parameters.</p>
  
  <pre><code>y = c(rep(0,60),rep(1,55))
  X = sample(c(0,1),size=3450,replace=T)
  Z = t(matrix(X,ncol=115))
  #The code is ;
  B     = matrix(rep(0,30*10),ncol=10)
  B[,1] = matrix(rep(0,30),ncol=1)
  for(i in 2 : 10){
    print(i)
    p       &lt;- exp(Z %*%as.matrix(B[,i])) / (1 + exp(Z %*% as.matrix(B[,i])))
    v.2     &lt;- diag(as.vector(1 * p*(1-p)))
    score.2 &lt;- t(Z) %*% (y - p) # score function
    increm  &lt;- solve(t(Z) %*% v.2 %*% Z) 
    B[,i]   =  as.matrix(B[,i-1])+increm%*%score.2
    if(B[,i]-B[i-1]==matrix(rep(0.0001,30),ncol=1)){
      return(B)
    }
  }
  </code></pre>