[R] question with uniroot function

Uwe Ligges
Sat, 03 Sep 2011 16:59:39 -0000

On 03.09.2011 18:31, li li wrote:
> Dear all,
>     I forgot to mention the values for the parameters in the first email.
>
> u1<- -3
>
> u2<- 4
>
> alpha<- 0.05
>
> p1<- 0.15
>
>
>
> Thank you very much.
>
> 2011/9/3 li li<hannah.hlx at gmail.com>
>
>> Dear all,
>>     I have the following problem with the uniroot function. I want to
find
>> roots for the fucntion "Fp2" which is defined as below.
>>
>>
>> Fz<- function(z){0.8*pnorm(z)+p1*pnorm(z-u1)+(0.2-p1)*pnorm(z-u2)}
>>
>>
>> Fp<-
function(t){(1-Fz(abs(qnorm(1-(t/2)))))+(Fz(-abs(qnorm(1-(t/2)))))}
>>
>>
>> Fp2<- function(t) {Fp(t)-0.8*t/alpha}
>>
>>
>>
>> th<- uniroot(Fp2, lower =0, upper =1,
>>
>>             tol = 0.0001)$root
>>
>>
>> The result is 0 as shown below.
>>
>>
>>> th
>> [1] 0


No surprise, since

Fp2(0) is 0. And uniroot is finished then and does not need to evaluate
at a lower starting at some positive value such as:

  uniroot(Fp2, lower=1e-7, upper=1, tol=1e-7)

# 0.009521749


Uwe Ligges





>>
>> However, there should be a root between 0.00952 and 0.00955, since the
>> function values are of opposite signs as below.
>>
>>
>>> Fp2(0.00952)
>> [1] 2.264272e-05
>>> Fp2(0.00955)
>> [1] -0.0003657404
>>
>> Can any one give me a hand here? Thanks a lot.
>>         Hannah
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.