Hi Reading the error message carefully you can see that f() is not defined at 0:
> uniroot(f, c(0, 1)) Error in uniroot(f, c(0, 1)) : f.lower = f(lower) is NA > f(0) [1] NaN If you plot f() in the interval (0,1) then you'll see there is two solutions: > uniroot(f, c(0.0001, 1)) Error in uniroot(f, c(1e-04, 1)) : f() values at end points not of opposite sign > uniroot(f, c(0.0001, 0.2)) $root [1] 0.1533901 $f.root [1] 0.3414232 $iter [1] 6 $estim.prec [1] 6.103516e-05 > uniroot(f, c(0.3, 1)) $root [1] 0.4699984 $f.root [1] -0.04112121 $iter [1] 8 $estim.prec [1] 6.103516e-05 > Yours sincerely / Med venlig hilsen Frede Aakmann Tøgersen Specialist, M.Sc., Ph.D. Plant Performance & Modeling Technology & Service Solutions T +45 9730 5135 M +45 2547 6050 fr...@vestas.com http://www.vestas.com Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement. Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Katherine Gobin > Sent: 6. januar 2014 12:42 > To: r-help@r-project.org > Subject: [R] Reversing the Equation to find value of variable > > Dear R forum > > I have following variables - > > EAD = 10000 > LGD = 0.45 > PD = 0.47 > M = 3 > > # Equation 1 > > R = 0.12*(1-exp(-50*PD))/(1-exp(-50)) + 0.24*(1-(1-exp(-50*PD))/(1-exp(- > 50))) > > b = (0.11852 - 0.05478 * log(PD))^2 > > K = (LGD * pnorm((1 - R)^(-0.5) * qnorm(PD) + (R / (1 - R))^0.5 * > qnorm(0.999)) - PD * LGD) * (1 - 1.5 * b)^(-1) * (1 + (M - 2.5) * b) > > RWA = K * 12.5 * EAD > > > > RWA > [1] 22845.07 > > # > __________________________________________________________ > _______ > > # MY Problem > > In the above part, knowing values of LGD, EAD, M and PD, the value of RWA > was calculated. However, I need to go reverse way in the sense knowing the > values of LGD, EAD, M and RWA, I need to find value of PD. > > So I have tried to use uniroot as (RWA - K * 12.5 * EAD and used the above > equations i place of K and R) > > RWA = 22845.07 > LGD = 0.45 > EAD = 10000 > M = 3 > > f = function(x) RWA - (LGD*pnorm((1-(0.12*(1-exp(-50*x))/(1-exp(- > 50))+0.24*(1-(1-exp(-50*x))/(1-exp(-50)))))^(-0.5)*qnorm(x)+((0.12*(1- > exp(-50*x))/(1-exp(-50))+0.24*(1-(1-exp(-50*x))/(1-exp(-50))))/(1-(0.12*(1- > exp(-50*x))/(1-exp(-50))+0.24*(1-(1-exp(-50*x))/(1-exp(- > 50))))))^0.5*qnorm(0.999))-x*LGD) * (1-1.5*((0.11852-0.05478 * > log(x))^2))^(-1)*(1+(M-2.5)*((0.11852-0.05478 * log(x))^2))*12.5*EAD > > uniroot(f, c(0,1), tol = 0.0000000001) > > I get following error - > > > uniroot(f, c(0,1), tol = 0.0000000001) > Error in uniroot(f, c(0, 1), tol = 1e-10) : f.lower = f(lower) is NA > > Kindly guide as I am not sure if uniroot is the correct way of doing it or > not. > Ideally, I should be getting the PD value of 0.47. > > With regards > > Katherine > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.