Bài về nhà tuần 1
library(ggplot2)
library(extraDistr)
Poisson
Distribution
poisson <- rpois(10000, lambda = 1.5)
summary(poisson)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 1.000 1.000 1.472 2.000 8.000
var(poisson)
## [1] 1.46274
sd(poisson)
## [1] 1.209438
poisson <- table(poisson)
poisson <- as.data.frame(poisson)
ggplot(poisson, aes(poisson, Freq)) + geom_col(fill = 'red') + geom_point() + geom_line(aes(as.integer(poisson), Freq), color = 'yellow')

Student
Distribution
student <- round(rt(10000, df = 70),0)
summary(student)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -4.0000 -1.0000 0.0000 0.0175 1.0000 4.0000
var(student)
## [1] 1.105704
sd(student)
## [1] 1.051525
student <- table(student)
student <- as.data.frame(student)
ggplot(student, aes(student, Freq)) + geom_col(fill = 'green') + geom_point() + geom_line(aes(as.integer(student), Freq), color = 'red')

Chi_square
Distribution
chisquare <- round(rchisq(10000, df = 10),0)
summary(chisquare)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 7.000 9.000 9.928 13.000 39.000
var(chisquare)
## [1] 20.36685
sd(chisquare)
## [1] 4.512965
chisquare <- table(chisquare)
chisquare <- as.data.frame(chisquare)
ggplot(chisquare, aes(chisquare, Freq)) + geom_col(fill = 'purple') + geom_point() + geom_line(aes(as.integer(chisquare), Freq), color = 'yellow')

Binomial
Distribution
binomial <- rbinom(10000, size = 10, prob = 0.2)
summary(binomial)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 1.000 2.000 1.996 3.000 7.000
var(binomial)
## [1] 1.554138
sd(binomial)
## [1] 1.246651
binomial <- table(binomial)
binomial <- as.data.frame(binomial)
ggplot(binomial, aes(binomial, Freq)) + geom_col(fill = 'yellow') + geom_point() + geom_line(aes(as.integer(binomial), Freq), color = 'red')

Normal
Distribution
normal <- rnorm(n = 10000, mean = 1, sd = 4)
summary(normal)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -14.145 -1.726 1.017 1.010 3.756 17.335
var(normal)
## [1] 16.27791
sd(normal)
## [1] 4.034589
hist(normal)

Exponential
Distribution
exponential <- rexp(n = 10000, rate = 1)
summary(exponential)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000246 0.285396 0.701611 1.016285 1.415225 11.092827
var(exponential)
## [1] 1.04669
sd(exponential)
## [1] 1.023079
hist(exponential)

Triangular
Distribution
Triangular <- rtriang(10000, a = 2, b = 10, c = 6)
summary(Triangular)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.053 4.858 6.025 6.008 7.163 9.993
var(Triangular)
## [1] 2.629848
sd(Triangular)
## [1] 1.621681
hist(Triangular)
