brms中的有序回归模型;错误 = 找不到函数 cumulative("logit")
Ordinal regression model in brms; Error =the function cumulative("logit") could not be found
我正在尝试 运行 带有 brms 包的序数 logit 模型,但我收到错误消息“找不到函数“cumulative”。我将其更改为 family =“cumulative”并且能够让它工作。这些有什么不同吗?
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)
发生这种情况是因为您通过指定 brms::brm()
调用了函数 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()
加载包,我可以调用与您的代码类似的代码,并且模型适合没有问题。这是因为尽管 brms 可从 Stan 获得的系列函数在基础 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).
我正在尝试 运行 带有 brms 包的序数 logit 模型,但我收到错误消息“找不到函数“cumulative”。我将其更改为 family =“cumulative”并且能够让它工作。这些有什么不同吗?
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)
发生这种情况是因为您通过指定 brms::brm()
调用了函数 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()
加载包,我可以调用与您的代码类似的代码,并且模型适合没有问题。这是因为尽管 brms 可从 Stan 获得的系列函数在基础 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).