I want to fit the following model.
y = e^(b0 + (b1 * X))
Using python and curve_fit from scipy, I get this result wich is correct.
import numpy as np
from scipy.optimize import curve_fit
x = np.array([1,2])
y = np.array([6,7])
def f(t,b0,b1):
return np.exp(b0 + (b1 * t))
p, cov = curve_fit(f, x, y)
#parameters
print(p)
I tried to implement this with pystan, but the values that I get are very different from the solution found with scipy.
(beta must be equal to something like -0.00180411)
model_code = """
data {
int<lower=0> N;
vector[N] y;
vector[N] x;
}
parameters {
real beta0;
real beta1;
real<lower=0> sigma;
}
transformed parameters {
real m;
real b0;
real b1;
b0 = exp(beta0);
b1 = exp(beta1);
for (i in 1:N)
m = b0+ (b1 * x[i]);
}
model {
// priors
beta0 ~ normal(0,10);
beta1 ~ normal(0, 10);
sigma ~ cauchy(0,5);
// likelihood
for (n in 1:N)
y[n] ~ normal(m, sigma);
}
"""
dat = {'N': 2,
'y': y,
'x': x }
sm = pystan.StanModel(model_code=model_code)
fit = sm.sampling(data=dat, iter=50000, chains=1)
fit
How can I obtain the solution of scipy with stan ?
Thank you.