I want to feed a function into another function in R.
I have a function that I have named R and it has 1 argument which is PD. I want to create a second function called K which will have 2 arguments namely PD and LGD and it will feed the function R into function K
R = function(PD) {(0.12*(1-exp(-50*PD))/(1-exp(-50)) + 0.24*(1-(1-exp(-50*PD))/(1-exp(-50))))}
K = function(PD, LGD) {LGD*(dnorm(sqrt(1/(1-R))*qnorm(PD) + sqrt(R/(1-R))*qnorm(0.999)))}
K(0.1, 0.4)
When I run the code I get the following error;
R = function(PD) {(0.12*(1-exp(-50*PD))/(1-exp(-50)) + 0.24*(1-(1-exp(-50*PD))/(1-exp(-50))))}
K = function(LGD, PD) {LGD*(dnorm(sqrt(1/(1-R))*qnorm(PD) + sqrt(R/(1-R))qnorm(0.999)))} K = function(PD, LGD) {LGD(dnorm(sqrt(1/(1-R))*qnorm(PD) + sqrt(R/(1-R))*qnorm(0.999)))} K(0.1, 0.4) Error in 1 - R : non-numeric argument to binary operator'
R(PD)
Compare:1-sqrt
vs.1-sqrt(4)
– jogo