Saltar al contenido principal
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
LibreTexts Español

11.2: Probabilidad Condicional (Sección 10.4)

( \newcommand{\kernel}{\mathrm{null}\,}\)

Determinemos la probabilidad condicional de que alguien no sea saludable, dado que tiene más de 70 años de edad, utilizando el conjunto de datos NHANES. Vamos a crear un nuevo marco de datos que

healthDataFrame <-
  NHANES %>%
  mutate(
    Over70 = Age > 70,
    Unhealthy = DaysPhysHlthBad > 0
  ) %>%
  dplyr::select(Unhealthy, Over70) %>%
  drop_na()

glimpse(healthDataFrame)
## Observations: 4,891
## Variables: 2
## $ Unhealthy <lgl> FALSE, FALSE, FALSE, TRUE, FALSE, TRUE,…
## $ Over70    <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALS…

Primero, ¿cuál es la probabilidad de tener más de 70 años?

pOver70 <- 
  healthDataFrame %>%
  summarise(pOver70 = mean(Over70)) %>% 
  pull()

# to obtain the specific value, we need to extract it from the data frame

pOver70
## [1] 0.11

Segundo, ¿cuál es la probabilidad de no ser saludable?

pUnhealthy <- 
  healthDataFrame %>%
  summarise(pUnhealthy = mean(Unhealthy)) %>% 
  pull()

pUnhealthy
## [1] 0.36

¿Cuál es la probabilidad para cada combinación de antisalud/saludablemente y mayores de 70/ no? Podemos crear una nueva variable que encuentre la probabilidad conjunta multiplicando las dos variables binarias individuales juntas; ya que cualquier cosa por cero es cero, esto solo tendrá el valor 1 para cualquier caso donde ambas sean verdaderas.

pBoth <- healthDataFrame %>% 
  mutate(
    both = Unhealthy*Over70
  ) %>%
  summarise(
    pBoth = mean(both)) %>% 
  pull()

pBoth
## [1] 0.043

Por último, ¿cuál es la probabilidad de que alguien no sea saludable, dado que tiene más de 70 años de edad?

pUnhealthyGivenOver70 <-
  healthDataFrame %>%
  filter(Over70 == TRUE) %>% # limit to Over70
  summarise(pUnhealthy = mean(Unhealthy)) %>% 
  pull()

pUnhealthyGivenOver70
## [1] 0.38
# compute the opposite:
# what the probability of being over 70 given that 
# one is unhealthy?
pOver70givenUnhealthy <-
  healthDataFrame %>%
  filter(Unhealthy == TRUE) %>% # limit to Unhealthy
  summarise(pOver70 = mean(Over70)) %>% 
  pull()

pOver70givenUnhealthy
## [1] 0.12

This page titled 11.2: Probabilidad Condicional (Sección 10.4) is shared under a not declared license and was authored, remixed, and/or curated by Russell A. Poldrack via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?