**From:** Simon Cullen (*cullens@tcd.ie*)

**Date:** Wed 05 May 2004 - 19:20:07 EST

**Next message:**Prof Brian Ripley: "Re: [R] Using integrate (was Discontinuities in a simple graph (machine precision?))"**Previous message:**Prof Brian Ripley: "Re: [R] Graphic size with X11 device"**Next in thread:**Prof Brian Ripley: "Re: [R] Using integrate (was Discontinuities in a simple graph (machine precision?))"**Reply:**Prof Brian Ripley: "Re: [R] Using integrate (was Discontinuities in a simple graph (machine precision?))"**Reply:**Peter Dalgaard: "Re: [R] Discontinuities in a simple graph (machine precision?)"**Reply:**Uwe Ligges: "Re: [R] Discontinuities in a simple graph (machine precision?)"**Reply:**Simon Cullen: "Re: [R] Discontinuities in a simple graph (machine precision?)"

Message-id: <opr7ir7te31pelvz@smtp.tcd.ie>

Hi,

I've got an ugly but fairly simple function:

mdevstdev <- function(a){

l <- dnorm(a)/(1-pnorm(a))

integrand <- function(z)(abs(z-l)*dnorm(z))

inted <- integrate(integrand, a, Inf)

inted[[1]]/((1- pnorm(a))*sqrt((1 + a*l - l^2)))

}

I wanted to quickly produce a graph of this over the range [-3,3] so I

used:

plotit <-function(x=seq(-3,3,0.01),...){

y<-sapply(x,mdevstdev)

plot(x,y,...)

}

*> plotit()
*

This produces the graph, but some discontinuities appear on it. I've

produced the same graph in Mathematica 5

(http://econserv2.bess.tcd.ie/cullens/R/DOverDelta.eps), and it was smooth

over this range (it takes ages to run, though). Is this a numerical

precision problem? Any suggestions on how to improve the precision?

I'm running R 1.9 on WinXP, PIII. I haven't changed any R parameters that

I know of.

-- SCSimon Cullen Room 3030 Dept. Of Economics Trinity College Dublin

Ph. (608)3477 Email cullens@tcd.ie

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

**Next message:**Prof Brian Ripley: "Re: [R] Using integrate (was Discontinuities in a simple graph (machine precision?))"**Previous message:**Prof Brian Ripley: "Re: [R] Graphic size with X11 device"**Next in thread:**Prof Brian Ripley: "Re: [R] Using integrate (was Discontinuities in a simple graph (machine precision?))"**Reply:**Prof Brian Ripley: "Re: [R] Using integrate (was Discontinuities in a simple graph (machine precision?))"**Reply:**Peter Dalgaard: "Re: [R] Discontinuities in a simple graph (machine precision?)"**Reply:**Uwe Ligges: "Re: [R] Discontinuities in a simple graph (machine precision?)"**Reply:**Simon Cullen: "Re: [R] Discontinuities in a simple graph (machine precision?)"

*
This archive was generated by hypermail 2.1.3
: Mon 31 May 2004 - 23:05:07 EST
*