Questions tagged [rstan]

RStan is an API in R for the STAN programming language for Bayesian Statistical Inference.

Stan uses an R-like language for specifying statistical models, and has an R interface for compiling and running the markov chain analyses, and reporting the results back to R.

Links

299 questions
3
votes
0 answers

rstanarm: Visualise/extract data of evidence accumulation (shift from prior to posterior)

I would like to visualise the shift from the prior to the posterior as data is gathered (for each new data point). I can visualise both the prior and the posterior: library(ggplot2) library(rstanarm) library(insight) library(bayestestR) model <-…
Dominique Makowski
  • 1,511
  • 1
  • 13
  • 30
3
votes
1 answer

ZIP - Hidden Markov model r Stan

I'm trying to adjust a Zero Inflated Poisson Hidden Markov Model with Stan. For the Poisson-HMM in a past forum this setting was shown. see link. While to adjust the ZIP with the classical theory is well documented the code and…
Rafael Díaz
  • 2,134
  • 2
  • 16
  • 32
3
votes
1 answer

Integration in rstan

Is calculating double integration possible in "RStan"? I found in this link pda-in-stan that one dimensional integration is very slow. Please note that, the double integral is the part of the user-defined log likelihood function. If it is not…
gultu
  • 143
  • 10
3
votes
1 answer

Extract and add to the data values of the probability density function based on a stan linear model

Given the sample data sampleDT and models lm.fit and brm.fit below, I would like to: estimate, extract and add to the data frame the values of the density function for a conditional normal distribution evaluated at the observed level of the…
Krantz
  • 1,424
  • 1
  • 12
  • 31
3
votes
2 answers

Skip a specific test file on travis in R

My testing suite is made of multiple files. I would like to skip one of them on travis (the one related to fitting Bayesian models) because it takes to much time and fails. I know that I can skip specific tests with testthat::skip_on_travis().…
Dominique Makowski
  • 1,511
  • 1
  • 13
  • 30
3
votes
1 answer

Rcpp functions undefined when used alongside Stan

I have an R package that uses Rcpp for some internal functions. These functions are not exported for the user to access directly (see minimally reproducible example in the rcpptest repository). I am now attempting to add Stan code to the src/…
Jake Thompson
  • 2,591
  • 1
  • 16
  • 32
3
votes
1 answer

Stan Polynomial Regression Parameter Estimation Model Review

I have the following polynomial regression model: Image Version LaTeX Version $Y_i | \mu_i, \sigma^2 \sim \text{Normal}(\mu_i, \sigma^2), i = 1, \dots, n \ \text{independent}$ $\mu_i = \alpha + \beta_1 x_{i1} + \beta_2 x_{i2} + \beta_3 x_{i1}^2 +…
The Pointer
  • 2,226
  • 7
  • 22
  • 50
3
votes
1 answer

Problems with if() condition in Stan/RStan when modelling values from binomial random variable

I'm trying to use Stan and R to fit a model that, uhh, models the observed realisations y_i = 16, 9, 10, 13, 19, 20, 18, 17, 35, 55, which are from a binomial distributed random variable, say, Y_i, with parameters m_i (number of trials) and p_i…
The Pointer
  • 2,226
  • 7
  • 22
  • 50
3
votes
1 answer

Compilation ERROR, function(s)/method(s) not created! for brms model

I am having this error again. But unlike before, now the test below works: fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , ' return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ; ' ) fx( 2L, 5 ) # returns 10 as should be But when…
Krantz
  • 1,424
  • 1
  • 12
  • 31
3
votes
1 answer

Simulations of Exponential Random Variables in Stan (RStan Package/Interface)

I'm trying to do simulations of exponential random variables using RStan code. The R code for the simulated exponential random variables looks like this: A <- rexp(1000, 4) B <- rexp(1000, lambda2) C <- rexp(1000, lambda3) D <- rexp(1000,…
handler's handle
  • 375
  • 1
  • 2
  • 10
3
votes
1 answer

Set priors for multiple predictors in rstanarm?

I'm a bit confused on how to set priors for multiple predictors for the following model: require(rstanarm) wi_prior <- normal(0, sd(train$attendance)) SEED <- 101 fmla <- attendance ~ (1 + W + W1 + W2 + W3 + DivWin1 + DivWin2 + DivWin3 + …
ssp3nc3r
  • 3,662
  • 2
  • 13
  • 23
3
votes
0 answers

Error in socketConnection(master, port = port, blocking = TRUE, open = "a+b", : cannot open the connection in Stan (from R)

I am on a Macbook Pro Retina Display from 2012 running El Capitan with 8 cores according to parallel::detectCores(). My firewall is off. I am performing the following call from stan_lmer loaded from the rstanarm package. hierarchical.model.1 <-…
Brandon Sherman
  • 673
  • 1
  • 8
  • 25
3
votes
1 answer

How to run maximum likelihood optimization (BFGS) in STAN?

According to the STAN homepage, STAN is capable of penalized maximum likelihood (BFGS) optimization. I am using R package rstan but I haven't found any way how to use this method. I tried to look at the ?stan help for the stan() function, but the…
Tomas
  • 57,621
  • 49
  • 238
  • 373
2
votes
0 answers

Rstan error with Apple M1 chip in Mac OSX Montery/Ventura: "unknown target CPU 'apple-m1'"

I have been having trouble running rstan on my Macbook Pro since I updated to OSX 12. I have tried updating R, RStudio, rstan, XCode, OSX, and the problem persisted. Initially, the error was something along the line of "march=native not supported".…
bill.lihan
  • 21
  • 1
2
votes
0 answers

Writing the Jeffreys prior for a vector variable in Stan?

I am trying to model the Jeffreys prior for error variance in a heteroscedastic ANOVA design in rstan. That is to say, . Is the following setting correct? target += -2 * sum(log(sigma)); where the vector variable is declared as vector[C]…
1 2
3
19 20