``` library(ggplot2) library(reshape2)

data <- datasets::mtcars data_mtcars <- data[, c(“mpg”,“disp”,“hp”,“wt”,“qsec”)]

#Matriks Korelasi cor_mtcars <- cor(data_mtcars) cor_mtcars

#Heatmap data_cor <-melt(cor_mtcars) ggplot(data_cor, aes(Var1, Var2, fill = value)) + geom_tile(color = “black”) + geom_text(aes(label = round(value, 2)), color = “black”) +

scale_fill_gradient2(low = “red”, high = “green”, mid = “yellow”, midpoint = 0, limit = c(-1, 1), name = “Korelasi”) + theme_minimal() + labs(title = “Heatmap Dataset mtcars”, x = “Variabel 1”, y = “Variabel 2) + theme(plot.title = element_text (hjust = 0.5), axis.text.x = element_text(hjust = 0.5))

bernoulli

bern<-function (x,p) {p^x* (1-p) ^ (1-x) } bern (1,3/6)

binomial

cmfbinom <- function(k, n, p) { # Validasi Input if (k < 0 || n < 0 || p < 0 || p > 1) { stop(“Input Tidak Valid”) } # Inisialisasi CMF
cmf <- 0 # Menghitung CMF
for (x in 0:k) { prob <- choose(n, x) * (p^x) * ((1 - p)^(n - x))
cmf <- cmf + prob }
return(cmf) } # Peluang paling sedikit 2 orang sembuh = 1 - P(X ≤ 1) Peluang = 1 - cmfbinom(1, 12, 0.2)
Peluang

poisson

cmfpois <- function(x, lambda) {
if (lambda <= 0) { stop(“Lambda Harus Bernilai > 0”) } if (x < 0) {
return(0) }
cmf <- 0
for (k in 0:x) { cmf <- cmf + (exp(-lambda) * (lambda^k) / factorial(k)) } return(cmf) } Peluang2 <- cmfpois(10, 2) - cmfpois(0, 2) Peluang2

geo<-function(x,p) {p*(1-p)^(x-1)} geo(5,0.3)

hyper<-function(x,N,n,k){(((factorial(k)/(factorial(k-x) * factorial(x))) * (factorial(N-k)/((factorial((N-k)-(n-x))) * (factorial(n-x)))))/(factorial(N)/(factorial(N-n)*factorial(n))))} hyper(2,100,10,5)