stan

Developing Hierarchical Version of Nonlinear Growth Curve Model in Stan

ぐ巨炮叔叔 提交于 2019-12-06 19:52:29
The following model is model 1 of Preece and Baines (1978, Annals of Human Biology ), and is used to describe human growth. My Stan code for this model is as follows: ```{stan output.var="test"} data { int<lower=1> n; ordered[n] t; // age ordered[n] y; // height of human } parameters { positive_ordered[2] h; real<lower=0, upper=t[n-1]>theta; positive_ordered[2] s; real<lower=0>sigma; } model { h[1] ~ uniform(0, y[n]); h[2] ~ normal(180, 20); sigma ~ student_t(2, 0, 1); s[1] ~ normal(5, 5); s[2] ~ normal(5, 5); theta ~ normal(10, 5); y ~ normal(h[2] - (2*(h[2] - h[1]) * inv(exp(s[1]*(t - theta)

Calculating marginal effects in binomial logit using rstanarm

久未见 提交于 2019-12-06 13:15:47
I am trying to get the marginal effects, according to this post: http://andrewgelman.com/2016/01/14/rstanarm-and-more/ td <- readRDS("some data") CHAINS <- 1 CORES <- 1 SEED <- 42 ITERATIONS <- 2000 MAX_TREEDEPTH <- 9 md <- td[,.(y,x1,x2)] # selection the columns i need. y is binary glm1 <- stan_glm(y~x1+x2, data = md, family = binomial(link="logit"), prior = NULL, prior_intercept = NULL, chains = CHAINS, cores = CORES, seed = SEED, iter = ITERATIONS, control=list(max_treedepth=MAX_TREEDEPTH) ) # launch_shinystan(glm1) tmp <- posterior_predict(glm1,newdata=md[,.(x1,x2)]) Issue After running

How to use a distinct data set per chain in Stan?

China☆狼群 提交于 2019-12-06 13:01:15
问题 I have a data set with many missing observations and I used the Amelia package to create imputed data sets. I'd like to know if it's possible to run the same model in parallel with a different data set per chain and combine the results into a single Stan object. # Load packages library(Amelia) library(rstan) # Load built-in data data(freetrade) # Create 2 imputed data sets (polity is an ordinal variable) df.imp <- amelia(freetrade, m = 2, ords = "polity") # Check the first data set head(df

Sampling from prior without running a separate model

独自空忆成欢 提交于 2019-12-05 21:25:35
I want to graph the histograms of parameter estimates from a stan model against the priors for those parameters. I have tried doing this by running a model in stan, graphing it with ggplot2, then overlaying an approximation of the prior distribution using R's random generator function (e.g. rnorm() , rbinom() ) but I have run into many scaling issues that make the graphs impossible to get looking right. I was thinking a better way to do it would be simply to sample directly from the prior distribution and then graph those samples against the parameter estimates, but running a whole separate

Embedding Stan in C++ application

蓝咒 提交于 2019-12-05 13:55:38
I wanted to know whether it is possible to incorporate Stan in another C++ application. Since Stan is also written in C++, there should be a way. Currently, I am using RInside to achieve this but then you have all this data transferring which is time-consuming. What specifically did you want from Stan? We're going to separate out the math library into a standalone include for Stan 2.7 --- that contains all the matrix, probability, and autodiff code. Our repos already reflect this structure. All of the MCMC and transform and I/O code is callable through C++, as is the translator from a Stan

Highest Density Interval (HDI) for Posterior Distribution Pystan

拈花ヽ惹草 提交于 2019-12-05 07:08:55
问题 I am seeing that in Pystan, an HDI function can be used to provide a 95% credible interval surrounding the posterior distribution. However, they say it will only work for unimodal distributions. If my model may have a multimodal distribution (up to 4 peaks), is there a way I can find the HDI in Pystan? Thanks! 回答1: I wouldn't consider this a Stan/PyStan-specific issue. The Highest Density Interval is by definition a single interval and therefore inappropriate for characterizing multimodal

How to report with APA style a Bayesian Linear (Mixed) Models using rstanarm?

守給你的承諾、 提交于 2019-12-05 02:27:59
问题 I'm currently struggling with how to report, following APA-6 recommendations, the output of rstanarm::stan_lmer() . First, I'll fit a mixed model within the frequentist approach, then will try to do the same using the bayesian framework. Here's the reproducible code to get the data: library(tidyverse) library(neuropsychology) library(rstanarm) library(lmerTest) df <- neuropsychology::personality %>% select(Study_Level, Sex, Negative_Affect) %>% mutate(Study_Level=as.factor(Study_Level),

Probit regression with data augmentation in stan

天大地大妈咪最大 提交于 2019-12-05 01:00:43
问题 I am attempting to do a probit model with data augmentation using stan. This is where we have outcomes y either 0/1 that tell us the sign of the latent variable ystar . This is what I have so far, but I'm not sure how to add information in the model section about y . Any thoughts? data { int<lower=0> N; // number of obs int<lower=0> K; // number of predictors int<lower=0,upper=1> y[N]; // outcomes matrix[N, K] x; // predictor variables } parameters { vector[K] beta; // beta coefficients

MC-Stan on Spark?

假装没事ソ 提交于 2019-12-04 13:53:13
问题 I hope to use MC-Stan on Spark, but it seems there is no related page searched by Google. I wonder if this approach is even possible on Spark, therefore I would appreciate if someone let me know. Moreover, I also wonder what is the widely-used approach to use MCMC on Spark. I heard Scala is widely used, but I need some language that has a decent MCMC library such as MC-Stan. 回答1: Yes it's certainly possible but requires a bit more work. Stan (and popular MCMC tools that I know of) are not

How do I get standard errors of maximum-likelihood estimates in STAN?

老子叫甜甜 提交于 2019-12-04 08:38:03
问题 I am using maximum-likelihood optimization in Stan, but unfortunately the optimizing() function doesn't report standard errors: > MLb4c <- optimizing(get_stanmodel(fitb4c), data = win.data, init = inits) STAN OPTIMIZATION COMMAND (LBFGS) init = user save_iterations = 1 init_alpha = 0.001 tol_obj = 1e-012 tol_grad = 1e-008 tol_param = 1e-008 tol_rel_obj = 10000 tol_rel_grad = 1e+007 history_size = 5 seed = 292156286 initial log joint probability = -4038.66 Iter log prob ||dx|| ||grad|| alpha