# [R] Simulation help

Richard Pugh rpugh at mango-solutions.com
Sun Feb 22 18:40:31 CET 2004

Try this ...

poisNums <- rpois(100000, 3) # Calculate 100,000 poissons (mean 3)
normNums <- sapply(poisNums, rnorm, mean=3) # Calculate N random normals

# for each simulated poisson.  Normal distribution is mean 3, sd
1
sumNums <- sapply(normNums, sum)
mySeq <- seq(0.85, 1, length=50)
plot(seq(0.85, 1, length=50)*100, quantile(sumNums, mySeq), type="l",
main="Quantiles of simulated data", xlab="Quantiles", ylab="")
abline(h=quantile(sumNums, c(0.95, 0.99)), col=2, lwd=2)

R does this for me in about 20 seconds ...

Rich.

Mango Solutions
Tel : (01628) 418134
Mob : (07967) 808091

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
jonathan_wang at sbcglobal.net
Sent: 22 February 2004 17:18
To: r-help at stat.math.ethz.ch
Subject: [R] Simulation help

I am a new R user.  As a test, I want to write a simple code that does
the following simulation:

1. Randomly generate a number from a distribution, say, Poisson.  Let's
say that number is 3.
2. Randomly generate 3 numbers from another distribution, say, Normal.
3. Compute the sum of the numbers generated in step 2 and read it into a
vector, V.
4. Repeat steps 1 through 3 for 100,000 times.
5. Derive quantiles (e.g., 0.95th, 0.99th) of V.

Any help in getting me going would be greatly appreciated.

[[alternative HTML version deleted]]

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help