How to use the cumulative sum function in Rstan

Hi All,
I’m trying to implement a function which uses the cumulative sum function in stan but I’m running into issues with the basic functionality.
To test the function initially Ive created a simple wrapper using expose stan functions in R.

model_code<-'
functions{
real test_cumulative_sum(vector phi, int nseasons){
real cumulative_sum[nseasons];
cumulative_sum = cumulative_sum(phi);
return cumulative_sum 
}


}
'
expose_stan_functions(stanc(model_code = model_code))

But I keep getting a compilation error.
Any tips on what I am doing wrong here?

Also I checked if it was the variable name and still have the same issue.
See below.
‘’’
model_code<-’
functions{
real test_cumulative_sum(vector phi, int nseasons){
real cumulative_sum[nseasons];
cumulative_sum = cumulative_sum(phi);
return cumulative_sum
}

}

expose_stan_functions(stanc(model_code = model_code))
‘’’

the return line is missing a semicolon.

1 Like

Omg thanks! Haha

2 Likes