Saltar al contenido principal
LibreTexts Español

11.1.1: Frecuencia empírica (Sección 10.2.2)

  • Page ID
    150942
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Vamos a recorrer cómo calculamos la frecuencia empírica de lluvia en San Francisco.

    Primero cargamos los datos:

    # we will remove the STATION and NAME variables 
    # since they are identical for all rows
    SFrain <- read_csv("data/SanFranciscoRain/1329219.csv") %>% 
      dplyr::select(-STATION, -NAME)
      
    glimpse(SFrain)
    ## Observations: 365
    ## Variables: 2
    ## $ DATE <date> 2017-01-01, 2017-01-02, 2017-01-03, 2017-01…
    ## $ PRCP <dbl> 0.05, 0.10, 0.40, 0.89, 0.01, 0.00, 0.82, 1.…

    Vemos que el marco de datos contiene una variable llamada PRCP que denota la cantidad de lluvia cada día. Vamos a crear una nueva variable llamada RainToday que denota si la cantidad de precipitación estuvo por encima de cero:

    SFrain <- 
      SFrain %>%
      mutate(rainToday = as.integer(PRCP > 0))
    
    glimpse(SFrain)
    ## Observations: 365
    ## Variables: 3
    ## $ DATE      <date> 2017-01-01, 2017-01-02, 2017-01-03, 20…
    ## $ PRCP      <dbl> 0.05, 0.10, 0.40, 0.89, 0.01, 0.00, 0.8…
    ## $ rainToday <int> 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, …

    Ahora vamos a resumir los datos para calcular la probabilidad de lluvia:

    pRainInSF <- 
      SFrain %>%
      summarize(
        pRainInSF = mean(rainToday)
      ) %>%
      pull()
    
    pRainInSF
    ## [1] 0.2

    This page titled 11.1.1: Frecuencia empírica (Sección 10.2.2) 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; a detailed edit history is available upon request.