Questions tagged [rstan]

Relating to the R bindings for mc-stan

Filter by
Sorted by
Tagged with
0 votes
1 answer
57 views

CIs for random intercepts from gam and stan_gamm4 are similar, but those from gamm4 are not. why?

Question: how can one obtain a good confidence interval for the estimated random effects from gamm4? Motivation: The example below, using binomial data with a random intercept, shows that estimated ...
user avatar
0 votes
0 answers
93 views

Can we define inverse gamma priors in stan_glmer()?

Although I tried to read the manual, I don't quite see how I can incorporate the following model in stan_glmer(). $Y_{ij}|\mu_j,\sigma_y \sim N(\mu_j,\sigma_y^2)$ $\...
user avatar
  • 3,385
1 vote
1 answer
48 views

How to write proportionality in a Stan model?

I am having difficulties in writing the following equation into a Stan model. $$ y_i = \mu(x_i) + \epsilon_i \\ \epsilon_i \sim N(\theta,\sigma^2) \\ \mu(x_i) = a + b x_i \\ p(a) = p(b) \propto 1 \\ \...
user avatar
  • 11
1 vote
1 answer
62 views

Help with rstan models [closed]

I would need help in order to write a specific Stan model. The biological question The idea of the model is modeling the number of Bones (NbBones : discret ...
user avatar
0 votes
1 answer
61 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 ...
user avatar
0 votes
1 answer
102 views

Reporting guideline for bayesian using pd and ROPE

In the bayestestR articles, I came across the reporting guidelines that they recommend “the effect of X has a probability of pd of being negative (Median = median, ...
user avatar
  • 165
1 vote
0 answers
209 views

Is my Stan model correct? The Jeffreys prior for a heteroscedastic mixed-effects model

I am using rstan to obtain MCMC samples from a heteroscedastic mixed-effects model with different residual variances $\sigma_j^2$ for each experimental condition $j$. One assumption is the Jeffreys ...
user avatar
1 vote
0 answers
65 views

Find latent variable using rSTAN

I have the following simulated data: ...
user avatar
  • 673
0 votes
1 answer
287 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 ...
user avatar
  • 11
2 votes
0 answers
97 views

How to define informative priors from previous studies using stan_glm?

I am trying to develop a linear regression model for estimating stature from handprint measurements. I would like to employ the Bayesian approach and define informative priors from the previous ...
user avatar
  • 21
0 votes
1 answer
391 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 ...
user avatar
  • 93
2 votes
2 answers
251 views

Cross validation on a single model (not model comparison)

I understand the method of cross validation to be to leave out some part of a dataset (whether that be one data point at a time = LOO, or subsets = K fold), and train the model on some data, test the ...
user avatar
15 votes
4 answers
702 views

How best to deal with a left-censored predictor (because of detection limits) in a linear model?

Context: I'm new to Bayesian stats and am trying to fit a multiple regression with rstan. All variables are continuous and there is no hierarchical structure. One ...
user avatar
  • 13.2k
2 votes
2 answers
805 views

Need help understanding hurdle model specification and results interpretation

I am trying to use hurdle gamma model for one of my use cases, to handle a zero-inflated scenario. I have a very simple code creating dummy data with quite a few zeros. ...
user avatar
5 votes
2 answers
560 views

Are Jacobian adjustments necessary when the target parameter is a difference between two parameters in Stan?

[Note on cross-posting: This question has now been posted on the Stan Forums as well.] I want to model the index called Delta P (e.g., p.144 of this paper), which is basically a difference between two ...
user avatar
6 votes
1 answer
402 views

Why do model selection (AIC and LOO) outcomes differ between ML and bayesian approaches

I am interested in understanding whether my continuous data (dput code at bottom for reproducibility) are fit better by a linear model (Gaussian distribution) or a gamma distributed model. I ...
user avatar
1 vote
1 answer
143 views

Sample from the posterior of normal model using rstan?

I have a very simple Bayesian model $y_j \mid \mu ,\sigma^2 \sim N(\mu,\sigma^2)$, $\mu \sim N(0,100)$, $\sigma \sim InvGamma(0.01,0.01)$. I am try to sample from the posterior using ...
user avatar
  • 11
0 votes
0 answers
88 views

Fitting Bayesian Hierarchical Models in rSTAN

The model I have is $$ \begin{align*} y_{ij} & \sim Normal\left(\alpha_j + \beta x_i, \sigma^2\right)\\ \alpha_j &\sim Normal\left(\gamma_0 + \gamma_1 u_j, \tau^2\right) \end{align*} $$ Where $...
user avatar
0 votes
1 answer
63 views

the marginal likelihood of analytical result is different from that of bridge_sampler

I try to calculate the marginal likelihood of the example in the article " a tutorial on bridge sampling", which is estimating the marginal likelihood for a binomial model assuming a uniform prior on ...
user avatar
1 vote
0 answers
63 views

RStan v.s. simple lm for multivariate regression [closed]

I want to fit a multivariate linear regression, with $Y_1, \dots,Y_4$ as the response and $X_1,\dots,X_n$ as the explanatory variables. $X_1$ and $X_2$ are two components of a mixture, and $X_3,\dots ,...
user avatar
  • 133
2 votes
1 answer
287 views

Parameter Updates in Stan

I am working on an example in which I have obtained parameter estimates using Stan. In a real life scenario, I would receive more data every week. The data are covariates of a product which are used ...
user avatar
  • 813
5 votes
1 answer
1k views

Why is a Gelman-Rubin diagnostic of < 1.1 considered acceptable?

In multiple sources a Gelman-Rubin MCMC convergence diagnostic of less than 1.1 is considered evidence that chains have converged. For example in this thread: https://stackoverflow.com/questions/...
user avatar
3 votes
1 answer
318 views

Nonlinear sin model with brms

I try to fit sin function with brms using next code: ...
user avatar
1 vote
1 answer
104 views

Forward algorithm for ZIP - Hidden Markov model

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 ...
user avatar
1 vote
0 answers
484 views

Suggested noninformative hyperprior distributions?

I have a hierarchical model that includes a normal distribution and a beta distribution. For the normal distribution, it has two parameters: $\mu$ and $\tau^2$. However, I want to implement ...
user avatar
1 vote
1 answer
318 views

Should weights be applied in generated quantities block in stan?

I want to do predictions via generated quantities block in stan. I have two questions: Should the weights be applied again in the generated quantities block in addition to the likelihood in the ...
user avatar
  • 576
0 votes
1 answer
87 views

Curved regression lines

I had already asked a similar question here, but I'm experiencing the same problem for a different data-set and for a different family of mixed models. My response variable is a binary outcome of ...
user avatar
  • 47
0 votes
0 answers
105 views

Non-straight lines in random intercept random slope plots

I'm trying to see how boldness of individuals change over time. For this, I constructed a repeated measures random intercept random slope model with boldness scores (measured as latency to resume ...
user avatar
  • 47
0 votes
1 answer
118 views

Intercepts of repeated measures

I'm examining how boldness of individuals change with time. My data consists of individuals repeatedly measured across trials for boldness scores. First, I plotted each individual to see its mean and ...
user avatar
  • 47
0 votes
1 answer
48 views

how can this missing observation model be extended to include cases where sigma is a function of other variables?

Richard McElreath's blog entry Algebra and the Missing Oxen describes a simple missing observation model in RStan. At the end of the blog, he says it can be extended easily to cases in which the ...
user avatar
1 vote
1 answer
679 views

performance issues with linear mixed model

I am fitting a linear mixed model $y_{t} = \beta_0 + \beta_1x_{1t} + \beta_2x_{2t}+ \beta_{0i[t]} + \beta_{1i[t]}x_{1t} + \beta_{2i[t]}x_{2t} + \beta_{0j[t]} + \epsilon_t$ with ...
user avatar
  • 175
2 votes
1 answer
79 views

Modelling Parameter $r = \max\limits_{i = 1, \dots , 10} p_i - \min\limits_{i = 1, \dots , 10} p_i$ of Binomial Random Variable in Stan/RStan/R

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$,...
user avatar
  • 1,126
4 votes
1 answer
4k views

hurdle model with non-zero gaussian distribution in R

I have biomass data (continuous response variable). If sufficient data is collected, the log(Biomass) follows a normal distribution. However, I am separating the overall biomass by family (i.e., ...
user avatar
  • 43
1 vote
1 answer
231 views

Obtaining effect size from "rstanarm" package's linear regression

In my study a control group (c) is pretested (pre.c) and post-tested (pos.c). Similarly a ...
user avatar
  • 3,076
3 votes
0 answers
73 views

Is there a way to use the brms function bayes_factor without having to refit models to not have prior samples?

In the brms package the function bayes_factor allows you to compare two models. Personally, I prefer the WAIC or LOO methods of comparing, but it is helpful to have both these and bayes factors for ...
user avatar
  • 400
0 votes
0 answers
16 views

Is this a sensible way to examine the effects of x on y for two different groups?

Let's say I have data from a number of brain regions in both teenagers and adults. I want to know if brain regions b1, b2, etc (selected based on theory) differ in their effect on a normally ...
user avatar
  • 400
3 votes
1 answer
645 views

What exactly does it mean that a 90% Credible Interval is computationally stable?

I was reading the rstanarm documentation and came across this about its use of 90% intervals as the default. I was hoping someone might be able to provide some clarification. Default 90% intervals ...
user avatar
  • 400
1 vote
1 answer
74 views

Stan - find dimensions of an object - lower and upper question [closed]

I have a bunch of objects (roughly rectangular) , for some of which I know what their dimesions - x, y, and ...
user avatar
2 votes
0 answers
503 views

stan - 2 approaches to missing value imputation; which is better and why?

So, me and a colleague have to impute some data, x, given a categorical variable. We arrived at two different approaches: a) as in the tutorial: split x into x_obs and x_mis, and treat x_mis as ...
user avatar
2 votes
1 answer
759 views

Why does MCMCpack use normal priors when running Poisson regression?

I thought that since the conjugate prior of Poisson distribution is gamma, we needed to use that when assigning prior distributions to the beta coefficient. MCMCpack and rstanarm both specify a ...
user avatar
  • 21
1 vote
1 answer
206 views

How to add random walk in rstanarm [closed]

I have used rstanarm GLM model without the intercept like below in R ...
user avatar
  • 13