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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: 22 February 2004 17:18 To: [EMAIL PROTECTED] 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]] ______________________________________________ [EMAIL PROTECTED] 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 --- Incoming mail is certified Virus Free. ______________________________________________ [EMAIL PROTECTED] 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