vectores aleatorios discretos

ej.1

recordando el experimento: lanzamiento de dos dados justos

\(\small (X_1, X_2):\Omega \longrightarrow \{(i,j): i,j \in (1,2,3,4,5,6) \}\)

dado_1 <- sample(1:6, 1, replace = TRUE)
dado_2 <- sample(1:6, 1, replace = TRUE)

(v.a <- c(dado_1, dado_2))
## [1] 1 2

considerando la probabilidad conjunta de \((X_1,X_2)\)

library(ggplot2)

num_simulaciones <- 23

resultados_dados <- data.frame(X1 = sample(1:6, num_simulaciones, replace = TRUE),
                                X2 = sample(1:6, num_simulaciones, replace = TRUE))


ggplot(resultados_dados, aes(x = X1, y = X2)) +
  geom_point(aes(text = paste("X1:", X1, "X2:", X2)),shape=21, alpha = 0.9, size=3, color = "#52A8BC", fill="#A1D5D2", stroke=2) +
  labs(x = "X1 (Dado 1)", y = "X2 (Dado 2)")+
  theme_minimal()
## Warning in geom_point(aes(text = paste("X1:", X1, "X2:", X2)), shape = 21, :
## Ignoring unknown aesthetics: text

si queremos observar la función marginal de \(X_1\)

ggplot(resultados_dados, aes(x = factor(X1))) +
  geom_bar(stat = "count", width = 0.8, fill = "#DEB0D0", color = "#B57FA4", size=0.7, alpha=0.7) +
  labs(x = "X1 (Dado 1)", y = "frecuencia") +
  theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

ahora consideramos la suma de los posibles resultados \(Y=X_1+X_2\)

n_sim <- 100000

x1_x2 <- matrix(0, ncol = 2, nrow = n_sim)

for (i in 1:n_sim) {
  
  x1_x2[i, ] <- sample(1:6, 2, replace = TRUE)
  
}

#histograma

dataframe_x1_X2 <- data.frame(X1 = x1_x2[, 1], X2 = x1_x2[, 2])

library(ggplot2)

ggplot(dataframe_x1_X2, aes(x = factor(X1 + X2))) +
  geom_bar(color = "#52A8BC", fill="#A1D5D2", alpha = 0.7, size=0.7,width = 0.8) +
  labs(x = "suma de los dados (X1 + X2)",
       y = "frecuencia") +
  theme_minimal()

vectores aleatorios continuos

ej.1

simularemos \((X,Y) ~ Uniforme \overline{D}_1(x,y)\)

primero consideraremos su función conjunta \[f_{(X,Y)}(x,y) = \begin{cases} \frac{1}{\pi} & \text{si } x^2+y^2 \leq 1 \\ 0 & \text{e.o.c}\\ \end{cases} \]

usando el método de transformada inversa:

n <-341


U <- runif(n)
V <- runif(n)


X <- sqrt(U) * cos(2 * pi * V)
Y <- sqrt(U) * sin(2 * pi * V)

dataaaa <- data.frame(X,Y)

# esto solo para el circulo
theta <- seq(0, 2 * pi, length.out = 100)
circle_x <- cos(theta)
circle_y <- sin(theta)


ggplot(dataaaa, aes(x = X, y = Y)) +
  geom_point(color = "#DEB0D0", size = 1.9) +
  geom_path(data = data.frame(x = circle_x, y = circle_y),
            aes(x = x, y = y), color = "#B57FA4", size = 1) +
  labs(title = "simulación de (X,Y)",
       x = "X", y = "Y") +
  theme_minimal()