Sebaran Normal Baku

u1 <- runif(100000,0,1)
u2 <- runif(100000,0,1)
z1 <- sqrt(-2*log(u1))*cos(2*pi*u2)
z2 <- sqrt(-2*log(u1))*sin(2*pi*u2)
z <- c(z1,z2)
plot(density(z))


Sebaran Normal dengan rata-rata = 5 dan standar deviasi = 4

u1 <- runif(100000,0,1)
u2 <- runif(100000,0,1)
z1 <- sqrt(-2*log(u1))*cos(2*pi*u2)
z2 <- sqrt(-2*log(u1))*sin(2*pi*u2)
z <- c(z1,z2)
x <- 4*z+5
plot(density(x))


Sebaran Chi-square db = 1

chi1<-function(n){
  u1<-runif(n,0,1)
  u2<-runif(n,0,1)
  z1<-sqrt(-2*log(u1))*cos(2*pi*u2)
  z2<-sqrt(-2*log(u1))*sin(2*pi*u2)
  z<-c(z1,z2)
  y<-z^2
}
x<-chi1(100000)
plot(density(x))


Sebaran Chi-square dengan db = 3

c<-chi1(100000)+chi1(100000)+chi1(100000)
plot(density(c))


Sebaran Eksponensial

eks<-function(n,lmd){
  u1<-runif(n,0,1)
  y<--1/lmd*log(u1)
}
y<-eks(100000,0.5)
plot(density(y))

hist(y)