title: Find the second derivative of a log likelihood function
body: <p>I'm interested in finding the values of the second derivatives of the log-likelihood function for logistic regression with respect to all of my m predictor variables.</p>
  
  <p>Essentially I want to make a vector of m <i>&#x2202;</i><sup>2</sup>L/<i>&#x2202;</i><i>&beta;</i><sub>j</sub><sup>2</sup> values where j goes from 1 to m.</p>
  
  <p>I believe the second derivative should be -&Sigma;<sub>i=1</sub><sup><i>n</i></sup> x<sub>ij</sub><sup>2</sup>(e<sup><i>x</i><sub><i>i</i></sub><i>&beta;</i></sup>)/((1+e<sup><i>x</i><sub><i>i</i></sub><i>&beta;</i></sup>)<sup>2</sup>) and I am trying to code it in R. I did something dumb when trying to code it and was wondering if there was some sort of sapply function I could use to do it more easily.</p>
  
  <p>Here's the code I tried (I know the sum in the for loop doesn't really do anything, so I wasn't sure how to sum those values).</p>
  
  <pre><code>  for (j in 1:m)
    {
      for (i in 1:n)
      {
        d2.l[j] &lt;- -1*(sum((x.center[i,j]^2)*(exp(logit[i])/((1 + exp(logit[i])^2)))))
      }
    }
  </code></pre>
  
  <p>And logit is just a vector consisting of <i>X&beta;</i> if that's not clear.</p>