Dear R people The function below should be decreasing, convex, and tend to zero when x tends to infinity. curve((1-pnorm(x))/dnorm(x),from=0, to=9)>From the plot we see that for x between 8.0 and 8.3 the function isfluctuating. As far as I understand, this is due to the function pnorm() not being sufficiently accurate in the tails. I am using pnorm() in a way that has probably not been intended. So I guess this should not be considered a bug (??) The function can also be written as 1/lambda(x) where lambda(x) is the hazard rate for the normal distribution. Is there a way to calculate lambda(x) without using pnorm() ? Any help would be appreciated. Cheers Ole Christensen -- Ole F. Christensen Department of Mathematics and Statistics Fylde College, Lancaster University Lancaster, LA1 4YF, England -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> > Dear R people > > The function below should be decreasing, convex, and tend to zero when x > tends to infinity. > > curve((1-pnorm(x))/dnorm(x),from=0, to=9)This is not a good way to do this in R. Instead use the options log and tail: exp(pnorm(x,log=T,lower.tail=F)-dnorm(x,log=T)) This may eliminate your problem. (I hope I got those names right from memory.) Jim> > >From the plot we see that for x between 8.0 and 8.3 the function is > fluctuating. > > As far as I understand, this is due to the function pnorm() not being > sufficiently accurate in the tails. > I am using pnorm() in a way that has probably not been intended. > So I guess this should not be considered a bug (??) > > The function can also be written as 1/lambda(x) where lambda(x) is the > hazard rate for the normal distribution. Is there a way to calculate > lambda(x) without using pnorm() ? > > Any help would be appreciated. > > Cheers > > Ole Christensen > > > -- > Ole F. Christensen > Department of Mathematics and Statistics > Fylde College, Lancaster University > Lancaster, LA1 4YF, England > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ole Christensen wrote:> > Dear R people > > The function below should be decreasing, convex, and tend to zero when x > tends to infinity. > > curve((1-pnorm(x))/dnorm(x),from=0, to=9) > > >From the plot we see that for x between 8.0 and 8.3 the function is > fluctuating.You get a numerically more stable result by using logs: R> curve(exp(pnorm(x, lower.tail=FALSE, log.p=TRUE)-dnorm(x, log=TRUE)),from=0, to=9)> As far as I understand, this is due to the function pnorm() not being > sufficiently accurate in the tails. > I am using pnorm() in a way that has probably not been intended. > So I guess this should not be considered a bug (??) > > The function can also be written as 1/lambda(x) where lambda(x) is the > hazard rate for the normal distribution. Is there a way to calculate > lambda(x) without using pnorm() ? > > Any help would be appreciated. > > Cheers > > Ole Christensen > > -- > Ole F. Christensen > Department of Mathematics and Statistics > Fylde College, Lancaster University > Lancaster, LA1 4YF, England > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Use pnorm(x,lower.tail=FALSE) instead of 1-pnorm(x). The help page describes lower.tail, but it doesn't say explicitly that it's for this kind of situation. Ben Bolker On Wed, 13 Feb 2002, Ole Christensen wrote:> Dear R people > > The function below should be decreasing, convex, and tend to zero when x > tends to infinity. > > curve((1-pnorm(x))/dnorm(x),from=0, to=9) > > From the plot we see that for x between 8.0 and 8.3 the function is > fluctuating. > > As far as I understand, this is due to the function pnorm() not being > sufficiently accurate in the tails. > I am using pnorm() in a way that has probably not been intended. > So I guess this should not be considered a bug (??) > > The function can also be written as 1/lambda(x) where lambda(x) is the > hazard rate for the normal distribution. Is there a way to calculate > lambda(x) without using pnorm() ? > > Any help would be appreciated. > > Cheers > > Ole Christensen > > >-- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._