simulation.pdf
(
227 KB
)
Pobierz
Simulation
Roger D. Peng, Associate Professor of Biostatistics
Johns Hopkins Bloomberg School of Public Health
Generating Random Numbers
Functions for probability distributions in R
·
rnorm
: generate random Normal variates with a given mean and standard deviation
·
dnorm
: evaluate the Normal probability density (with a given mean/SD) at a point (or vector of
points)
·
pnorm
: evaluate the cumulative distribution function for a Normal distribution
·
rpois
: generate random Poisson variates with a given rate
2/15
Generating Random Numbers
Probability distribution functions usually have four functions associated with them. The functions are
prefixed with a
·
d
for density
·
r
for random number generation
·
p
for cumulative distribution
·
q
for quantile function
3/15
Generating Random Numbers
Working with the Normal distributions requires using these four functions
dnorm(x,
pnorm(q,
qnorm(p,
rnorm(n,
mean
mean
mean
mean
=
=
=
=
0,
0,
0,
0,
sd
sd
sd
sd
=
=
=
=
1,
log =
FALSE)
1,
lower.tail =
TRUE,
log.p =
FALSE)
1,
lower.tail =
TRUE,
log.p =
FALSE)
1)
If
Φ
is the cumulative distribution function for a standard Normal distribution, then
pnorm(q)
=
Φ(q)
and
qnorm(p)
=
Φ
−1
(p)
.
4/15
Generating Random Numbers
> x <- rnorm(10)
> x
[1]
1.38380206 0.48772671 0.53403109 0.66721944
[5]
0.01585029 0.37945986 1.31096736 0.55330472
[9]
1.22090852 0.45236742
> x <- rnorm(10,
20, 2)
> x
[1]
23.38812 20.16846 21.87999 20.73813 19.59020
[6]
18.73439 18.31721 22.51748 20.36966 21.04371
> summary(x)
Min. 1st Qu. Median
Mean 3rd Qu.
Max.
18.32
19.73
20.55
20.67
21.67
23.39
5/15
Plik z chomika:
mileymandy
Inne pliki z tego folderu:
Subsetting.pdf
(100 KB)
tapply.pdf
(62 KB)
reading_data_II.pdf
(84 KB)
Scoping.pdf
(185 KB)
reading_data_I.pdf
(101 KB)
Inne foldery tego chomika:
Pliki dostępne do 01.06.2025
Pliki dostępne do 09.04.2026
Pliki dostępne do 19.01.2025
●● BIZNES i PRACA
Absolwentka
Zgłoś jeśli
naruszono regulamin