Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use Shinystan to look at rstanarm glmer results #128

Closed
rayleigh opened this issue Jul 19, 2016 · 8 comments
Closed

Can't use Shinystan to look at rstanarm glmer results #128

rayleigh opened this issue Jul 19, 2016 · 8 comments

Comments

@rayleigh
Copy link

For a project, I used RStanarm's glmer function in the following way:

stan_fit <- stan_glmer(formula = formula(reg_formula), data = data_matrix,
family = "binomial", iter = 500, sample_file = output_filename)

However, when I tried to upload the files and look at the results in Shinystan, I got the following warnings and error messages:

> naes_one <- read_stan_csv(c("Annenberg_analysis_1_sample_output1", "Annenberg_analysis_1_sample_output2", "Annenberg_analysis_1_sample_output3", "Annenberg_analysis_1_sample_output4"))
There were 12 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: In if (adapt_term_lineno == len) adaptation_info <- "" else { ... :
the condition has length > 1 and only the first element will be used
2: In (adapt_term_lineno + 1):(time_lineno - 1) :
numerical expression has 2 elements: only the first used
3: In 1:(adapt_term_lineno - 1) :
numerical expression has 2 elements: only the first used
4: In if (adapt_term_lineno == len) adaptation_info <- "" else { ... :
the condition has length > 1 and only the first element will be used
5: In (adapt_term_lineno + 1):(time_lineno - 1) :
numerical expression has 2 elements: only the first used
6: In 1:(adapt_term_lineno - 1) :
numerical expression has 2 elements: only the first used
7: In if (adapt_term_lineno == len) adaptation_info <- "" else { ... :
the condition has length > 1 and only the first element will be used
8: In (adapt_term_lineno + 1):(time_lineno - 1) :
numerical expression has 2 elements: only the first used
9: In 1:(adapt_term_lineno - 1) :
numerical expression has 2 elements: only the first used
10: In if (adapt_term_lineno == len) adaptation_info <- "" else { ... :
the condition has length > 1 and only the first element will be used
11: In (adapt_term_lineno + 1):(time_lineno - 1) :
numerical expression has 2 elements: only the first used
12: In 1:(adapt_term_lineno - 1) :
numerical expression has 2 elements: only the first used
> launch_shinystan(naes_one)

Creating shinystan object...
Error in if (.used_vb(x) || !(algo %in% c("NUTS", "HMC"))) warning("Many features are only available for models fit using\n algorithm NUTS or algorithm HMC.", :
missing value where TRUE/FALSE needed

@rayleigh
Copy link
Author

I just tried looking at the Stanfit object in Shinystan right after getting glmer results. Shinystan launches fine in that case. So, is this an Rstanarm issue instead?

@jgabry
Copy link
Member

jgabry commented Jul 20, 2016

Thanks Rayleigh. I'm not sure yet what the problem is, but it might
be either an issue with shinystan + stanfit objects created from csv files
(this at least used to work pre-2.10).

Can you send me the csv files? Or trimmed csv files (if they're big). I
think I should be able to figure it out pretty quickly if I can reproduce
it exactly.

On Tuesday, July 19, 2016, rayleigh <notifications@github.com
javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:

I just tried looking at the Stanfit object in Shinystan right after
getting glmer results. Shinystan launches fine in that case. So, is this an
Rstanarm issue instead?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#128 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHb4Q1LEVA4wkENELJgjFEAf_A1KynECks5qXS2YgaJpZM4JQFSa
.

@rayleigh
Copy link
Author

One csv file is around 20 MB. What can I trim to make it smaller for you?

@jgabry
Copy link
Member

jgabry commented Jul 20, 2016

I probably only need a small subset of the posterior draws. So you could
discard everything after the first 50 iterations or something like that.

On Tuesday, July 19, 2016, notifications@github.com wrote:

One csv file is around 20 MB. What can I trim to make it smaller for you?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#128 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHb4Qz3mhTO9QN2befvfHXSFIV-sHrbPks5qXZCngaJpZM4JQFSa
.

@mkiang
Copy link

mkiang commented Jun 23, 2017

Was this ever resolved? I get the same error when trying to read in a sample file generated by RStan.

@martinmodrak
Copy link
Contributor

The problem persists as of Stan 2.17.0, the problem is when reading fits from CSV files. A minimal reproducible example:

stan_code <- "parameters { real a; } model { a ~ normal(0,1); }"
fit <- stan(model_code = stan_code, sample_file = "samples.csv", chain = 1, iter = 100)
fit2 <- read_stan_csv("samples.csv")

#launch_shinystan(fit) #Works OK
launch_shinystan(fit2)

Results in

Error in if (.used_vb(x) || !(algo %in% c("NUTS", "HMC"))) warning("Many features are only available for models fit using\n            algorithm NUTS or algorithm HMC.",  : 
  missing value where TRUE/FALSE needed

@martinmodrak
Copy link
Contributor

So I filed a pull request with a fix. In the long run it might be more reasonable to unify the CSV output of rstan::sampling and CmdStan to avoid those hacks.

jgabry added a commit that referenced this issue Mar 16, 2018
Extract correct info from fits reconstructed from CSV files. Refs #128
@jgabry
Copy link
Member

jgabry commented Apr 29, 2018

PR already merged and release is coming so I'm closing this one. Thanks @martinmodrak! I agree that in the long term unifying the output is desirable.

@jgabry jgabry closed this as completed Apr 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants