[R] Simulation help
Richard Pugh
rpugh at mango-solutions.com
Sun Feb 22 20:46:50 CET 2004
Sorry - looks like the text wrapped when I sent this ... am resending
with better format, so you can read the code!
# This bit does the work ...
> poisNums <- rpois(100000, 3)
> normNums <- sapply(poisNums, rnorm, mean=3)
> sumNums <- sapply(normNums, sum)
# Produce a plot with quantiles ...
> 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)
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
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
---
Incoming mail is certified Virus Free.
______________________________________________
R-help at stat.math.ethz.ch 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.
More information about the R-help
mailing list