我正在编写一些由同事汇编的代码,并expose_functions()
在brms
. 当我得到错误时(一旦我确定我没有粗心大意的东西),我开始了一个新的 R 会话,确保我的所有包等都已更新,然后再次尝试 - 同样的错误。
在这一点上,我去了小插图(这里)并运行了该代码 - 错误完全重复了。
以下是小插图的相关部分:
# Data
data("cbpp", package = "lme4")
# Custom family definition
beta_binomial2 <- custom_family(
"beta_binomial2", dpars = c("mu", "phi"),
links = c("logit", "log"), lb = c(NA, 0),
type = "int", vars = "vint1[n]")
# Stan function definition
stan_funs <- "
real beta_binomial2_lpmf(int y, real mu, real phi, int T) {
return beta_binomial_lpmf(y | T, mu * phi, (1 - mu) * phi);
}
int beta_binomial2_rng(real mu, real phi, int T) {
return beta_binomial_rng(T, mu * phi, (1 - mu) * phi);
}
"
# Stan variables
stanvars <- stanvar(scode = stan_funs, block = "functions")
# Model fit
fit2 <- brm(
incidence | vint(size) ~ period + (1|herd),
data = cbpp,
family = beta_binomial2,
stanvars = stanvars
)
# Expose functions
expose_functions(fit2, vectorize = TRUE)
这些都不是原始代码 - 它直接取自小插图。当我运行它时,我生成了 32 个警告和一个错误:
Error: $ operator is invalid for atomic vectors
这与我运行其他代码时发生的情况完全相同。我确定是我而不是代码,但我看不出我在哪里出错了。
以防万一它可以帮助任何人找到解决方案,这里是各种警告的列表(仅限唯一警告)。它们中的大多数看起来“无害”(基于此),但有些可能不是。
In file included from file656664715164.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/RcppEigen.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/RcppEigenForward.h:40:
In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/unsupported/Eigen/SparseExtra:51:
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:14:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
#pragma clang diagnostic pop
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/err/check_matching_dims.hpp:33:8: warning: unused variable 'error' [-Wunused-variable]
bool error = false;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/err/hmm_check.hpp:33:7: warning: unused variable 'n_transitions' [-Wunused-variable]
int n_transitions = log_omegas.cols() - 1;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/fun/gp_matern52_cov.hpp:275:10: warning: unused variable 'neg_root_5' [-Wunused-variable]
double neg_root_5 = -root_5;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/fun.hpp:183:
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/fun/log_mix.hpp:86:13: warning: unused variable 'N' [-Wunused-variable]
const int N = stan::math::size(theta);
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/prob/double_exponential_cdf.hpp:82:10: warning: unused variable 'N' [-Wunused-variable]
size_t N = max_size(y, mu, sigma);
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/prob/gaussian_dlm_obs_rng.hpp:98:7: warning: unused variable 'n' [-Wunused-variable]
int n = G.rows(); // number of states
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/prob/hmm_marginal.hpp:26:13: warning: unused variable 'n_states' [-Wunused-variable]
const int n_states = omegas.rows();
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/prob.hpp:315:
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/prob/std_normal_rng.hpp:23:22: warning: unused variable 'function' [-Wunused-variable]
static const char* function = "std_normal_rng";
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/prob.hpp:335:
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/prob/von_mises_cdf.hpp:72:10: warning: unused variable 'ck' [-Wunused-variable]
double ck = 50;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/src/stan/io/dump.hpp:778:15: error: no member named 'validate_dims' in namespace 'stan::io'
stan::io::validate_dims(*this, stage, name, base_type, dims_declared);
~~~~~~~~~~^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/src/stan/model/indexing/rvalue.hpp:610:13: warning: unused variable 'cols' [-Wunused-variable]
const int cols = rvalue_index_size(idxs.tail_.head_, x_ref.cols());
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/src/stan/model/indexing/rvalue_varmat.hpp:241:22: warning: unused variable 'x_cols' [-Wunused-variable]
const Eigen::Index x_cols = x.cols();
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/rev/core/operator_subtraction.hpp:88:43: warning: lambda capture 'b' is not used [-Wunused-lambda-capture]
[avi = a.vi_, b](const auto& vi) mutable {
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/rev/core/operator_minus_equal.hpp:24:16: note: in instantiation of function template specialization 'stan::math::operator-<double, nullptr>' requested here
vi_ = (*this - b).vi_;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/core/complex_base.hpp:136:9: note: in instantiation of member function 'stan::math::var_value<double, void>::operator-=' requested here
re_ -= x;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/core/operator_subtraction.hpp:24:5: note: in instantiation of function template specialization 'stan::math::complex_base<stan::math::var_value<double, void> >::operator-=<int>' requested here
y -= rhs;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/core/operator_subtraction.hpp:55:20: note: in instantiation of function template specialization 'stan::math::internal::complex_subtract<std::__1::complex<stan::math::var>, int>' requested here
return internal::complex_subtract(x, y);
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/fun/acosh.hpp:105:31: note: in instantiation of function template specialization 'stan::math::operator-<stan::math::var_value<double, void>, int>' requested here
auto y = log(z + sqrt(z * z - 1));
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/rev/fun/acosh.hpp:94:32: note: in instantiation of function template specialization 'stan::math::internal::complex_acosh<stan::math::var_value<double, void> >' requested here
return stan::math::internal::complex_acosh(z);
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/rev/core/operator_addition.hpp:84:43: warning: lambda capture 'b' is not used [-Wunused-lambda-capture]
[avi = a.vi_, b](const auto& vi) mutable {
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/rev/fun/grad_inc_beta.hpp:45:43: note: in instantiation of function template specialization 'stan::math::operator+<int, nullptr>' requested here
grad_2F1(dF1, dF2, a + b, var(1.0), a + 1, z);
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/rev/core/operator_addition.hpp:84:43: warning: lambda capture 'b' is not used [-Wunused-lambda-capture]
[avi = a.vi_, b](const auto& vi) mutable {
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/fun/trigamma.hpp:63:31: note: in instantiation of function template specialization 'stan::math::operator+<double, nullptr>' requested here
value = -trigamma_impl(-x + 1.0) + square(pi() / sin(-pi() * x));
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/rev/fun/trigamma.hpp:23:44: note: in instantiation of function template specialization 'stan::math::trigamma_impl<stan::math::var_value<double, void> >' requested here
inline var trigamma(const var& u) { return trigamma_impl(u); }