[R] Simulation / bayesian model

Chuck Cleland ccleland at optonline.net
Thu Jun 15 19:16:23 CEST 2006


Ahmed Elhabti wrote:
> Hi,
>    
>   (In the bayesian model, this program makes estimate the value of theta (tn)
>   with the empirical method.)
>    
>   I want to know how one can repeat this program 100 times, before to have 100 estimated values of tn.
>    
>   This is the program:
>    
>   a<-1 
> theta<-rexp(50,a)
> x<-rpois(length(theta),theta)
>   t<-rexp(a)
>   xn<-rpois(1,t)
>   tn<-(1+xn)*mean(x)/(1+mean(x))
>   tn

  my.tn <- function(){
    a <- 1
    theta <- rexp(50,a)
    x <- rpois(length(theta),theta)
    t <- rexp(a)
    xn <- rpois(1,t)
    tn <- (1+xn)*mean(x)/(1+mean(x))
    return(tn)
  }

  replicate(100, my.tn())
   [1] 0.5575221 0.5192308 1.0099010 1.2954545
   [5] 0.4949495 1.0099010 0.5238095 0.4791667
   [9] 1.8494624 1.4693878 0.5098039 0.8235294
  [13] 0.5495495 0.4565217 0.5726496 1.4042553
  [17] 0.5798319 2.2826087 1.0909091 1.0000000
  [21] 0.5327103 0.4623656 1.0291262 0.7804878
  [25] 1.4536082 0.9690722 0.9795918 0.8888889
  [29] 0.5049505 0.5762712 0.4680851 0.4623656
  [33] 0.5327103 1.3516484 0.9247312 0.4505495
  [37] 0.8888889 0.5238095 1.7394958 0.5614035
  [41] 0.5412844 0.5454545 1.0099010 0.4382022
  [45] 0.4444444 0.5000000 0.9898990 0.4444444
  [49] 0.9795918 1.7777778 0.5192308 1.0196078
  [53] 0.4505495 0.5454545 1.4693878 2.2300885
  [57] 0.5238095 0.5098039 1.8021978 1.9591837
  [61] 0.4047619 1.0654206 0.5283019 0.4680851
  [65] 0.5652174 2.5490196 1.1735537 1.0566038
  [69] 2.1308411 2.5728155 0.4186047 1.0099010
  [73] 0.4897959 1.3695652 0.4897959 1.0825688
  [77] 0.5145631 0.4382022 1.0476190 0.5145631
  [81] 0.5535714 0.4565217 0.5238095 0.4680851
  [85] 0.4736842 0.5098039 0.5327103 1.9381443
  [89] 0.5454545 0.5238095 0.5412844 0.4117647
  [93] 0.4444444 1.1379310 0.5327103 1.0990991
  [97] 0.4382022 0.4444444 1.1803279 0.5967742

?replicate

>   Thank you very much.
> 
>  __________________________________________________
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list