metrumresearchgroup / example-models

Moved from Charles' own github - July 31, 2017
10 stars 4 forks source link

piecewise-linear-interpolation-function #4

Closed billgillespie closed 6 years ago

billgillespie commented 7 years ago

Summary:

Torsten feature: Provide a Stan language function for piecewise linear interpolation.

Description:

Return the values of a piecewise linear function at specified values of the first function argument. The function is specified in terms of a set of x y pairs. The x values must be in increasing order. All 3 arguments may be data or parameters.

The following is a simple toy Stan model that illustrates use of the proposed function.

data{ int nObs; real xObs[nObs]; real yObs[nObs]; int nx; real x[nx]; }

parameters{ real y[nx]; real sigma; }

transformed parameters{ real yHat[nObs]; yHat = linear_interpolation(xObs, x, y); }

model{ y ~ normal(0, 25); yObs ~ normal(yHat, sigma); }

billgillespie commented 6 years ago

linear_interpolation function has been merged with the develop branch