I saw already a similar question, but I can´t figure out, how to do. Maybe you can help.
Back solving a function or goal seek in R
ES <- function(y, z){-y * (1-pnorm(y/z)) + z * dnorm(y/z)} # = x
ES(906.19, 707.1) #33.47587
What I want is to solve for y, so z and x (33.4) is known. I have seen the solve and optim function, but I am not able to get the expected result.
Thanks!
We can use uniroot
to find the root of ES(y, z) - x
for y
given values z = 707.1
and x = 33.4
.
ES <- function(y, z) -y * (1 - pnorm(y / z)) + z * dnorm(y / z)
res <- uniroot(function(x, y, z) ES(y, z) - x, c(0, 1000), z = 707.1, x = 33.4)
The solution for y
is then
res$root
#[1] 906.9494
We confirm that E(y, z) = x
ES(res$root, 707.1)
#[1] 33.4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With