Hi,
I'm trying to calculate the value of the variable, dp, below, in the
argument to the integral of dnorm(x-dp) * pnorm(x)^(m-1). This
corresponds to the estimate of the sensitivity of an observer in an
m-alternative forced choice experiment, given the probability of
a correct response, Pc, a Gaussian assumption for the noise and
no bias. The function that I wrote below gives me an error:
Error in f(x, ...) : recursive default argument reference
The problem seems to be at the statement using uniroot,
because the furntion est.dp works fine outside of the main function.
I've been using R for awhile but there are still many nuances
about the scoping and the use of environments that I'm weak on
and would like to understand better. I would appreciate any
suggestions or solutions that anyone might offer for fixing
my error. Thank you.
dprime.mAFC <- function(Pc, m) {
est.dp <- function(dp, Pc = Pc, m = m) {
pr <- function(x, dpt = dp, m0 = m) {
dnorm(x - dpt) * pnorm(x)^(m0 - 1)
}
Pc - integrate(pr, lower = -Inf, upper = Inf,
dpt = dp, m0 = m)$value
}
dp.res <- uniroot(est.dp, interval = c(0,5), Pc = Pc, m = m)
dp.res$root
}
platform powerpc-apple-darwin6.8
arch powerpc
os darwin6.8
system powerpc, darwin6.8
status
major 2
minor 0.1
year 2004
month 11
day 15
language R
ken
____________________
Ken Knoblauch
Inserm U 371
Cerveau et Vision
18 avenue du Doyen Lepine
69675 Bron cedex
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: 06 84 10 64 10
problem using uniroot with integrate
3 messages · Ken Knoblauch, Sundar Dorai-Raj, Tony Plate
Ken Knoblauch wrote on 3/9/2005 10:27 AM:
Hi,
I'm trying to calculate the value of the variable, dp, below, in the
argument to the integral of dnorm(x-dp) * pnorm(x)^(m-1). This
corresponds to the estimate of the sensitivity of an observer in an
m-alternative forced choice experiment, given the probability of
a correct response, Pc, a Gaussian assumption for the noise and
no bias. The function that I wrote below gives me an error:
Error in f(x, ...) : recursive default argument reference
The problem seems to be at the statement using uniroot,
because the furntion est.dp works fine outside of the main function.
I've been using R for awhile but there are still many nuances
about the scoping and the use of environments that I'm weak on
and would like to understand better. I would appreciate any
suggestions or solutions that anyone might offer for fixing
my error. Thank you.
dprime.mAFC <- function(Pc, m) {
est.dp <- function(dp, Pc = Pc, m = m) {
pr <- function(x, dpt = dp, m0 = m) {
dnorm(x - dpt) * pnorm(x)^(m0 - 1)
}
Pc - integrate(pr, lower = -Inf, upper = Inf,
dpt = dp, m0 = m)$value
}
dp.res <- uniroot(est.dp, interval = c(0,5), Pc = Pc, m = m)
dp.res$root
}
Ken, Look at the argument list for ?uniroot and think "partial matching". You're "m" is being interpretted for "maxiter". Simply change to dp.res <- uniroot(est.dp, interval = c(0,5), Pc = Pc, m0 = m) and in other places for consistency and the error goes away. Of course, since you gave no working example, I'm not sure if other errors are present that I'm missing. --sundar
At Wednesday 09:27 AM 3/9/2005, Ken Knoblauch wrote:
Hi,
I'm trying to calculate the value of the variable, dp, below, in the
argument to the integral of dnorm(x-dp) * pnorm(x)^(m-1). This
corresponds to the estimate of the sensitivity of an observer in an
m-alternative forced choice experiment, given the probability of
a correct response, Pc, a Gaussian assumption for the noise and
no bias. The function that I wrote below gives me an error:
Error in f(x, ...) : recursive default argument reference
The problem seems to be at the statement using uniroot,
because the furntion est.dp works fine outside of the main function.
I've been using R for awhile but there are still many nuances
about the scoping and the use of environments that I'm weak on
and would like to understand better. I would appreciate any
suggestions or solutions that anyone might offer for fixing
my error. Thank you.
dprime.mAFC <- function(Pc, m) {
est.dp <- function(dp, Pc = Pc, m = m) {
pr <- function(x, dpt = dp, m0 = m) {
dnorm(x - dpt) * pnorm(x)^(m0 - 1)
}
Pc - integrate(pr, lower = -Inf, upper = Inf,
dpt = dp, m0 = m)$value
}
dp.res <- uniroot(est.dp, interval = c(0,5), Pc = Pc, m = m)
dp.res$root
}
You've got several problems here * recursive argument defaults: these are unnecessary but result in the particular error message you are seeing (e.g., in the def of est.dp, the default value for the argument 'm' is the value of the argument 'm' itself -- default values for arguments are interpreted in the frame of the function itself) * the argument m=m you supply to uniroot() is being interpreted as specifying the 'maxiter' argument to uniroot() I think you can fix it by changing the 'm' argument of function est.dp to be named 'm0', and specifying 'm0' in the call to uniroot. (but I can't tell for sure because you didn't supply a working example -- when I just guess at values to pass in I get numerical errors.) Also, it would be best to remove the incorrect recursive default arguments for the functions est.dp and pr. -- Tony Plate