Questions tagged [stan]
Stan is software for Bayesian estimation using the No-U-Turn sampling (NUTS) algorithm instead of the simpler Gibbs sampling (BUGS).
270
questions
3
votes
1
answer
291
views
Visualizing the variable DAG in a stan / brms model
I would like to visualize the relationships between variables in the brms / stan models I write. I could make these myself for each model, but I'm hoping there's a package to generate them ...
8
votes
3
answers
2k
views
In Stan is there a way to use parameter posterior from old analysis as prior in new analysis?
Normally within the model block I might specify a prior on a parameter with
y ~ normal(mu, sigma);
But what if I already have a posterior on y from a previous ...
8
votes
3
answers
2k
views
Example where the posterior from Jags and Stan are really different and have real impacts on decisions using the model
I have seen many people claiming Stan is "much better" than JAGS, meaning roughly this: "although Jags is much faster, the quality of the samples is worse. So it's worth waiting for the ...
1
vote
0
answers
22
views
What is the difference between hierarchical modeling and setting a (fixed) prior on a parameter?
I was reading through Chapter 11 of Data Analysis using Regression & Multilevel Models, and was confused by a slight variation of a simple hierarchical model posed in the text.
Lets say I have a ...
3
votes
1
answer
501
views
How to get around to "Argument 'coef' may not be specified when using boundaries."?
I have a model, the brms code is given below. It is a system of equations (I am estimating demand for two categories of goods). Economic theory tells me that the ...
2
votes
0
answers
67
views
Can an outcome variable be used twice in the same model?
When is it appropriate to use the same outcome variable in two likelihoods in the same model framework?
Here is a specific example:
...
2
votes
1
answer
266
views
How to model a combination of measurement error and missing data in R and Stan
The data
Consider some simulated data:
...
1
vote
0
answers
29
views
Inconsistent posterior from hierarchical survival model
I asked about this question on Stan forum but no one replied so dual posting here. I'd really appreciate some insight, as I'm completely stuck.
I’m trying to do hierarchical survival modeling using ...
1
vote
2
answers
31
views
Incorporating neighboring years in multilevel model, estimated in Stan using brms
I am estimating a multilevel model in Stan, using the brms package. Specifically, I am estimating a model of the following form:
m1 <- brm(y ~ 1 + (1 | year))
...
1
vote
0
answers
54
views
How could I fit a model of a non-homogeneous Poisson process in STAN? [closed]
I have some data $t_1, t_2, ..., t_n$ where $0 < t_i < T$ for all $t_i$.
I assume that this has been generated by an inhomogeneous Poisson process with parameter $\lambda(t)$ defined again for $...
0
votes
0
answers
13
views
Using PCA to check if parameters simulated from a hierarchical Bayesian model are close to real parameters
I have a hierarchical Bayesian model that learns a 5-parameter function for each of the N participants. The priors on each of the 5 parameters are parameterized by a scale parameter, so, it also ...
2
votes
1
answer
83
views
Can you specify correlated coefficients in Stan models?
Closest question I could find to mine was this one, which doesn't cover it.
Is it possible to specify a correlation between two parameters in a Stan model? Consider a linear regression specified by:
$$...
0
votes
0
answers
17
views
Lotka-Volterra ordinary differential equation model to describe oscillations in a single observed entity
Background
The Lotka-Volterra model is the starting point for any model of ecological dynamics. It can be described as a set of two ordinary differential equations (ODEs) with varying complexity. ...
3
votes
1
answer
136
views
Choosing Bayesian Priors [duplicate]
I am fairly new to Bayesian Modeling, however I am experimenting with such framework in order to produce several estimates.
The part I am struggling the most with is the selection of prior ...
1
vote
1
answer
18
views
Efficient construction of correlation matrix—serial correlation
Given $\rho$, is there a way to efficiently construct this matrix (i.e., as a product of matrices, rather than using a for loop)?
$$
\Sigma =
\begin{pmatrix}
1 & \rho & \rho^2 &\cdots &...
2
votes
2
answers
824
views
Specifying specific priors for a correlation matrix via Stan
I'm trying to estimate a correlation matrix for a model where I already have a sense of the values of the off-diagonals based on existing studies. I'm quite new to Bayesian analysis so trying to learn ...
0
votes
0
answers
60
views
Why are my random effects and variance zero?
I'm trying to implement a logistic regression model with random effects and interactions. For some reason, when I remove an interaction between a parameter and a random effect parameter (Player and ...
1
vote
0
answers
41
views
Model test sensitivity to ability
I have a set of tests and a population of agents whose ability I want to assess. Each agent has taken some of the tests. The agents have no memory of the tests they have taken, so each time an agent ...
1
vote
1
answer
395
views
Reproduce results of bayesglm with stan_glm
As indicated in the title, I am trying to reproduce the
results of the bayesglm function with the stan_glm. In
principle, the ...
1
vote
1
answer
77
views
Centering prior distributions on MLE/OLS estimates
Andrew Gelman recommends placing weakly-informative $N(0, 1)$ priors on unknown parameters fitted in Stan and often does so in his own models. In Stan, the Normal distribution is parameterized by the ...
1
vote
0
answers
57
views
Bayesian model with maybe-missing data
Suppose we have data that come from a normal distribution with unknown $\mu$ and $\sigma$ parameters. The twist is that each value is missing with the given probability $p$, i.e. we observe a vector ...
1
vote
0
answers
62
views
Two different methods to plot residuals with rstan but two different distributions [closed]
The following is the first exercice of chapter 5 from the Book 'Bayesian Statistical Modeling with Stan, R and Python' of Kentaro Matsuura, 2023.
I am fitting a bayesian linear model in rstan and I ...
0
votes
1
answer
834
views
R Stan: Rejecting initial value error only with real data, not with simulated data
I am trying to fit a non-linear function to a dataset using Stan and R. I tested my model with a simulated dataset. It works nicely. However, as soon as I use real data that is formatted exactly the ...
2
votes
0
answers
31
views
How do I evaluate correlation of model parameters using MCMC posterior samples from a rstan fit?
Is there a better way to do so than simply by taking posterior parameter estimates and calculating the Spearman or Pearson correlation between them? Anything specific to having posterior samples from ...
0
votes
0
answers
25
views
Defining parameters so that they obey multiple constraints
I'd like to define parameters $\beta_i$ for $i=1,\ldots,I$ for a problem so that they automatically obey some constraints. The constraints are:
$\sum_{i=1,\ldots,I} w_i \beta_i = c_1$ and
$\sum_{i=1,\...
2
votes
0
answers
106
views
Probability that $\beta_A$ > $\beta_B$ using the posterior distributions directly
Suppose a regression coefficient was estimated in sample A (from country A) through a Bayesian linear regression model. The resulting posterior distribution, comprising 10,000 simulations, was ...
7
votes
1
answer
947
views
Fit a time series model with unknown lag in Stan
I try to fit a population time-series model in stan/rstan(2.7.0) where the death rate depends on the generation before (n-1) but the reproduction depends on a unknown generation (n-x). I haven't found ...
3
votes
2
answers
112
views
In Bayesian linear regression Advantages of predictive posterior compared to posterior of model coefficients
In Bayesian linear regression, if we want to get confidence intervals for predictions of a new observation. I was thinking of the following two options.
Use the quantiles from samples sampled from ...
2
votes
0
answers
75
views
Generalized Difference in Differences model: time*group interaction contradicts lift
I've constructed a Bayesian Generalized Difference in Differences model. I model an intercept as well as three coefficients; one for treatment_group assignment, one for post-start period, and one for ...
0
votes
0
answers
16
views
Intermediate variables in Bayesian model for binomial data
Let us assume we have the data modeled $D|\pi\sim Binomial (N,\pi)$, where we assume $N$ is given throughout. We also have that $\pi|\theta \sim V( \theta )$ where $V$ is a known distribution and $\...
0
votes
1
answer
33
views
Modeling simple longitudinal data, unknown trend
Suppose I have many sensors recording a certain measure at discrete times (not too many times, something around 20/30 max). I want to get an idea of the average trend of the measure over time without ...
1
vote
1
answer
332
views
Intraclass Correlation Coefficient with Bayesian ordered-logit GLMM (STAN)
I am fitting a Generalized Linear Mixed Model for an ordered outcome, in form of an ordered logit, with random intercept and slope. For this task, I am going Bayesian by handling STAN through the ...
0
votes
1
answer
138
views
How can I solve identifiability problems in my STAN estimation?
So I am trying to validate my STAN model before using real data and am having some trouble estimating parameters separately. My data structure contains count data with people on the rows, and test ...
1
vote
0
answers
51
views
Power of Bernoulli likelihood in Jags (R2jags) [closed]
In a fixed power prior model, the model is set up as:
$$ \pi(p_i \mid \alpha,\mathcal{D}_0) \propto L(p_i\mid \mathcal{D}_0)^{w} \pi(p_i) $$
Suppose that the event follows a Bernoulli distribution ...
10
votes
2
answers
5k
views
Low effective sample size but good R-hat is this a problem?
I am using Stan (Hamiltonian Monte-Carlo) to run a highly paramaterized model. One of the parameters in particular has a very low effective sample size (n_eff < .10*number of retained draws), but ...
1
vote
0
answers
49
views
Multilevel Bayesian model for Experimental Design with levels in treatment and control groups
Context
I'm designing an experiment and Bayesian analysis to interpret results. I've used Statistical Rethinking as inspiration for model structure.
Suppose I want to study the effects of a sports ...
1
vote
0
answers
129
views
When and how to use approximate leave-future-out cross-validation on hierarchical time series Stan model
I am fitting a hierarchical state space AR(1) model in Stan and am struggling use common model evaluation metrics on the model output. Computing the WAIC or using loo_cv in the loo package give ...
1
vote
1
answer
405
views
What is the correct bayesian formulation for the zero-truncated Poisson lognormal model?
In ecology we use compound distributions to describe species-abundance data. One example is the Poisson Lognormal (PLN) distribution which is a Poisson distribution with rate parameter $\lambda$ that ...
1
vote
0
answers
172
views
Why am I getting very different results from jags and stan
Why am I getting different results from jags and stan in a simple linear regression model?
Using Sepal.Length ~ Petal.Length in the ...
0
votes
0
answers
65
views
Latent variable estimation with fixed effects
I have survey data on political beliefs that I'd like to estimate latent ideology with. Survey questions are binary agree/disagree responses. However, respondents can repeat the survey and skip any ...
1
vote
0
answers
24
views
Find probability of students to cheat with Bernoulli model [closed]
I have been trying to solve this for a long time now, but I still can't figure it out.
Background of the problem:
I have data on two exams. There were suspicions that many people cheated on the first ...
0
votes
0
answers
68
views
Stan: modulated distribution
I am modeling a process where events happen every X days with X following a gamma distribution. I already have a model for that ...
1
vote
0
answers
128
views
Using survival analysis parameters from multilevel model as a workaround for censored predictor?
I am interested in predicting psychopathology development over time using survival parameters from the survival model.
I have data collected using ESM in daily life during which individuals reported ...
0
votes
1
answer
25
views
How to fit a stand model with two nested multiplications to mu
I'm studying the Statistical Rethinking 2ed book and trying to write the codes to Stan (I'm using pystan). And stuck on how to write the model below in stan.
This problem is described in the book page ...
1
vote
1
answer
50
views
Mixture of Two Normals
Suppose we have a data which consists of two normals,
x = rnorm(50,mean=1,sd=2)
y = rnorm(50,mean=2,sd=3)
z = sample( c(x,y) , size = 100, replace=FALSE )
The goal ...
0
votes
1
answer
731
views
How to extract predicted values from stan_lmer()
I fitted a stan_lmer model and tried to extract predicted (predict() function) but R suggested me to use posterior_predict() but cannot at this point plot the predicted vs observed plot, as I have a ...
1
vote
1
answer
143
views
Using a Generalized Beta Distribution of the Second Kind as a Prior in Stan Linear Regression
So I'm considering a simple linear regression model with $p = 1$ predictor $$y = \beta x + \epsilon$$ where $\epsilon \sim N(0,\sigma^2)$. I want to use a generalised beta distribution of the second ...
2
votes
2
answers
1k
views
Bayesian estimation of GEE models
I'm facing a problem where I want to model a GEE with a tweedie distribution but it's not implemented in any R package that I found.
I know that GEEs and linear mixture models (LMM) are somehow ...
3
votes
1
answer
2k
views
Default Priors for Intercept and Standard Deviations in R package brms
The only resource I found explaining the default priors in brms is its manual (newest version, updated 03/14/2021) for function set_prior().
For the intercept, the manual does not specify how the ...
0
votes
1
answer
314
views
How do I write the Jeffreys prior for error variances in stan? $p(\mu, \sigma_1^2, \dots, \sigma_C^2) \propto \Pi{ \sigma_i^{-2}}$ [closed]
I need to model the Jeffreys prior for error variances in a heteroscedastic ANOVA design in rstan.
That is to say, $\pi(\mu,\sigma_1^2,\dotsb,\sigma_C^2)\varpropto\Pi_{i=1}^{C}\sigma_i^{-2}$.
Is the ...