I’m interested in using the rstanarm::product_normal()prior, but it error.
What am I doing wrong here?
library(rstanarm)
m <- stan_glm(mpg ~ am,
data = mtcars,
prior = product_normal(2, 0, 1),
family = gaussian())
#> Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) :
#> Exception: mismatch in number dimensions declared and found in context; processing stage=data initialization; variable name=num_normals; dims declared=(1); dims found=() (in '/data/hyperparameters.stan' at line 18; included from 'model_continuous' at line 56)
#> failed to create the sampler; sampling not done
#> Error in check_stanfit(stanfit) :
#> Invalid stanfit object produced please report bug
Sorry for taking so long for an answer to pop up! I think that the problem is the 2 in your call to product_normal()? According to the documentation,
Each element of df must be an integer of at least 2 because these “degrees of freedom” are interpreted as the number of normal variates being multiplied and then shifted by location to yield the regression coefficient. Higher degrees of freedom produce a sharper spike at location .
Does the above imply that you should provide a vector, i.e., degfree <- c(2,2) or something like that?
library(rstanarm)
m <- stan_glm(mpg ~ am,
data = mtcars,
prior = product_normal(c(3,3), 0, 1),
family = gaussian())
#> Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) :
#> Exception: mismatch in dimension declared and found in context; processing stage=data initialization; variable name=prior_df; position=0; dims declared=(1); dims found=(2) (in '/data/hyperparameters.stan' at line 10; included from 'model_continuous' at line 56)
#> failed to create the sampler; sampling not done
#> Error in check_stanfit(stanfit) :
#> Invalid stanfit object produced please report bug
It seems like all options give some error (slightly different Exceptions…):
library(rstanarm)
m <- stan_glm(mpg ~ am,
data = mtcars,
prior = product_normal(c(3,3), 0, c(1,1)),
family = gaussian())
#> Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) :
#> Exception: mismatch in dimension declared and found in context; processing stage=data initialization; variable name=prior_scale; position=0; dims declared=(1); dims found=(2) (in '/data/hyperparameters.stan' at line 2; included from 'model_continuous' at line 56)
#> failed to create the sampler; sampling not done
#> Error in check_stanfit(stanfit) :
#> Invalid stanfit object produced please report bug
m <- stan_glm(mpg ~ am,
data = mtcars,
prior = product_normal(c(3,3), c(0,0), c(1,1)),
family = gaussian())
#> Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) :
#> Exception: mismatch in dimension declared and found in context; processing stage=data initialization; variable name=prior_scale; position=0; dims declared=(1); dims found=(2) (in '/data/hyperparameters.stan' at line 2; included from 'model_continuous' at line 56)
#> failed to create the sampler; sampling not done
#> Error in check_stanfit(stanfit) :
#> Invalid stanfit object produced please report bug
etc…
But these, I think, are due to the fact that there is only one fixed effect, so can’t have a vector of df, location, scale (mismatch in dimension declared and found - expecting 1, found 2).
The original error is because the length of num_normals should be 1, but is 0. But I have no idea what num_normals is…