Max and min function in Stan

2,122 views
Skip to first unread message

Kazem

unread,
Sep 6, 2013, 12:29:56 PM9/6/13
to stan-...@googlegroups.com

Dear all, 
How maximum and minimum functions work in rstan?
I am trying to fit a mixed model in rstan, which in the mean of the function I am going to use maximum of  two values. In rjags and bugs you can use "max", but in rstan? 
Here is my model:
Mu[i]<-b[id[i],1]+beta[1]+beta[2]*Age[i]+beta[3]*Season[i]+Drop*max(dif[i],0) ; 
                                                                                             ^-- here


DIAGNOSTIC(S) FROM PARSER:
no matches for function name="max"

Thanks,
Kazem Nasserinejad

Ben Goodrich

unread,
Sep 6, 2013, 4:21:34 PM9/6/13
to stan-...@googlegroups.com
In Stan v1.3.0, I think you need to use the "floating-point" variants, fmax() and fmin().

Ben

Bob Carpenter

unread,
Sep 6, 2013, 8:47:47 PM9/6/13
to stan-...@googlegroups.com
fmin and fmax if the inputs are continuous ("f" is
for floating point). The reason we follow the C++
convention is to make it clear what the result type is:

int max(int,int)
int min(int,int)

real fmax(real,real)
real fmin(real,real)

Because int gets promoted to real, you can use fmax
and fmin with real or int inputs, but the outputs
are always real.

- Bob
> --
> 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/groups/opt_out.

Kazem

unread,
Sep 8, 2013, 8:29:36 AM9/8/13
to stan-...@googlegroups.com
Thanks,
Kazem
Reply all
Reply to author
Forward
0 new messages