0

How do we go about numerically solving equations of the sort below using R?

enter image description here

enter image description here

Please note, this can be shown to be convex and there is a separate thread on this. https://stats.stackexchange.com/questions/158042/convexity-of-function-of-pdf-and-cdf-of-standard-normal-random-variable

This question has been posted on the Mathematics Forum to get Closed Form or other Theoretical Approaches, but it seems numerically solutions are the way to go? https://math.stackexchange.com/questions/2689251/solving-equations-with-standard-normal-cdf-and-pdf-optimization

Ajean
  • 5,528
  • 14
  • 46
  • 69
texmex
  • 151
  • 9
  • Have you looked at these packages https://cran.r-project.org/web/views/Optimization.html? – Ralf Stubner Mar 14 '18 at 06:01
  • @RalfStubner ... Thanks for your suggestion. I had never come across these packages before. I briefly looked at it. Any further pointers you have would be greatly appreciated. – texmex Mar 14 '18 at 10:50

1 Answers1

1

You can use the build in optimize function to directly optimize the original function:

g <- function(x, xi) {
  (xi * x + dnorm(xi * x) / pnorm(xi * x))
}

fun <- function(x, xi, K) {
  K * g(x, xi) + (K - x) * g((K - x), xi)
}

optimize(fun, interval = c(0, 10), xi = 1, K = 1)
#> $minimum
#> [1] 1.173975
#> 
#> $objective
#> [1] 1.273246

Your original problem f(x) = g(x) can be formulated as a root finding problem f(x) - g(x) = 0. You can then use the uniroot function to solve that. See ?uniroot for details.

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
  • Wow, three lines :-) Thanks .. I will try it out and be in touch if any further questions. Could you also let me know how to solve such equations as shown above, which arise after taking FOC or derivatives on the original minimization problem. – texmex Mar 14 '18 at 11:24
  • @user249613 See expanded answer. – Ralf Stubner Mar 14 '18 at 11:30
  • @Thanks again for your very helpful and extremely easy to follow answers. – texmex Mar 14 '18 at 11:33