Questions tagged [rstan]

Relating to the R bindings for mc-stan

Filter by
Sorted by
Tagged with
0
votes
0answers
9 views

how to build an interaction model between two dummy variables

Morning, Everyone. I want to build an interaction model between two variables. But I keep getting the error message below: ============== SYNTAX ERROR, MESSAGE(S) FROM PARSER: No matches for: real[ ] *...
1
vote
0answers
48 views

Find latent variable using rSTAN

I have the following simulated data: ...
0
votes
1answer
16 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 ...
0
votes
0answers
19 views

How to interpret p-value from Bayesian?

My data example: ...
1
vote
0answers
54 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 ...
0
votes
0answers
19 views

RStan for multivariate distribution with different N1 and N2

I am new to RStan and trying to code this multivariate model up on RStan but it takes very long to load so i am assuming that there is probably a better code. $Y_1 = (Y_{1.1},Y_{1.2} . . . , Y_{1.n1})$...
0
votes
1answer
96 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
2answers
112 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 ...
0
votes
0answers
27 views

Best way to get a single sequence of states using Viterbi algorithm in Stan/R

I am writing this up because it seems like there should be a standard, easy way to do this and I just haven't found it. I wrote up my Viterbi algorithm in Stan as shown here in the Stan User's Guide, ...
13
votes
4answers
366 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 ...
2
votes
2answers
319 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. ...
0
votes
0answers
38 views

elpd_diff and se_diff

My comparision result from RSTAN is as below: elpd_diff se_diff fit2 0.0 0.0 fit4 0.0 0.0 fit3 -0.9 0.3 fit1 -1.8 2.7 ...
3
votes
2answers
206 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 ...
6
votes
1answer
204 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 ...
0
votes
0answers
89 views

Bayesian MMRM with Covariance Structure

I use a mixed model for repeated measures (MMRM) to model longitudinal continuous outcomes with individual random slopes. In the R package nlme, I use the following code to fit my data. ...
1
vote
1answer
58 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 ...
0
votes
0answers
55 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 $...
0
votes
1answer
23 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 ...
1
vote
0answers
48 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 ,...
1
vote
1answer
175 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 ...
3
votes
1answer
611 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/...
3
votes
1answer
226 views

Nonlinear sin model with brms

I try to fit sin function with brms using next code: ...
1
vote
1answer
83 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 ...
1
vote
0answers
364 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 ...
1
vote
1answer
208 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 ...
0
votes
1answer
72 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 ...
0
votes
0answers
88 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 ...
0
votes
1answer
79 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 ...
0
votes
1answer
47 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 ...
0
votes
1answer
369 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 ...
2
votes
1answer
70 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$,...
2
votes
1answer
2k 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., ...
1
vote
1answer
196 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 ...
3
votes
0answers
62 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 ...
0
votes
0answers
15 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 ...
3
votes
1answer
540 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 ...
1
vote
1answer
66 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 ...
2
votes
0answers
409 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 ...
1
vote
1answer
539 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 ...
1
vote
1answer
162 views

How to add random walk in rstanarm [closed]

I have used rstanarm GLM model without the intercept like below in R ...