相关测试的贝叶斯因子误差始终完美为0

时间:2018-10-11 00:32:45

标签: r bayesian

我编写了一个简单的函数,该函数使用BayesFactor包(https://richarddmorey.github.io/BayesFactor/)运行贝叶斯(BF)相关测试,并返回包含BF10(有利于替代)的数据帧,BF的错误,和用于计算BF的先验宽度。

以下是该函数的外观:

# setup 
library(magrittr)
set.seed(123)

# function 
bf_corr_test <-
  function(data,
           x,
           y,
           bf.prior = 0.707) {

    # creating a dataframe
    data <-
      dplyr::select(
        .data = data,
        x = !!rlang::enquo(x),
        y = !!rlang::enquo(y)
      ) %>%
      stats::na.omit(.)

    # extracting results from bayesian test and creating a dataframe
    bf_df <- BayesFactor::extractBF(
      x = BayesFactor::correlationBF(
        x = data$x,
        y = data$y,
        nullInterval = NULL,
        rscale = bf.prior
      ),
      logbf = FALSE,
      onlybf = FALSE
    ) %>% # converting to a tibble dataframe
      tibble::as_data_frame(.) %>% # removing unnecessary columns
      dplyr::select(.data = ., -time, -code) %>% # adding info about prior width
      dplyr::mutate(.data = ., bf.prior = bf.prior)

    # return the dataframe
    return(bf_df)

  }

但是,当我使用此功能时,无论我运行什么关联,该错误总是完美地为0。

# examples 

bf_corr_test(data = ggplot2::msleep, x = sleep_rem, y = brainwt)
#> # A tibble: 1 x 3
#>      bf error bf.prior
#>   <dbl> <dbl>    <dbl>
#> 1 0.654     0    0.707

bf_corr_test(data = mtcars, x = wt, y = mpg)
#> # A tibble: 1 x 3
#>          bf error bf.prior
#>       <dbl> <dbl>    <dbl>
#> 1 56223033.     0    0.707

bf_corr_test(data = iris, x = Sepal.Length, y = Petal.Width)
#> # A tibble: 1 x 3
#>        bf error bf.prior
#>     <dbl> <dbl>    <dbl>
#> 1 9.30e33     0    0.707

我是Bayes Factors的新手,但仍然不称职,因此我不确定这是BayesFactor中的错误还是预期的结果。有人可以帮我解决这个问题吗?

0 个答案:

没有答案