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

Error when both n.chain and start.val are given if n.chain>1 #2

Open
hdarjus opened this issue Mar 3, 2023 · 5 comments
Open

Error when both n.chain and start.val are given if n.chain>1 #2

hdarjus opened this issue Mar 3, 2023 · 5 comments

Comments

@hdarjus
Copy link

hdarjus commented Mar 3, 2023

Hi @ArdiaD,

thanks for the package. For improved MCMC diagnostics for my case study, I wanted to run multiple chains and also provide starting values. I got into an error that I was able to overcome only by reading the source code of the package.

MWE:

model_control <- list(n.chain = 2,
                      start.val = matrix(c(0.01, 0.1, 0.7, 500,
                                           0.3, 3, 0.01, 500),
                                         2, 4, byrow = TRUE))
fit <- bayesGARCH(rep(0, 10), control = model_control)

The following error is thrown before sampling starts:

Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent

The problem is in this line:

else con$start.val <- matrix(rep(con$start.val, con$n.chain),

It is true that providing n.chain is redundant if start.val is given but I personally found the behavior counterintuitive (I think in JAGS and Stan you have to provide both) and the solution should be simple.
I hope you find this ticket useful.

Cheers,
Darjus

@ArdiaD
Copy link
Owner

ArdiaD commented Mar 3, 2023

Hi @hdarjus cannot you simple make a loop around the fit and collect the results?

@hdarjus
Copy link
Author

hdarjus commented Mar 4, 2023

Yes, that's one potential workaround. However, that doesn't solve the issue that I provided consistent control input (since n.chain is equal to NROW(start.val)) to bayesGARCH and received an error.

A package-wide solution could be to add something like

else if (NROW(con$start.val) > 1) {if (NROW(con$start.val) != con$n.chain) stop("Arguments 'n.chain' and 'start.val' inconsistent; please double-check your input.")}

to the above linked line before the else.

@ArdiaD
Copy link
Owner

ArdiaD commented Mar 4, 2023

Simply put n.chain = 1. I won't change the package for this design feature. But thx for your proposal

@ArdiaD ArdiaD closed this as completed Mar 4, 2023
@ArdiaD ArdiaD reopened this Mar 4, 2023
@ArdiaD
Copy link
Owner

ArdiaD commented Mar 4, 2023

Oh, sorry @hdarjus, I missunderstood your idea. Yes, will make the fix for the next release. Thx for pointing this to me !

@hdarjus
Copy link
Author

hdarjus commented Mar 4, 2023

I am glad it works out!

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

2 participants