[R] truncated normal
    Thomas Lumley 
    tlumley at u.washington.edu
       
    Thu May  9 22:16:18 CEST 2002
    
    
  
On Thu, 9 May 2002 scott.ctr.summerill at tc.faa.gov wrote:
> Does anyone know of an R-function that will generate an observation from a
> truncated normal (left or right) with a mu and sigma2? Any correspondence
> would be greatly appreciated.
>
No, but you can do it by inverting the cdf
eg
  rtnorm<-function(n,mu,sigma2,left){
	lp<-pnorm(left)
	u<-lp+(1-lp)*runif(n)
	qnorm(u,m=mu,s=sigma2)
	}
	-thomas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
    
    
More information about the R-help
mailing list