0

我正在尝试使用 brms 包运行序数 logit 模型,但出现错误“找不到函数“累积”。我将其更改为 family =“累积”并且能够使其工作。是这些不同?

 bmodel<- brms::brm(pop ~  RDB2000pop + Temperature2003 + Population2003 +  
                              (1+RDB2000pop+Temperature2003+Population2003|species_id),
                 data      = dfpop_chenv,
                 family    = cumulative(link = "logit", threshold = "flexible"),
                 warmup    = 100,
                 iter      = 500,
                 chains    = 4,
                 cores     = 2) 
4

1 回答 1

1

发生这种情况是因为您brm()通过指定调用该函数brms::brm()。这意味着包中包含的其他功能cumulative()尚未加载。

我从 mtcars 包中制作了一些玩具序数数据,以使用以下代码重现错误:

mtcars$cyl <- as.ordered(mtcars$cyl)

然后,如果我尝试使用与您的代码相似的模型来拟合模型,则会遇到相同的错误:

m1 <- brms::brm(cyl ~ mpg,
          data = mtcars,
          family = cumulative(link = "logit", threshold = "flexible"))

Error in cumulative(link = "logit", threshold = "flexible") : 
  could not find function "cumulative"

但是,如果相反,我使用 加载包library(),我可以调用与您的代码类似的代码,并且模型适合没有问题。这是因为 Stan 提供的系列函数虽然brms通常在基础 R 中不可用。

library(brms)
m1 <- brm(cyl ~ mpg,
          data = mtcars,
          family = cumulative(link = "logit", threshold = "flexible"))

现在该模型在这里没有太大意义,但它没有问题。

summary(m1)
 Family: cumulative 
  Links: mu = logit; disc = identity 
Formula: cyl ~ mpg 
   Data: mtcars (Number of observations: 32) 
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
         total post-warmup samples = 4000

Population-Level Effects: 
             Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept[1]   -39.51     13.40   -72.37   -19.61 1.01      775      821
Intercept[2]   -34.24     11.83   -63.63   -16.48 1.01      827      863
mpg             -1.85      0.63    -3.42    -0.91 1.01      803      884

Family Specific Parameters: 
     Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
disc     1.00      0.00     1.00     1.00 1.00     4000     4000

Samples were drawn using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
于 2021-08-08T14:49:07.160 回答