Reputation: 31
I want to create a function a(v,x) using pnorm but with the standard deviation of pnorm that depends on x. R returns the error : non-numeric argument to mathematical function.
I am quite new to R so I don't really know how to handle the problem but i did not manage to find any answer elsewhere.
x0 = 6
R = 5
r = 2
p=0.5
sig = 5
sigR <- function(x){ sig*(x - r)*sqrt(p*(1-p))}
a <- function(v,x) {
pnorm(v + p*(x0-x) + (1-p)*(R-r), sd = sigR)
}
Thanks for the help.
Upvotes: 3
Views: 33
Reputation: 206253
Since sigR
is a function of x
, you need to pass the x
value to that function to get a constant out. The sd=
parameter expects a numeric value, not a function.
a <- function(v,x) {
pnorm(v + p*(x0-x) + (1-p)*(R-r), sd = sigR(x))
}
Upvotes: 3