Saltar al contenido principal
LibreTexts Español

17.2: Simulación de valores p

  • Page ID
    150961
  • \( \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}}\)

    En este ejercicio realizaremos pruebas de hipótesis muchas veces para comprobar si los valores p proporcionados por nuestra prueba estadística son válidos. Muestrearemos datos de una distribución normal con una media de cero, y para cada muestra realizaremos una prueba t para determinar si la media es diferente de cero. Luego contaremos la frecuencia con la que rechazamos la hipótesis nula; ya que sabemos que la verdadera media es cero, estos son por definición errores de Tipo I.

    nRuns <- 5000
    
    # create input data frame for do()
    input_df <- tibble(id=seq(nRuns)) %>%
      group_by(id)
    
    # create a function that will take a sample
    # and perform a one-sample t-test
    
    sample_ttest <- function(sampSize=32){
      tt.result <- t.test(rnorm(sampSize))
      return(tibble(pvalue=tt.result$p.value))
    }
    
    # perform simulations
    
    sample_ttest_result <- input_df %>%
      do(sample_ttest())
    
    p_error <-
      sample_ttest_result %>%
      ungroup() %>%
      summarize(p_error = mean(pvalue<.05)) %>%
      pull()
    
    p_error
    ## [1] 0.048

    Deberíamos ver que la proporción de muestras conp<.05p< .05es de aproximadamente 5%.


    This page titled 17.2: Simulación de valores p 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.