Transformed data error

Hello:

in the data block there is:
real x[N];

in the transformed data block there is:
real xx[N];
xx=x^x;

and the stan file returns error:

arguments to ^ must be primitive real or but cannot exponentiate real by int in transformed parameter block

can you advise why xx=x^x fails and how to fix?

TY

Did you try to use pow(x,x)?

1 Like

x^x fails because ^ is not defined for two arrays in Stan. However, the elementwise equivalent .^ is defined and should do what you want. Same for pow as @danielparthier suggests.

As an aside, @WardBrian do you think the doc for elementwise operators needs updating to clarify how they operate on arrays, or is there no need to be repetitive with the overview of vectorized functions (see sec. 3.1.1.1)?

2 Likes