[R] saving only part of a computation in integrate

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Jul 30 19:09:02 CEST 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Mary A. Marion
> Sent: Thursday, July 30, 2009 12:56 PM
> To: r-help at r-project.org
> Subject: [R] saving only part of a computation in integrate
> 
> Hello,
> 
> I am using
> Beta <-integrate(dnorm,mean=0,sd=1,-Inf,2.3552)
>  > Beta
> 0.9907436 with absolute error < 4.2e-06
> 
> 1-Beta results in an error
> How can I store into Beta only .9907436?
> 
> Thank you.
> 
> Sincerely,
> Mary A. Marion
> 

Take a look at the results of 

str(Beta)

List of 5
 $ value       : num 0.99
 $ abs.error   : num 4.22e-06
 $ subdivisions: int 4
 $ message     : chr "OK"
 $ call        : language integrate(f = dnorm, lower = -Inf, upper = 2.3552, mean = 0,      sd = 1)
 - attr(*, "class")= chr "integrate"

So it would appear that you could do

Beta <-integrate(dnorm,mean=0,sd=1,-Inf,2.3552)$value

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204
 




More information about the R-help mailing list