-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.Rmd
More file actions
74 lines (56 loc) · 2.57 KB
/
index.Rmd
File metadata and controls
74 lines (56 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
title: "R Lab for Statistical Computing"
author: |
| [Young-geun Kim](https://github.com/ygeunkim)
| [Department of Statistics](https://stat.skku.edu/stat/index.jsp), [SKKU](https://www.skku.edu/skku/index.do)
| [dudrms33@g.skku.edu](mailto:dudrms33@g.skku.edu)
date: "`r format(Sys.time(), '%d %b, %Y')`"
include-before:
- \newcommand{\iid}{\stackrel{iid}{\sim}}
- \newcommand{\indep}{\stackrel{indep}{\sim}}
- \newcommand{\hsim}{\stackrel{H_0}{\sim}}
- \newcommand{\ind}{\perp\!\!\!\perp}
- \newcommand{\R}{\mathbb{R}}
- $\DeclareMathOperator*{\argmin}{argmin}$
- $\DeclareMathOperator*{\argmax}{argmax}$
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
description: "This is a lab session for statistical computing."
---
# Welcome {-}
<img src="cover.png" width="250" height="375" alt="Cover image" align="right" style="margin: 0 1em 0 1em" /></a> Statistical computing mainly treats useful simulation methods.
```{r, eval=FALSE}
library(tidyverse)
```
`tidyverse` package family will be used in every chapter. Loading step is in `_common.R`, so it is not included in the text. Sometimes `data.table` library will be called for efficiency.
## Statistical Computing {-}
We first look at *random generation* methods. Lots of simulation methods are built based on this random numbers.
### Sampling from a fininte population {-}
Generating random numbers is like sampling. From finite population, we can sample data with or without replacement. For example of sampling with replacement, we toss coins 10 times.
```{r}
sample(0:1, size = 10, replace = TRUE)
```
Sampling without replacement: Choose some lottery numbers which consist of 1 to 100.
```{r}
sample(1:100, size = 6, replace = FALSE)
```
### Random generators of common probability distributions {-}
`R` provides some functions which generate random numbers following famous distributions. Although we will learn some skills generating these numbers in basis levels, these functions do the same thing more elegantly.
```{r dbrb, fig.cap="Beta(3,2) random numbers"}
gg_curve(dbeta, from = 0, to = 1, args = list(shape1 = 3, shape2 = 2)) +
geom_histogram(
data = tibble(
rand = rbeta(1000, 3, 2),
idx = seq(0, 1, length.out = 1000)
),
aes(x = rand, y = ..density..),
position = "identity",
bins = 30,
alpha = .45,
fill = gg_hcl(1)
)
```
Figure \@ref(fig:dbrb) shows that `rbeta()` function generate random numbers very well. Histogram is of the random number, and the curve is the true beta distribution.