# Using nls in place of the delta method

*This was originally posted at Point Mass Prior and features MathML. If you’re viewing from StatsBlogs the math probably won’t show up properly and it would be beneficial to view the post here*.

It’s been a while since my last post which was on using the delta method in R with a specific application to finding the ‘x’ value that corresponds to the maximum/minimum value in a quadratic regression. This post will be about how to do the same thing in a slightly different way. Quadratic regression can be fit using a linear model of the form

where are independent and identically distributed normal random variables with mean 0 and a variance of . However, if our concern is on the ‘x’ value that provides the minimum/maximum value and possibly the value of the response at the minimum/maximum we can reformulate the model as

So that the x value that corresponds to the minimum/maximum is represented directly through the parameter . The actual minimum/maximum value is also represented as a parameter in the model as . In this case can be interpreted as half of the second derivative with respect to x but that isn’t as much of an interest here. Note that we can expand this model out to get the same form as the linear model so it really is representing the same model but notice that we don’t actually have a *linear* model anymore.

To fit this we would need to use something other than `lm`

. The natural choice in R is to use `nls`

. We’ll look at an example of how to fit this model and get confidence intervals for the quantities of interest. We’ll use the same simulated data as my previous post so we can compare how the delta method and nls compare for this problem.

As a reminder the exact model we fit previously was where so to write it using the same form as our nonlinear model we have . So the maximum occurs at and produces an output of 25 at that location.

Now we fit our model using `nls`

. We need to provide starting values for the parameters since it fits using an iterative procedure. I provide some pretty bad starting values here but it still fits its just fine.

Now we can look at the output we get

We see that the estimated value at which the maximum occurs is 5.1903. If we go back to the delta method post we see that we obtained the same estimate. Another interesting point is the the standard error for this term is the same as we obtained using the delta method. In both cases we get a standard error of 0.2652

We can easily obtain a confidence interval for this using `confint`

Now recall that we used the asymptotic normality of the transformation applied when we used the delta method to obtain a confidence interval so that previous interval which went from 4.671 to 5.710 was based on a normal distribution assumption. When using confint with a nls object it uses t-based methods to get a confidence interval so it will be a little bit wider. Recall that we have the same estimate and the same standard error as when we used the delta method so if we want we could get the same interval based on asymptotic normality as well. Alternatively if you use `confint.default`

it will use a normal distribution to create your confidence intervals

And here we see that we get the same confidence interval as when we used the asymptotic normality argument to get the confidence intervals for the delta method approach.