Large number of errors when attempting to run code and I'm not sure what to do.

775 views
Skip to first unread message

Daniel Berman

unread,
May 1, 2014, 11:38:34 PM5/1/14
to stan-...@googlegroups.com
Hi,

I previously asked about a few questions and I have some more. I'm having a lot of trouble running my code and I can't seem to get it to work. I'm not a great programmer so my code is probably very clunky and as a result, I very much appreciate the help. Here are the errors and warnings I'm getting:

TRANSLATING MODEL 'cpt_hierarchical_model_positive_and_negative24' FROM Stan CODE TO C++ CODE NOW.
DIAGNOSTIC(S) FROM PARSER:

Warning (non-fatal):     sampling statement (~) contains a transformed parameter or local variable.
     You must increment lp__ with the log absolute determinant of the Jacobian of the transform.
     Sampling Statement left-hand-side expression:
          get_base1(alpha_phi,j,"alpha_phi",1) ~ normal_log(...)
Warning (non-fatal):     sampling statement (~) contains a transformed parameter or local variable.
     You must increment lp__ with the log absolute determinant of the Jacobian of the transform.
     Sampling Statement left-hand-side expression:
          get_base1(beta_phi,j,"beta_phi",1) ~ normal_log(...)
Warning (non-fatal):     sampling statement (~) contains a transformed parameter or local variable.
     You must increment lp__ with the log absolute determinant of the Jacobian of the transform.
     Sampling Statement left-hand-side expression:
          get_base1(gamma_phi,j,"gamma_phi",1) ~ normal_log(...)
Warning (non-fatal):     sampling statement (~) contains a transformed parameter or local variable.
     You must increment lp__ with the log absolute determinant of the Jacobian of the transform.
     Sampling Statement left-hand-side expression:
          get_base1(delta_phi,j,"delta_phi",1) ~ normal_log(...)
Warning (non-fatal):     sampling statement (~) contains a transformed parameter or local variable.
     You must increment lp__ with the log absolute determinant of the Jacobian of the transform.
     Sampling Statement left-hand-side expression:
          get_base1(lluce,j,"lluce",1) ~ normal_log(...)
Warning (non-fatal):     sampling statement (~) contains a transformed parameter or local variable.
     You must increment lp__ with the log absolute determinant of the Jacobian of the transform.
     Sampling Statement left-hand-side expression:
          get_base1(llambda,j,"llambda",1) ~ normal_log(...)

COMPILING THE C++ CODE FOR MODEL 'cpt_hierarchical_model_positive_and_negative24' NOW.
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-31~1.0/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-31~1.0/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
C:/Users/daniel/Documents/R/win-library/3.1/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
C:/Users/daniel/Documents/R/win-library/3.1/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
SAMPLING FOR MODEL 'cpt_hierarchical_model_positive_and_negative24' NOW (CHAIN 1).
Error : Error during user-specified initialization:
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 1.#QNAN:0, but must be greater than 1
error occurred during calling the sampler; sampling not done

The parameters of interest are alpha, beta, delta, gamma, lambda, and luce. Alpha, beta, delta, and gamma range between 0 and 1.
Lambda is greater than 1.
Luce is greater than 0.
R_code_positive_and_negativeSTAN.R
cpt_hierarchical_model_positive_and_negative24.stan

Joshua Rosenau

unread,
May 1, 2014, 11:50:28 PM5/1/14
to stan-...@googlegroups.com
It looks like alpha_phi, beta_phi, gamma_phi, delta_phi, lluce, and llambda are parameters, not transformed parameters, so you should move them from one block to the other.

You should also declare the constraints on those parameters as real<lower=-3,upper=3>… rather than just as real…, and then I think you can drop the truncation on the sampling statements.

--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<R_code_positive_and_negativeSTAN.R><cpt_hierarchical_model_positive_and_negative24.stan>

Daniel Berman

unread,
May 2, 2014, 12:22:15 AM5/2/14
to stan-...@googlegroups.com
Thank you for responding so quickly. I really appreciate the help. After using <lower=-3, upper=3> and moving alpha_phi, beta_phi, gamma_phi, delta_phi, lluce, and llambda to parameters, the warnings go away, but I get the error:
Error : Error during user-specified initialization:
variable alpha_phi missing

Ben Goodrich

unread,
May 2, 2014, 12:37:01 AM5/2/14
to stan-...@googlegroups.com
On Friday, May 2, 2014 12:22:15 AM UTC-4, Daniel Berman wrote:
Thank you for responding so quickly. I really appreciate the help. After using <lower=-3, upper=3> and moving alpha_phi, beta_phi, gamma_phi, delta_phi, lluce, and llambda to parameters, the warnings go away, but I get the error:
Error : Error during user-specified initialization:
variable alpha_phi missing
error occurred during calling the sampler; sampling not done

This sounds as if you are passing starting values for some parameters but omitted a starting value for alpha_phi. So, you could specify that or just forget about specifying initial values entirely.

Ben

Daniel Berman

unread,
May 2, 2014, 8:22:09 AM5/2/14
to stan-...@googlegroups.com
Unfortunately declaring alpha_phi as an init doesn't solve the problem and results in the error:
Error : Error during user-specified initialization:
mismatch in number dimensions declared and found in context; processing stage=initialization; variable name=alpha_phi; dims declared=(1); dims found=()
error occurred during calling the sampler; sampling not done


Neither does getting rid of init in the stan() function does not solve the problem. Not doing so results in:
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 18.190631465656615:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 70.441623786153812:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 11.870938400030523:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 20.123034909111681:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.099534055478837757:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.1340370520610299:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 65.372619438870927:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 18.935693474648751:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 34.113577692150031:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 2.0366562432709512:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.90708351601342785:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 2.7214271622502322:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.99983326810675721:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 156.9524040288496:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 260.03799826199008:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 6.017343853903987:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 58.465570781943022:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.20264685592969389:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 172.88975303779986:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 3.009380828461699:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.3181014979988004:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 11.929800973338093:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.3107545006670462:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.46323309086172171:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.0075504084347444:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 6.6593189091030851:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.99377670021019693:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 84.219521004016556:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.86349541426664489:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 615.35771030180274:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 234.0545799526549:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.69822987916309831:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 34.665960419542984:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.9446750652240847:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.84548907760160996:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 38.44025065306959:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.44920762192078656:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.5342813450601862:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.59019573161231031:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.5764554718393695:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 11.052302261322211:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 44.743230332057557:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 271.1176731418912:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 15.488140380901001:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.40913055426684575:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.8458496438074248:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.0971278112162799:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.82799141630868522:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 13.438031372315555:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.5667073888410048:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 151.31745022947476:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 89.331730407780114:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 591.89486513262716:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.82638581798839406:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 100.65312385451678:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 6.5440097310612382:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.7516758305226086:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.20569993261722574:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.9180956170690353:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 371.30463189934881:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.565270112181655:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 2.1420809661266507:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 32.079834179785564:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 2.4259405869637294:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.76528322781173408:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 27.301920059285521:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.82135759789345486:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.1265535600872738:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.1902393709684658:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.092032546137831517:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 10.040099875759802:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 84.354009242532811:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.1113451065382356:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 10.303736110938992:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 246.12679279912808:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 2.5413140898020141:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 15.048584588549726:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 96.599561232250906:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 5.73097812200887:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 2.3080591949534734:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.055459810779217467:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 594.52524025947616:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.92976276202108599:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.0641324238457663:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.6223202010241977:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.7114185053771322:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.424366151213408:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 62.515390354901882:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.11052950541746687:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 14.117395243275464:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 10.445077171647528:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -1.8430256743450686:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 35.584002169029262:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 789.49277570338245:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 10.240001133527066:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.073321675092756777:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.31172275487713375:0, but must be > 0!Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.25277076742532012:0, but must be > 0!Rejecting proposed initial value with zero density.
Invalid value of luce: Error in function validate transformed params N4stan5agrad3varE: luce[k0__] is 575.99391023982514:0, but must be less than or equal to 2Rejecting proposed initial value with zero density.
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -0.35351141467782754:0, but must be > 0!Rejecting proposed initial value with zero density.
Initialization failed after 100 attempts.  Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
error occurred during calling the sampler; sampling not done

Ben Goodrich

unread,
May 2, 2014, 9:28:23 AM5/2/14
to stan-...@googlegroups.com
On Friday, May 2, 2014 8:22:09 AM UTC-4, Daniel Berman wrote:
Unfortunately declaring alpha_phi as an init doesn't solve the problem and results in the error:
Error : Error during user-specified initialization:
mismatch in number dimensions declared and found in context; processing stage=initialization; variable name=alpha_phi; dims declared=(1); dims found=()
error occurred during calling the sampler; sampling not done


By dims declared=(1); dims found=(), it is saying that it expected alpha_phi to be a vector of length number of subjects but got a scalar.
 
Neither does getting rid of init in the stan() function does not solve the problem. Not doing so results in:
Invalid value of lambda: Error in function validate transformed params N4stan5agrad3varE: lambda[k0__] is 18.190631465656615:0, but must be less than or equal to 10Rejecting proposed initial value with zero density.

All of these rejections are due to the fact that the constraints on the parameters and the constraints on the transformed parameters are not compatible. If lambda is a transformed parameter that must be <= 10, then whatever parameter(s) get transformed into lambda have to be constrained to make that happen. For example, if the parameter were lambda_squared, then it would need to be constrained to be <= 100.

Ben

Daniel Berman

unread,
May 2, 2014, 10:12:42 AM5/2/14
to stan-...@googlegroups.com
I'm unsure how to address the first error. I've tried making the initial value for alpha_phi=rep(c(0),numberofsubjects), but that doesn't help. I would prefer not to change alpha_phi to a scalar because I hope to be able to run multiple data sets at the same time, meaning I would need multiple alpha_phis.

Ben Goodrich

unread,
May 2, 2014, 12:36:02 PM5/2/14
to stan-...@googlegroups.com
On Friday, May 2, 2014 10:12:42 AM UTC-4, Daniel Berman wrote:
I'm unsure how to address the first error. I've tried making the initial value for alpha_phi=rep(c(0),numberofsubjects), but that doesn't help. I would prefer not to change alpha_phi to a scalar because I hope to be able to run multiple data sets at the same time, meaning I would need multiple alpha_phis.

Possibly it needs to be a one-column matrix?

alpha_phi = matrix(0, numberofsubjects, 1)

But the second problem with the model needs to be fixed regardless. It suggests the stated constraints are incoherent.
 
Ben

Daniel Berman

unread,
May 5, 2014, 7:38:22 PM5/5/14
to stan-...@googlegroups.com
Unfortunately that still didn't work:
mismatch in number dimensions declared and found in context; processing stage=initialization; variable name=alpha_phi; dims declared=(1); dims found=(1,1)
error occurred during calling the sampler; sampling not done

I also tried using
alpha_phi=vector(length=numberofsubjects,mode='numeric')

and got the error:
mismatch in number dimensions declared and found in context; processing stage=initialization; variable name=alpha_phi; dims declared=(1); dims found=()
error occurred during calling the sampler; sampling not done

What do you mean about the constraints being incoherent?

Ben Goodrich

unread,
May 5, 2014, 7:46:49 PM5/5/14
to stan-...@googlegroups.com
Can you post your most recent code? By incoherent constraints, I mean some constraint on the sample space of one or more of the parameters that does not guarantee that the constraints on the transformed parameter will be satisfied.

Ben

Daniel Berman

unread,
May 5, 2014, 9:48:12 PM5/5/14
to stan-...@googlegroups.com
Thank you for being so quick to respond and so helpful. I really appreciate it. Here is the most recent version of the code
cpt_hierarchical_model_positive_and_negative24.stan
R_code_positive_and_negativeSTAN.R

Ben Goodrich

unread,
May 5, 2014, 10:11:42 PM5/5/14
to stan-...@googlegroups.com
In parameters, you have

real<lower=-.7> lluce[numberofsubjects];
real
<lower=0> llambda[numberofsubjects];

while in transformed parameters, you have

real <lower=1, upper=10> lambda[numberofsubjects];
real
<lower=0, upper=2>  luce[numberofsubjects];

luce
[j]   <- exp(lluce[j]);
lambda[j] <- exp(llambda[j]);

How can luce[j] be guaranteed to be less than 2 if there is no upper bound on lluce[j] and how can lambda[j] be less than 10 if there is no upper bound on llambda[j]? That is what I mean by incoherent constraints. If you reconcile those, then you probably won't have to worry about getting the dimensions of the starting values right.

Ben

Daniel Berman

unread,
May 5, 2014, 11:00:46 PM5/5/14
to stan-...@googlegroups.com
Even fixing that didn't stop the errors:
Error : Error during user-specified initialization:
mismatch in number dimensions declared and found in context; processing stage=initialization; variable name=alpha_phi; dims declared=(1); dims found=(1,1)
cpt_hierarchical_model_positive_and_negative24.stan

Daniel Lee

unread,
May 5, 2014, 11:06:53 PM5/5/14
to stan-...@googlegroups.com
Hi Daniel,

Can you double-check the definition of alpha_phi and make sure it's a vector, not a matrix in your initialization file?


Daniel



Daniel Berman

unread,
May 6, 2014, 12:23:36 AM5/6/14
to stan-...@googlegroups.com
When they are both matricies, i get:
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'cpt_hierarchical_model_positive_and_negative24' with error message:
EXPECTATION FAILURE LOCATION: file=input; line=30, column=46

	matrix<lower=-3,upper=3>[numberofsubjects] alpha_phi;
                                             ^-- here


DIAGNOSTIC(S) FROM PARSER:
Parser expecting: ","

when it's a vectors digit:
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'cpt_hierarchical_model_positive_and_negative24' with error message:
EXPECTATION FAILURE LOCATION: file=input; line=30, column=31

	vector <lower=-3,upper=3> alpha_phi[numberofsubjects];
                              ^-- here


DIAGNOSTIC(S) FROM PARSER:
Parser expecting: "["

Ben Goodrich

unread,
May 6, 2014, 12:33:53 AM5/6/14
to stan-...@googlegroups.com
On Tuesday, May 6, 2014 12:23:36 AM UTC-4, Daniel Berman wrote:
When they are both matricies, i get:
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'cpt_hierarchical_model_positive_and_negative24' with error message:
EXPECTATION FAILURE LOCATION: file=input; line=30, column=46

	matrix<lower=-3,upper=3>[numberofsubjects] alpha_phi;
                                             ^-- here

A matrix needs two dimensions, like matrix<lower=-3,upper=3>[numberofsubjects,2]; or whatever. My guess is that you could just make it a vector.
 
DIAGNOSTIC(S) FROM PARSER:
Parser expecting: ","

when it's a vectors digit:
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'cpt_hierarchical_model_positive_and_negative24' with error message:
EXPECTATION FAILURE LOCATION: file=input; line=30, column=31

	vector <lower=-3,upper=3> alpha_phi[numberofsubjects];
                              ^-- here

In this form, it would be vector<lower=-3,upper=3>[numberofsubjects] alpha_phi;

In any event, once you do that, you can just omit the inits argument to stan(), and it should initialize fine.

Ben

Daniel Lee

unread,
May 6, 2014, 12:35:17 AM5/6/14
to stan-...@googlegroups.com
Hi Daniel,

I think there's confusion between Stan's types and the R dump format's types. And these seem like different messages than what you've had before.

Some insight into the error messages below:

On Tue, May 6, 2014 at 12:23 AM, Daniel Berman <daniel....@gmail.com> wrote:
When they are both matricies, i get:
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'cpt_hierarchical_model_positive_and_negative24' with error message:
EXPECTATION FAILURE LOCATION: file=input; line=30, column=46

	matrix<lower=-3,upper=3>[numberofsubjects] alpha_phi;
                                             ^-- here


DIAGNOSTIC(S) FROM PARSER:
Parser expecting: ","

The above error message is telling you that the Stan model is not valid, thus it's not compiling. It's not compiling because the definition of matrix is expecting the number of rows and the number of columns within the square brackets. It should look something like:
   matrix[M, N] x;


when it's a vectors digit:
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'cpt_hierarchical_model_positive_and_negative24' with error message:
EXPECTATION FAILURE LOCATION: file=input; line=30, column=31

	vector <lower=-3,upper=3> alpha_phi[numberofsubjects];
                              ^-- here


DIAGNOSTIC(S) FROM PARSER:
Parser expecting: "["


This error message is also telling you that the Stan model isn't valid. The compiler is expecting square brackets with the declaration of the vector, not after the variable, which is creating an array. So it should look like:
  vector[N] x;


For more information, Bob has written a comprehensive section in the Stan manual called "Containers: Arrays, Vectors, and Matrices."


I believe a few messages ago, you got past this and were having issues with initial values, but it looks like you've changed your Stan model. My suggestion is to first create a working Stan model and see if it'll fit without initialization.

I'll stop here because it looks like Ben just responded and may provide more insightful information.


Daniel

Daniel Berman

unread,
May 8, 2014, 11:00:30 PM5/8/14
to stan-...@googlegroups.com
I think I have everything working. I found a few errors, like it not handling -0, so I had to use abs(). Is there a way I can get only a few parameters. I tried using the (variable name)@(parameter), but that didn't work. Is there a way to just pull the information from it?

Bob Carpenter

unread,
May 9, 2014, 12:15:24 PM5/9/14
to stan-...@googlegroups.com
There's no way
On May 9, 2014, at 5:00 AM, Daniel Berman <daniel....@gmail.com> wrote:

> I think I have everything working. I found a few errors, like it not handling -0,

Do you have an example of a problem with -0?

> so I had to use abs(). Is there a way I can get only a few parameters.

You mean in the results? There's no way to save only a few, but there's
a way to extract only a few in RStan --- you just provide a second argument
to extract.

> I tried using the (variable name)@(parameter), but that didn't work. Is there a way to just pull the information from it?

What information? You can just pull the samples.

- Bob

Daniel Berman

unread,
May 9, 2014, 12:56:16 PM5/9/14
to stan-...@googlegroups.com
My data sets contain data points with negatives and zeros. Originally, I turned those into positives by multiplying them by -1, so I could put them to some power. I noticed that I was having some errors, so I printed out what was happening. I noticed that -0=-0, rather than 0 and (-0)^a resulted in an error.

When running R2Winbugs, you would run fit1=bugs(...), where fit1 is a list. After that you could use the command fit1$summary would return a matrix. When you use View(fit1$summary), the first row is row.names and contains the names of the parameters estimated. After that, the columns are titled with measures of the parameters such as mean, standard deviation, 2.5%, 25%, etc. This was easy to manipulate. Say I wanted the mean and standard deviation of the very first parameter, I would simply type fit1$summary[1,1:2] and it would return those as class numeric:

      mean         sd 
0.69656000 0.09513074 

Is there a way to do that?

Christian Roy

unread,
May 9, 2014, 1:13:06 PM5/9/14
to stan-...@googlegroups.com
If you are using rstan you can use extract() to extract samples from a model 

model1 <- stan(file="my_model.stan",  init =my.inits(), pars =my.params, data=my.data,  warmup = 200, iter= 2000, chains = 4)
output1 <- extract(model1, permuted = TRUE)   

output1 will be an array and you can access the parameters by calling them by their name

output1$mean

or

output1$sd

the function print() will return you a table containing  a resume of the model

print(model1)

or if you want only to check one parameter:

print(model1, pars="mean", probs=c(0.5, 0.025, 0.975), digits=3)

Hope that help

Chris
-------------
Reply all
Reply to author
Forward
0 new messages