Thiha Naung
January,27, 2022
Example
x <- rnorm(10, 100, 1) # numbers in distribution, mean, standard deviation
x
[1] 100.28190 100.24831 100.57220 101.89139 99.60102 98.79762 99.53777
[8] 100.00382 99.75911 99.41948
x <- rbinom(10, 5, 0.5) # numbers of distribution, size, probability
x
[1] 2 2 4 4 2 1 4 3 3 2
x <- rpois(10, 4) # numbers of distribution, lambda
x
[1] 4 1 10 5 1 4 5 7 4 0
x <- rnorm(1000, 0, 1) # numbers of sample, mean, sd
results <- NA
for (i in c(1:10)){ # for loop for number-frequency times that you choose
s <- sample(x, 10, replace=TRUE) # size of the data that you want to sampling
results[i] <- mean(s) # calculate the mean and append the result to results
}
results
[1] 0.3406001 0.5451265 0.2838471 0.1782119 -0.5091241 0.2152859
[7] -0.1953038 -0.3199212 0.1879391 -0.3135394
par(mfrow=c(2,1))
hist(x, col = 'darkgray', border = 'white', main="ORIGINAL NORMAL DISTRIBUTION", xlim = c(min(x), max(x)))
hist(results, col = 'darkgray', border = 'white', main="SAMPLING DISTIBUTION", xlim = c(min(x), max(x)))