我正在使用Polya-Gamma潜变量技术维护一个使用BayesLogit
进行贝叶斯Logistic回归的包,并从马尔可夫链 - 蒙特卡罗(MCMC)返回样本。 BayesLogit
不再使用CRAN,我可以安装以前的版本
install_version("BayesLogit", version = "0.6")
但是这个黑客会阻止我的包裹提交给CRAN。 source code最近一年前更新过,所以我认为它不会再回到CRAN了。
我发现another package使用类似的语法做同样的事情。但是这个软件包也不在CRAN上并安装
devtools::install_github("kasparmartens/PolyaGamma")
CRAN包是否使用Polya-Gamma方案实现贝叶斯逻辑回归并返回MCMC样本?
我自己和同事处于类似情况(我们依赖BayesLogit的一个软件包,最终被归档),因此我们决定将我们为MATLAB开发的C ++ Polya-Gamma采样器实现打包成R软件包。它目前在CRAN上作为包pgdraw。从我们的测试来看,它实际上甚至比原始的BayesLogit包快一点。
我们决定使用RStan,因为它已经在CRAN上,我们已经在包的另一部分使用了它。对于实施贝叶斯回归的CRAN而言,我们对Polya-Gamma方案的偏好更强。
Stan文件包含:
// Code for 0-1 loss Bayes Logistic Regression model
data {
int<lower=0> n; // number of observations
int<lower=0> p; // number of covariates
matrix[n,p] x; // Matrix of covariates
int<lower=0,upper=1> y[n]; // Responses
real<lower=0> beta_sd; // Stdev of beta
}
parameters {
vector[p] beta;
}
model {
beta ~ normal(0,beta_sd);
y ~ bernoulli_logit(x * beta); // Logistic regression
}
我们称之为:
bayes_log_reg <- rstan::stan(stan_file, data = data, seed = seed,
iter = n_bootstrap * 2, chains = 1)
stan_bayes_sample <- rstan::extract(bayes_log_reg)$beta
有关完整的详细信息,请参阅the package vignette。
我意识到许多其他软件包在一般情况下实现了贝叶斯逻辑回归。