Require real scalar return type for probability function

I am probably making a really silly mistake but whenever I try to write a user-defined probability function I get the following sort of response:

``````functions{
real dummy_lpdf(real x ){
return 0.1;
}
}
data{
real l;
}

parameters{
real<lower=0, upper=10> x;
}
model{

l ~ dummy(x);
}
``````

With the following error message:

``````
No matches for:

real ~ dummy(real)

Available argument signatures for dummy:

real ~ dummy()

require real scalar return type for probability function.
error in 'model_test' at line 15, column 16
-------------------------------------------------
13: model{
14:
15:   l ~ dummy(x);
^
-------------------------------------------------
``````
``````l ~ dummy(x);
``````

is like calling

``````target += dummy(l | x)
``````

so you would need a signature for

``````real ~ dummy(real)
``````

which is lacking since you only defined a 1-arg function, so instead define

``````functions{
real dummy_lpdf(real x, real y ){
return 0.1;
}
}
``````

which is sort of silly but it would squash the error (maybe would give warnings about unused variablesâ€¦ or tell us what you really want to do because this makes no sense :)

1 Like

Krzysztof
Jeremy

This is the second time this has come up in as many days. The point is clearer with a reimplementation of a normal-like signature:

``````real foo_lpdf(real y, real mu, real sigma);
``````

which would support:

``````y ~ foo(mu, sigma);
``````

Thatâ€™s because the sampling notation is just shorthand for

``````target += foo_lpdf(y | mu, sigma);
``````

When I started this topic I said that I had probably been making a silly mistake, and Krzysztofâ€™s quick and helpful reply proved that. So I was glad to read from Bob that I am not alone in doing so. I think that I was misled by the notation

``````y~foo(mu,sigma)
``````

because, when one is in a hurry and perhaps not thinking as clearly as one should, that notation makes it appear that the arguments of

``````foo_lpdf
``````

are just

``````mu, sigma
``````

The responses to this topic have prompted thought-processes leading me to an entirely different approach to solving my particular problem, so I am very grateful for the help.
Jeremy

[editâ€”those backticks need to be on their own lineâ€”you shoudl be able to see the output in the preview box if you do this online]