Fit data to a curve with stan

Dear all,
I’m here since I’m still new to stan and still need to familiarize with this powerful tool.
My purpose is to simply fit a light curve (curve specifying the brightness of an object during a certain time) of a star during a microlensing phenomenon (put simply, we should notice an unusual increase in brightness following a specific curve).

In my possession as data elements for stan I have: n measurements of brightness (mags_obs), the error on every measure of brightness (sigma), and the time elapsed (time).

The model I’m using is that every measurement mags_obs[i] should be distributed as N(\mu, \sigma [i]),
where \mu is the theoric value of brightness under the phenomenon of microlensing and \sigma [i] is the error on the measure of mags_obs[i]. The likelihood will thus have the form:

p(\{y_i\} | h) = \prod p( y_i | h) = \prod \frac{e^{\frac{(y_i - h(t))^2}{2\sigma^2}}}{Z}

The theoric value of \mu = \mu(t) is specified via the correct values of the 5 parameters of the model, namely:
h = h(t_0, \, t_e, \, u_0, \, Ibl, f), which are specific to the object causing the microlensing. The relation is shown below inside the function block of the stan file:

functions {
real mag (data real t, real u0, real t0, real te, real Ibl, real f) {
real u_t = sqrt(u0^2 + ((t-t0)/te)^2);
real mu_t = (u_t^2 + 2)/(u_t*sqrt(u_t^2 + 4));
real Ltot = 10^(-Ibl/2.5); //total luminosity
real L1 = (1 - f)*Ltot; //lens luminosity
real L0 = f*Ltot; //stars luminosity
real L_t = L0*mu_t + L1;

real m = -2.5*log10(L_t);

return m;
}
}

data {
int<lower=1> n;
real mags_obs[n];
real t[n];
real sigma[n];

}

parameters {
real t0;
real te;
real u0;
real Ibl;
real f;
}

model {
real mu;

t0 ~ uniform(2450000,2470000);   //priors
te  ~ uniform(20, 30);
u0 ~ uniform(0, 1);
Ibl ~ uniform(10,20);
f ~ uniform(0, 1);

for (i in 1:n) {
mu = mag(t[i], u0, t0, te, Ibl, f);
mags_obs[i] ~ normal(mu, sigma[i]);   //liklelihood
}
}


So the problem is that I constatly get warining messages like:

1: There were 2475 divergent transitions after warmup. See
http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
2: There were 1 chains where the estimated Bayesian Fraction of Missing Information was low. See
http://mc-stan.org/misc/warnings.html#bfmi-low
3: Examine the pairs() plot to diagnose sampling problems


with unreliable means and incorrect predictions of the parameters. For example, these are the diagnostic plot of three of the sought parameters, with iter = 5000 , good starting values and all other options are left by default.

I tried also with a high iteration number and with different adapt_value, but I got the same unsatisfying results nevertheless.

Is there something wrong with my implementation? This is a known phenomenon on which I’ve already worked before, so I’m trying to translate in stan to see the increase in performance.
For clarity I’ll show here an example of a fitted light curve over a set of observations of brightness magnitude:

Anyone have a clue on why it behaves like this? Thank you!!

At first glance, it looks like you want you parameters to be constrained to the support of the priors?

Then you will have to specify lower and upper bounds as described here: 5.3 Univariate data types and variable declarations | Stan Reference Manual

However, I would assume that you might have to replace the uniform priors, but I might be mistaken.

1 Like

There’s no need to replace the uniform priors, but they could safely be omitted once the parameters are declared with appropriate constraints–they won’t contribute anything to the likelihood. The Jacobian of the constraining transform is handled automatically when parameters are declared with constraints.

1 Like

Yes @jsocolar , this is an important piece of information for @Astrolabio, but I just meant that I would be surprised if the model would just works with those uniform priors.

2 Likes

Oh, got it! Sorry for the mix-up! And yeah, I agree.

1 Like

It’s good that you clarified this, my response was a bit brief!

Though I wish the documentation were more explicit about all the implications.

I don’t understand what is sigma[i] in the code and why it is different for each point

Hello, It means that every measurement comes with a quantifiable error.

Hello thanks for the replies. I will attach here the code of my past fit made with python, which follows the same model with the same priors. Here the result is correct, it has been used the python library emcee which is a viarant of a Markov Chain sampler.
Microlensing.pdf (509.6 KB)

Would you be able to provide a snippet of the data or some simulated data?

Sure, the file has three columns specifying “time” (T), “brightness observed” (mag) and “error on the measurement of brightness” (sigma_m), such as:

T             mag      sigma_m
2457424.87095 15.72500 0.00400
2457425.86647 15.72300 0.00500
2457427.85967 15.70800 0.00500
2457428.86007 15.71500 0.00400
2457429.85229 15.71300 0.00500
2457431.85199 15.72500 0.00400
2457432.86063 15.72800 0.00500
2457433.85854 15.70200 0.00500
2457434.84802 15.71800 0.00500
2457435.86417 15.71900 0.00600
2457435.88866 15.71900 0.00500
2457436.85964 15.72500 0.00500
2457436.88380 15.72500 0.00500
2457437.84049 15.71400 0.00400
2457437.88953 15.71700 0.00400
2457438.85430 15.70800 0.00500
2457438.88470 15.69400 0.00500
2457439.84874 15.71300 0.00500
2457439.88737 15.71600 0.00400
2457440.84662 15.72100 0.00500
2457440.88530 15.72300 0.00400
2457441.84908 15.71800 0.00400
2457441.88715 15.73800 0.00400
2457442.84306 15.71000 0.00500
2457442.88580 15.71500 0.00500
2457443.85008 15.71300 0.00500
2457444.82763 15.71700 0.00500
2457444.87660 15.70500 0.00400
2457445.82880 15.71500 0.00500
2457445.86350 15.70900 0.00400
2457446.81642 15.72700 0.00400
2457446.84573 15.73400 0.00400
2457446.88563 15.74400 0.00400
2457447.81654 15.70600 0.00400
2457447.85693 15.73200 0.00400
2457447.89512 15.72400 0.00400
2457448.83400 15.71700 0.00400
2457448.87860 15.72900 0.00400
2457449.87936 15.72500 0.00600
2457451.81746 15.73000 0.00400
2457451.83852 15.72600 0.00600
2457451.88551 15.71700 0.00500
2457452.81274 15.72700 0.00400
2457452.85774 15.73300 0.00400
2457452.90402 15.73800 0.00400
2457453.82475 15.71800 0.00300
2457453.87866 15.73500 0.00300
2457454.85030 15.71800 0.00400
2457454.87043 15.70800 0.00400
2457455.78897 15.72400 0.00600
2457455.84386 15.72400 0.00400
2457455.89762 15.70900 0.00400
2457456.80475 15.73400 0.00500
2457456.85284 15.72100 0.00400
2457456.90724 15.72100 0.00400
2457457.81821 15.72800 0.00500
2457457.87433 15.72400 0.00400
2457458.78359 15.71900 0.00500
2457458.82840 15.71100 0.00400
2457458.88304 15.72000 0.00400
2457460.79513 15.71500 0.00500
2457460.85298 15.72100 0.00400
2457460.89814 15.72800 0.00400
2457461.81017 15.71600 0.00400
2457461.86434 15.72300 0.00400
2457462.76634 15.71800 0.00500
2457462.81187 15.71700 0.00400
2457462.87078 15.73800 0.00400
2457463.80080 15.71100 0.00400
2457463.87059 15.72200 0.00400
2457464.81880 15.71100 0.00400
2457465.76607 15.72300 0.00500
2457465.81078 15.71200 0.00400
2457465.86434 15.71800 0.00400
2457465.91019 15.72000 0.00400
2457466.88643 15.72600 0.00400
2457467.79968 15.71800 0.00500
2457467.84582 15.73200 0.00400
2457467.89063 15.73000 0.00400
2457470.76970 15.70400 0.00600
2457470.81662 15.71800 0.00500
2457470.86112 15.71000 0.00400
2457470.91424 15.71900 0.00500
2457471.78287 15.71800 0.00500
2457471.82710 15.69600 0.00500
2457471.88439 15.72200 0.00400
2457472.74799 15.72000 0.00600
2457472.79256 15.72300 0.00500
2457472.83787 15.71200 0.00500
2457472.89377 15.70600 0.00400
2457473.77351 15.71500 0.00500
2457474.74202 15.70200 0.00600
2457474.78200 15.72400 0.00500
2457474.82109 15.70800 0.00500
2457474.85967 15.72300 0.00400
2457474.89834 15.73200 0.00400
2457475.76043 15.71700 0.00600
2457475.80126 15.71300 0.00600
2457475.84127 15.70900 0.00500
2457475.88024 15.71500 0.00400
2457475.91851 15.72400 0.00500
2457476.76217 15.73000 0.00600
2457476.84057 15.70500 0.00400
2457479.81167 15.74100 0.00500
2457479.82564 15.72700 0.00500
2457479.83956 15.73000 0.00500
2457480.77598 15.70600 0.00500
2457480.80569 15.71400 0.00600
2457480.83080 15.71000 0.00500
2457480.85213 15.72600 0.00600
2457480.87230 15.73800 0.00500
2457480.88634 15.72600 0.00500
2457480.90163 15.74200 0.00400
2457480.91646 15.73000 0.00500
2457484.72317 15.71400 0.00500
2457484.73888 15.71100 0.00500
2457484.75284 15.71700 0.00500
2457484.76674 15.72200 0.00400
2457484.78069 15.71200 0.00500
2457484.80024 15.73800 0.00500
2457484.81423 15.72700 0.00400
2457484.82824 15.72800 0.00500
2457484.84224 15.72200 0.00400
2457484.85632 15.73900 0.00400
2457484.88043 15.72500 0.00500
2457484.89468 15.71300 0.00400
2457484.91083 15.71900 0.00400
2457484.92499 15.72200 0.00500
2457485.72502 15.69100 0.00600
2457485.74477 15.71500 0.00500
2457485.75875 15.71700 0.00500
2457485.77279 15.71200 0.00400
2457485.78680 15.72800 0.00400
2457485.80072 15.71800 0.00400
2457485.81471 15.71800 0.00400
2457485.83532 15.73400 0.00400
2457485.84944 15.71700 0.00400
2457485.86368 15.72500 0.00400
2457485.87839 15.72500 0.00400
2457485.89351 15.73600 0.00400
2457485.90779 15.73200 0.00400
2457485.92226 15.72400 0.00400
2457486.71706 15.71400 0.00500
2457486.73725 15.70000 0.00500
2457486.75117 15.71600 0.00500
2457486.76516 15.71900 0.00500
2457486.77922 15.72200 0.00500
2457486.79312 15.71400 0.00500
2457486.80709 15.71500 0.00500
2457486.82147 15.73400 0.00500
2457486.83547 15.72100 0.00400
2457486.84975 15.72900 0.00400
2457486.87404 15.71400 0.00500
2457486.88834 15.72400 0.00500
2457486.90465 15.71600 0.00500
2457486.91926 15.71800 0.00500
2457487.71396 15.72100 0.00500
2457487.72814 15.74000 0.00500
2457487.74219 15.72100 0.00500
2457487.75887 15.71100 0.00500
2457487.77291 15.71500 0.00400
2457487.78908 15.71300 0.00400
2457487.80437 15.72000 0.00400
2457487.81839 15.71300 0.00500
2457487.84467 15.71600 0.00400
2457487.85894 15.72200 0.00400
2457487.87312 15.71800 0.00400
2457487.88755 15.71600 0.00400
2457487.90312 15.71700 0.00400
2457487.91716 15.72800 0.00400
2457488.71357 15.72800 0.00400
2457488.72759 15.73000 0.00500
2457488.74221 15.72500 0.00500
2457488.75629 15.73100 0.00400
2457488.77071 15.73300 0.00400
2457488.78529 15.72200 0.00400
2457488.81194 15.73300 0.00400
2457488.83551 15.70900 0.00400
2457488.84989 15.71900 0.00400
2457488.86504 15.72800 0.00400
2457488.87980 15.72300 0.00400
2457488.89516 15.71400 0.00400
2457488.90972 15.71400 0.00400
2457488.92378 15.71800 0.00400
2457489.76923 15.72100 0.00400
2457489.79216 15.72800 0.00400
2457489.81334 15.73100 0.00400
2457489.83259 15.72600 0.00400
2457489.86171 15.71800 0.00400
2457489.90458 15.71500 0.00400
2457489.91789 15.71900 0.00400
2457489.93215 15.70200 0.00500
2457491.69825 15.71100 0.00500
2457491.71219 15.72100 0.00500
2457491.72616 15.72800 0.00500
2457491.74005 15.71500 0.00500
2457491.75432 15.71100 0.00500
2457491.76858 15.71000 0.00400
2457491.78270 15.70600 0.00400
2457491.79699 15.71200 0.00400
2457491.82075 15.73200 0.00400
2457491.83487 15.72000 0.00400
2457491.85912 15.70900 0.00400
2457491.87342 15.73200 0.00400
2457491.88847 15.73100 0.00400
2457491.90365 15.73300 0.00400
2457491.91782 15.72400 0.00400
2457492.69274 15.72800 0.00500
2457492.70883 15.71300 0.00500
2457492.72532 15.71400 0.00400
2457492.74572 15.71800 0.00400
2457492.76962 15.71000 0.00400
2457492.78542 15.71200 0.00400
2457492.80130 15.72100 0.00400
2457492.82623 15.71600 0.00400
2457492.85971 15.72700 0.00400
2457492.87648 15.72700 0.00400
2457492.89324 15.72300 0.00400
2457492.90948 15.71000 0.00400
2457493.70069 15.71100 0.00400
2457493.71631 15.73000 0.00500
2457493.73209 15.71600 0.00400
2457493.74773 15.72800 0.00400
2457493.77138 15.72100 0.00400
2457493.79711 15.71700 0.00400
2457493.81265 15.71800 0.00400
2457493.83777 15.72400 0.00400
2457493.86204 15.74700 0.00300
2457493.87887 15.72600 0.00400
2457493.89519 15.71100 0.00400
2457493.91090 15.72200 0.00400
2457494.69608 15.72500 0.00400
2457494.71181 15.70800 0.00400
2457494.72743 15.72100 0.00400
2457494.74341 15.73200 0.00400
2457494.77067 15.72900 0.00400
2457494.79628 15.72700 0.00400
2457494.81201 15.72800 0.00400
2457494.83722 15.72100 0.00400
2457494.86261 15.71800 0.00400
2457494.87936 15.72500 0.00400
2457494.89592 15.71800 0.00400
2457494.91185 15.72300 0.00400
2457495.68151 15.71400 0.00500
2457495.69723 15.71200 0.00500
2457495.71299 15.72000 0.00500
2457495.72872 15.72000 0.00400
2457495.75235 15.71900 0.00400
2457495.76811 15.72100 0.00400
2457495.79290 15.73300 0.00400
2457495.80849 15.73300 0.00400
2457495.84252 15.73000 0.00400
2457495.85883 15.72200 0.00400
2457495.87540 15.73100 0.00400
2457495.89205 15.71900 0.00400
2457495.91626 15.71500 0.00400
2457495.93181 15.72900 0.00500
2457497.85629 15.74100 0.00400
2457497.88420 15.72000 0.00400
2457497.90002 15.72600 0.00500
2457497.91581 15.71300 0.00500
2457497.93139 15.71400 0.00600
2457498.71161 15.71800 0.00500
2457498.72727 15.71600 0.00500
2457498.74309 15.73700 0.00500
2457498.75877 15.70600 0.00400
2457498.80377 15.72300 0.00400
2457498.83564 15.72200 0.00500
2457498.85181 15.71100 0.00400
2457498.86868 15.72100 0.00400
2457498.89366 15.71700 0.00400
2457498.91884 15.72200 0.00400
2457499.67713 15.72000 0.00600
2457499.69271 15.70200 0.00500
2457499.71692 15.71000 0.00500
2457499.73272 15.71300 0.00500
2457499.74827 15.73200 0.00500
2457499.76382 15.70800 0.00500
2457499.78825 15.71800 0.00400
2457499.80391 15.72300 0.00400
2457499.81962 15.71800 0.00400
2457499.83520 15.71300 0.00400
2457499.85995 15.72300 0.00400
2457499.87644 15.70800 0.00500
2457499.89246 15.73100 0.00400
2457499.90825 15.71100 0.00400
2457499.93213 15.71300 0.00500
2457500.67572 15.70200 0.00600
2457500.70136 15.73200 0.00500
2457500.71684 15.72400 0.00500
2457500.73249 15.70700 0.00500
2457500.74802 15.70600 0.00500
2457500.77190 15.71000 0.00500
2457500.78747 15.71500 0.00500
2457500.80323 15.73300 0.00500
2457500.81899 15.71500 0.00500
2457500.84299 15.72500 0.00500
2457500.86111 15.72000 0.00500
2457500.87752 15.71500 0.00500
2457500.89310 15.71700 0.00500
2457500.91685 15.71100 0.00500
2457500.93235 15.70300 0.00600
2457507.74342 15.71000 0.00400
2457507.75737 15.72500 0.00400
2457507.77136 15.72100 0.00400
2457507.78581 15.72300 0.00400
2457507.79976 15.71900 0.00400
2457507.81377 15.71200 0.00400
2457507.82805 15.71800 0.00400
2457507.84268 15.72100 0.00400
2457507.86293 15.72100 0.00400
2457507.87700 15.72900 0.00400
2457507.89126 15.72000 0.00400
2457507.90529 15.72300 0.00400
2457507.92391 15.72700 0.00400
2457508.64851 15.69800 0.00400
2457508.66263 15.71500 0.00400
2457508.67678 15.72400 0.00400
2457508.69091 15.72100 0.00400
2457508.70488 15.72000 0.00400
2457508.71889 15.72300 0.00400
2457508.72973 15.72500 0.00400
2457508.74376 15.70800 0.00400
2457508.75765 15.73200 0.00400
2457508.77157 15.72400 0.00300
2457508.78568 15.72200 0.00300
2457508.79982 15.71200 0.00400
2457508.81397 15.71600 0.00400
2457508.82874 15.72200 0.00400
2457508.84380 15.71800 0.00400
2457508.85847 15.70900 0.00400
2457508.87292 15.71400 0.00400
2457508.88715 15.72200 0.00400
2457508.90252 15.72000 0.00400
2457508.91668 15.73400 0.00400
2457508.93061 15.72500 0.00400
2457509.72257 15.71100 0.00400
2457509.73707 15.72400 0.00500
2457509.75118 15.72200 0.00500
2457509.76550 15.72400 0.00400
2457509.77957 15.71700 0.00400
2457509.79445 15.71900 0.00400
2457509.80941 15.72500 0.00400
2457509.82408 15.71100 0.00400
2457509.83959 15.72000 0.00400
2457509.85398 15.73100 0.00400
2457509.86809 15.72600 0.00400
2457509.88219 15.72200 0.00400
2457509.89669 15.71000 0.00400
2457509.91090 15.71100 0.00400
2457509.92777 15.72100 0.00500
2457511.63959 15.70800 0.00400
2457511.67716 15.71600 0.00400
2457511.69153 15.72000 0.00400
2457511.70556 15.72800 0.00400
2457511.71953 15.71200 0.00400
2457511.73357 15.72200 0.00400
2457511.74763 15.71500 0.00400
2457511.76177 15.72700 0.00400
2457511.78593 15.72300 0.00400
2457511.80013 15.71900 0.00400
2457511.82525 15.72500 0.00400
2457511.84012 15.72800 0.00400
2457511.85491 15.71800 0.00400
2457511.86917 15.72500 0.00400
2457511.88319 15.71900 0.00400
2457511.89781 15.72300 0.00400
2457511.91191 15.71900 0.00400
2457511.92585 15.72100 0.00400
2457511.93528 15.71100 0.00400
2457512.70151 15.71800 0.00300
2457512.71716 15.72300 0.00300
2457512.72943 15.73000 0.00300
2457512.74059 15.72000 0.00400
2457512.75147 15.72300 0.00300
2457512.76246 15.72700 0.00300
2457512.77227 15.72400 0.00300
2457512.78146 15.72300 0.00300
2457512.79225 15.72600 0.00300
2457512.81587 15.73400 0.00400
2457512.83079 15.71900 0.00400
2457512.85452 15.73300 0.00300
2457512.86891 15.72900 0.00300
2457512.88289 15.73400 0.00400
2457512.89701 15.73600 0.00400
2457512.91101 15.73600 0.00400
2457512.92903 15.72600 0.00300
2457513.74610 15.70600 0.00400
2457516.63306 15.70100 0.00500
2457516.64777 15.70000 0.00500
2457516.66204 15.71000 0.00500
2457516.68408 15.72700 0.00500
2457516.70631 15.72200 0.00400
2457516.72272 15.73100 0.00400
2457516.76820 15.71800 0.00400
2457516.79164 15.72000 0.00400
2457518.73199 15.72700 0.00500
2457518.74795 15.70700 0.00500
2457518.87997 15.72300 0.00500
2457518.90005 15.73200 0.00500
2457519.80843 15.70200 0.00500
2457519.87708 15.72200 0.00400
2457522.72584 15.70500 0.00500
2457522.79200 15.72400 0.00400
2457522.81779 15.72000 0.00500
2457522.83660 15.72500 0.00500
2457522.85073 15.72200 0.00500
2457522.86476 15.70400 0.00500
2457522.87927 15.71200 0.00500
2457522.89355 15.72500 0.00500
2457522.90760 15.71100 0.00500
2457522.92179 15.70900 0.00600
2457522.93743 15.70900 0.00600
2457523.84914 15.72500 0.00400
2457523.86333 15.72800 0.00400
2457523.87756 15.72300 0.00400
2457523.89166 15.72600 0.00400
2457523.90577 15.72600 0.00400
2457523.91983 15.73000 0.00500
2457523.93389 15.71200 0.00500
2457526.60922 15.72000 0.00600
2457526.62886 15.70400 0.00600
2457526.64406 15.70700 0.00500
2457526.65930 15.73500 0.00500
2457526.67399 15.72300 0.00500
2457526.68879 15.70400 0.00500
2457526.70463 15.72800 0.00600
2457526.71906 15.72400 0.00500
2457526.73358 15.71700 0.00500
2457526.75427 15.71700 0.00400
2457526.78447 15.70800 0.00400
2457526.80011 15.69700 0.00400
2457526.82314 15.70600 0.00500
2457526.84563 15.71100 0.00500
2457526.85972 15.71600 0.00400
2457526.87476 15.71700 0.00400
2457526.88885 15.70200 0.00500
2457526.90298 15.72200 0.00500
2457526.91716 15.72200 0.00500
2457526.93119 15.70600 0.00600
2457527.91939 15.72600 0.00400
2457527.93037 15.74400 0.00400
2457528.76603 15.69700 0.00500
2457528.84378 15.73300 0.00500
2457528.86709 15.72200 0.00500
2457528.88186 15.72000 0.00500
2457528.89608 15.70900 0.00500
2457528.91043 15.71500 0.00500
2457528.92449 15.70400 0.00500
2457528.93849 15.71800 0.00500
2457529.75072 15.69600 0.00600
2457529.76568 15.72800 0.00500
2457529.78103 15.72100 0.00600
2457529.79635 15.71400 0.00600
2457529.81073 15.72600 0.00600
2457529.83366 15.71300 0.00700
2457529.88960 15.72700 0.00700
2457530.63310 15.72800 0.00600
2457530.64643 15.73100 0.00600
2457530.66236 15.72000 0.00600
2457530.67455 15.72700 0.00500
2457530.69171 15.71500 0.00500
2457530.71241 15.72500 0.00500
2457530.73791 15.71300 0.00500
2457530.76070 15.71700 0.00500
2457530.77706 15.71200 0.00500
2457530.79797 15.71000 0.00500
2457530.81578 15.72100 0.00500
2457530.83425 15.70100 0.00500
2457530.85638 15.71600 0.00500
2457530.87858 15.72400 0.00500
2457530.90111 15.73100 0.00500
2457530.91348 15.73200 0.00600
2457534.64788 15.71600 0.00500
2457534.65753 15.71800 0.00500
2457534.67696 15.72400 0.00500
2457534.69091 15.71600 0.00500
2457534.70597 15.71200 0.00500
2457534.71994 15.72500 0.00500
2457534.73472 15.71100 0.00500
2457534.75379 15.71800 0.00400
2457534.77206 15.71300 0.00400
2457534.78859 15.72600 0.00400
2457534.80266 15.71500 0.00400
2457534.81660 15.73100 0.00400
2457534.83190 15.72100 0.00400
2457534.84785 15.70900 0.00400
2457534.86230 15.72000 0.00500
2457534.87640 15.71800 0.00400
2457534.89424 15.71900 0.00400
2457534.90831 15.71500 0.00400
2457534.93043 15.71600 0.00500
2457534.93930 15.73000 0.00500
2457534.94895 15.70200 0.00600
2457536.58134 15.70200 0.00600
2457536.59615 15.71800 0.00500
2457536.61068 15.72100 0.00500
2457536.62634 15.72300 0.00600
2457536.64637 15.72400 0.00500
2457536.66141 15.73800 0.00500
2457536.67555 15.72400 0.00500
2457536.69869 15.72400 0.00500
2457536.71264 15.72500 0.00400
2457536.73618 15.72100 0.00400
2457536.75082 15.72100 0.00400
2457536.76566 15.73100 0.00400
2457536.77976 15.70000 0.00400
2457536.79384 15.69800 0.00400
2457536.80801 15.71100 0.00400
2457536.82207 15.73100 0.00400
2457536.83632 15.71400 0.00400
2457536.85037 15.72100 0.00400
2457536.86447 15.70700 0.00400
2457536.88002 15.72100 0.00400
2457536.89761 15.71800 0.00400
2457536.91255 15.70200 0.00400
2457545.59099 15.71000 0.00500
2457545.63066 15.72800 0.00500
2457545.64000 15.70500 0.00500
2457545.65208 15.71600 0.00400
2457545.66411 15.70900 0.00400
2457545.67589 15.72500 0.00400
2457545.72238 15.70600 0.00400
2457545.73403 15.70900 0.00400
2457545.74670 15.72000 0.00400
2457545.76031 15.71500 0.00400
2457545.77136 15.71600 0.00400
2457545.79543 15.71400 0.00400
2457545.81845 15.71800 0.00400
2457545.83237 15.72200 0.00400
2457545.84646 15.72500 0.00400
2457545.86070 15.73200 0.00400
2457545.87463 15.71000 0.00400
2457545.89021 15.73100 0.00500
2457545.90410 15.70900 0.00400
2457545.91835 15.70800 0.00400
2457545.93266 15.71900 0.00500
2457546.59688 15.73000 0.00500
2457546.61152 15.72100 0.00600
2457546.62440 15.71400 0.00600
2457546.63968 15.72900 0.00500
2457546.65368 15.71800 0.00500
2457546.66515 15.71700 0.00500
2457546.67939 15.71600 0.00500
2457546.69651 15.71500 0.00400
2457546.71093 15.72400 0.00400
2457546.72567 15.72600 0.00400
2457546.74324 15.71700 0.00500
2457546.75737 15.71000 0.00400
2457546.77138 15.73700 0.00500
2457546.78543 15.71400 0.00400
2457546.79943 15.72300 0.00400
2457546.81413 15.70900 0.00500
2457546.82812 15.71700 0.00400
2457546.84226 15.71200 0.00400
2457546.85638 15.71100 0.00400
2457546.87036 15.70600 0.00500
2457546.88435 15.70100 0.00500
2457546.89835 15.70800 0.00500
2457546.91249 15.72800 0.00500
2457546.92646 15.72800 0.00500
2457546.93735 15.72400 0.00500
2457547.54062 15.71800 0.00600
2457547.55240 15.73200 0.00600
2457547.56679 15.70700 0.00600
2457547.58077 15.70100 0.00600
2457547.59467 15.71400 0.00500
2457547.60881 15.72900 0.00500
2457547.62316 15.72300 0.00500
2457547.63700 15.72700 0.00400
2457547.65170 15.72600 0.00400
2457547.66908 15.72600 0.00400
2457547.68745 15.72500 0.00400
2457547.70480 15.72000 0.00500
2457547.71885 15.72500 0.00400
2457547.73329 15.72200 0.00400
2457547.75099 15.72500 0.00400
2457547.76525 15.72000 0.00400
2457547.77927 15.72400 0.00400
2457547.79334 15.73000 0.00400
2457547.80747 15.71800 0.00400
2457547.82165 15.71400 0.00400
2457547.83584 15.71600 0.00400
2457547.84992 15.72700 0.00400
2457547.87790 15.71500 0.00500
2457547.89189 15.71100 0.00600
2457547.90583 15.69600 0.00500
2457547.92419 15.71900 0.00400
2457547.93349 15.71500 0.00500
2457548.54179 15.69700 0.00400
2457548.55978 15.71100 0.00500
2457548.58499 15.72200 0.00400
2457548.59995 15.71500 0.00300
2457548.61526 15.71400 0.00300
2457548.63249 15.71700 0.00400
2457548.64891 15.72400 0.00400
2457548.66262 15.71200 0.00300
2457548.67626 15.71200 0.00300
2457548.69310 15.71200 0.00300
2457548.71077 15.72800 0.00300
2457548.72724 15.72200 0.00300
2457548.74072 15.73400 0.00400
2457548.75654 15.72700 0.00300
2457548.76939 15.70800 0.00300
2457548.78519 15.71700 0.00400
2457548.79886 15.72900 0.00400
2457548.81887 15.72400 0.00300
2457548.83392 15.70400 0.00300
2457548.84763 15.72300 0.00400
2457548.86289 15.72500 0.00300
2457548.87665 15.69500 0.00300
2457548.89020 15.70100 0.00300
2457548.90532 15.70500 0.00300
2457548.92065 15.70800 0.00400
2457549.56581 15.70700 0.00400
2457549.58246 15.71400 0.00500
2457549.59406 15.71400 0.00500
2457549.60840 15.71700 0.00400
2457549.62057 15.71500 0.00400
2457549.63451 15.71100 0.00400
2457549.64855 15.71400 0.00400
2457549.66652 15.71600 0.00400
2457549.68104 15.71900 0.00400
2457549.69816 15.73100 0.00400
2457549.71251 15.71400 0.00400
2457549.72735 15.71400 0.00400
2457549.74236 15.71200 0.00400
2457549.75672 15.72100 0.00400
2457549.77069 15.72500 0.00400
2457549.79046 15.73000 0.00400
2457549.80444 15.73500 0.00400
2457549.81846 15.73000 0.00400
2457549.83247 15.72400 0.00400
2457549.84649 15.73100 0.00400
2457549.86050 15.71200 0.00400
2457549.87447 15.72400 0.00400
2457549.88844 15.71900 0.00400
2457549.90251 15.72000 0.00400
2457549.91649 15.71600 0.00500
2457549.92898 15.72500 0.00500
2457550.56612 15.71900 0.00500
2457550.57707 15.72600 0.00500
2457550.59036 15.72400 0.00500
2457550.60357 15.71600 0.00400
2457550.61458 15.70700 0.00500
2457550.62870 15.71300 0.00500
2457550.64287 15.72000 0.00500
2457550.65704 15.69900 0.00500
2457550.67141 15.70700 0.00400
2457550.68558 15.70600 0.00400
2457550.70432 15.73500 0.00400
2457550.72067 15.71800 0.00400
2457550.73871 15.72200 0.00400
2457550.75295 15.72000 0.00400
2457550.76853 15.71600 0.00400
2457550.78306 15.72100 0.00400
2457550.79698 15.71900 0.00400
2457550.81100 15.72000 0.00400
2457550.82498 15.72800 0.00400
2457550.83906 15.72600 0.00400
2457550.85340 15.73200 0.00400
2457550.86735 15.71400 0.00500
2457550.88135 15.71900 0.00500
2457550.89594 15.71700 0.00500
2457550.90998 15.69800 0.00500
2457550.92391 15.73300 0.00600
2457551.59387 15.73000 0.00400
2457552.73135 15.72900 0.00400
2457552.74576 15.72100 0.00400
2457553.85615 15.71000 0.00500
2457554.54066 15.70700 0.00500
2457554.58395 15.71800 0.00500
2457554.60233 15.73200 0.00500
2457554.61859 15.73200 0.00400
2457554.63901 15.71600 0.00500
2457554.65821 15.71500 0.00400
2457554.68325 15.72300 0.00400
2457554.72888 15.71700 0.00400
2457554.74766 15.72400 0.00500
2457554.78447 15.71500 0.00400
2457554.81297 15.71500 0.00400
2457555.52383 15.72400 0.00500
2457555.54036 15.71700 0.00500
2457555.55659 15.73500 0.00500
2457555.57568 15.72000 0.00400
2457555.59147 15.72200 0.00500
2457555.60640 15.72600 0.00400
2457555.62108 15.70500 0.00400
2457555.63624 15.71100 0.00400
2457555.65148 15.71600 0.00400
2457555.66670 15.71600 0.00400
2457555.68204 15.72000 0.00400
2457555.69815 15.70600 0.00400
2457555.71491 15.70400 0.00400
2457555.72998 15.73200 0.00500
2457555.74502 15.71600 0.00400
2457555.75923 15.72300 0.00400
2457555.77330 15.71900 0.00400
2457555.78783 15.71800 0.00400
2457555.80202 15.72400 0.00400
2457555.81653 15.73500 0.00400
2457555.83066 15.73000 0.00400
2457555.85652 15.72300 0.00400
2457555.87953 15.71700 0.00400
2457555.89368 15.71000 0.00400
2457555.90776 15.71800 0.00400
2457557.54240 15.71500 0.00600
2457557.55941 15.71700 0.00500
2457557.57389 15.73000 0.00500
2457557.59036 15.72200 0.00500
2457557.60537 15.72500 0.00500
2457557.61836 15.73000 0.00500
2457557.63316 15.71700 0.00500
2457557.65389 15.71300 0.00400
2457557.67067 15.71000 0.00400
2457557.68366 15.72200 0.00400
2457557.70272 15.71600 0.00500
2457557.71955 15.72900 0.00500
2457557.73853 15.71900 0.00500
2457557.75535 15.71700 0.00500
2457557.78583 15.71500 0.00500
2457557.81067 15.73600 0.00400
2457557.83102 15.72000 0.00400
2457557.84860 15.72700 0.00400
2457557.86524 15.72700 0.00500
2457557.88085 15.72400 0.00500
2457557.89661 15.72000 0.00500
2457557.90974 15.70700 0.00500
2457561.51330 15.73400 0.00600
2457561.52812 15.71500 0.00600
2457561.54324 15.74100 0.00700
2457561.57135 15.72700 0.00600
2457561.58858 15.72100 0.00500
2457561.60552 15.71300 0.00500
2457561.62014 15.71300 0.00400
2457561.63520 15.72600 0.00400
2457561.64955 15.70800 0.00400
2457561.66782 15.70900 0.00400
2457561.68585 15.70900 0.00500
2457561.70040 15.71800 0.00400
2457561.72238 15.71200 0.00400
2457561.73756 15.72700 0.00500
2457561.75223 15.71100 0.00400
2457561.76677 15.71400 0.00400
2457561.78109 15.71000 0.00400
2457561.79298 15.71100 0.00400
2457561.80564 15.71700 0.00500
2457561.82123 15.72700 0.00500
2457561.83552 15.71500 0.00400
2457561.85227 15.72700 0.00500
2457562.51670 15.71400 0.00600
2457562.52677 15.73400 0.00500
2457562.54098 15.74400 0.00600
2457562.55492 15.72800 0.00600
2457562.56947 15.72800 0.00500
2457562.58513 15.73400 0.00600
2457562.60200 15.73200 0.00600
2457562.61889 15.74400 0.00600
2457562.64189 15.72800 0.00500
2457562.66007 15.71400 0.00500
2457566.52749 15.71700 0.00500
2457566.54178 15.71700 0.00500
2457566.55682 15.72000 0.00500
2457566.57085 15.72700 0.00500
2457566.59429 15.70400 0.00600
2457566.60847 15.71000 0.00500
2457566.63313 15.70500 0.00500
2457566.64734 15.72100 0.00400
2457566.66163 15.72100 0.00400
2457566.67593 15.71800 0.00400
2457566.69075 15.70700 0.00400
2457566.70535 15.71900 0.00400
2457566.72084 15.72600 0.00400
2457566.73503 15.72000 0.00400
2457566.74910 15.71900 0.00500
2457566.76321 15.73300 0.00500
2457566.77776 15.72600 0.00500
2457566.79184 15.72500 0.00400
2457566.80593 15.73600 0.00500
2457566.82007 15.71900 0.00400
2457566.83419 15.72400 0.00500
2457566.84831 15.73700 0.00600
2457566.86239 15.73300 0.00600
2457566.87512 15.72100 0.00600
2457567.49685 15.71600 0.00600
2457567.51434 15.73200 0.00500
2457567.52839 15.72900 0.00600
2457567.54253 15.73100 0.00500
2457567.55732 15.71500 0.00500
2457567.57131 15.73600 0.00500
2457567.58558 15.73100 0.00500
2457567.60888 15.71500 0.00400
2457567.62445 15.71300 0.00400
2457567.64764 15.71000 0.00400
2457567.66241 15.72800 0.00400
2457567.67745 15.72500 0.00400
2457567.69213 15.72400 0.00500
2457567.70671 15.70400 0.00400
2457567.72081 15.71400 0.00400
2457567.73599 15.72600 0.00400
2457567.74996 15.71100 0.00400
2457567.76397 15.71300 0.00500
2457567.77808 15.71500 0.00500
2457567.79227 15.71800 0.00400
2457567.80622 15.71600 0.00400
2457567.82020 15.70800 0.00400
2457567.83425 15.72200 0.00400
2457567.84828 15.71400 0.00500
2457567.86241 15.70800 0.00500
2457567.87813 15.73200 0.00500
2457568.49863 15.70700 0.00600
2457568.56541 15.72200 0.00500
2457568.57921 15.72100 0.00500
2457568.59316 15.72800 0.00400
2457568.60843 15.73500 0.00500
2457568.62239 15.71100 0.00400
2457568.63654 15.72500 0.00400
2457568.66202 15.73000 0.00400
2457568.67716 15.73000 0.00500
2457568.70209 15.72800 0.00400
2457568.71652 15.70300 0.00500
2457568.73097 15.69600 0.00500
2457568.74876 15.70300 0.00500
2457568.76288 15.71600 0.00500
2457568.77703 15.70600 0.00500
2457568.79101 15.70200 0.00500
2457568.80640 15.72600 0.00400
2457568.84210 15.68800 0.00600
2457568.85632 15.70600 0.00500
2457569.51725 15.71200 0.00500
2457569.53990 15.72400 0.00500
2457569.55393 15.71700 0.00500
2457569.56781 15.71800 0.00400
2457569.58195 15.71200 0.00500
2457569.59666 15.72000 0.00500
2457569.61092 15.72100 0.00400
2457569.63619 15.72000 0.00400
2457569.65037 15.72600 0.00400
2457569.67532 15.72400 0.00400
2457569.69138 15.73900 0.00400
2457569.70631 15.73400 0.00500
2457569.72233 15.72800 0.00400
2457569.73665 15.71200 0.00500
2457569.75082 15.71700 0.00400
2457569.76626 15.71900 0.00400
2457569.78045 15.71800 0.00400
2457569.79449 15.71500 0.00400
2457569.80854 15.71700 0.00400
2457569.82371 15.71500 0.00500
2457570.57181 15.69500 0.00500
2457570.65601 15.71100 0.00300
2457570.67696 15.72300 0.00400
2457570.68951 15.72600 0.00500
2457570.70361 15.72300 0.00400
2457570.71805 15.73100 0.00400
2457570.73079 15.71300 0.00400
2457570.74723 15.71200 0.00400
2457570.76083 15.72100 0.00500
2457570.77862 15.73900 0.00400
2457570.79313 15.71900 0.00400
2457570.82738 15.72500 0.00500
2457570.84076 15.71200 0.00400
2457570.85395 15.69600 0.00500
2457572.52407 15.71700 0.00400
2457573.59038 15.72500 0.00500
2457573.60302 15.72800 0.00400
2457573.62549 15.71700 0.00500
2457573.63869 15.72200 0.00500
2457573.65341 15.72200 0.00400
2457573.67933 15.71500 0.00500
2457573.69202 15.69900 0.00400
2457573.70789 15.71000 0.00400
2457573.72059 15.71500 0.00400
2457573.73480 15.69500 0.00600
2457573.77777 15.70700 0.00500
2457575.50700 15.72000 0.00500
2457575.52096 15.70200 0.00500
2457575.53409 15.72000 0.00500
2457575.54729 15.70800 0.00500
2457575.57045 15.71800 0.00500
2457575.58334 15.70400 0.00500
2457575.59733 15.69400 0.00500
2457575.61051 15.71700 0.00500
2457575.62315 15.72200 0.00500
2457575.63595 15.73700 0.00400
2457575.65912 15.72700 0.00400
2457575.67296 15.72300 0.00400
2457575.68605 15.73300 0.00400
2457575.70020 15.71200 0.00400
2457575.71278 15.71000 0.00400
2457575.72548 15.72300 0.00400
2457575.73839 15.72100 0.00400
2457575.75126 15.71600 0.00400
2457575.76410 15.71500 0.00400
2457575.77680 15.72000 0.00400
2457575.78968 15.72500 0.00400
2457575.80247 15.71100 0.00400
2457575.81535 15.70700 0.00400
2457575.82794 15.70900 0.00400
2457575.84093 15.71100 0.00400
2457575.84903 15.72700 0.00500
2457576.47811 15.71600 0.00500
2457576.49105 15.71700 0.00400
2457576.50373 15.71800 0.00500
2457576.51648 15.70700 0.00500
2457576.52907 15.72400 0.00500
2457576.54276 15.70300 0.00500
2457576.57179 15.70400 0.00400
2457576.58460 15.71600 0.00400
2457576.60706 15.72000 0.00400
...


Here the complete file
data.txt (88.2 KB)

1 Like

As others mentioned the parameters and priors should have the same support, and I think it’s considered a bad idea just to declare a uniform prior with a range much larger than the expected parameter value. This document outlines the current wisdom of Stan’s developers on principles for prior specification: Prior-Choice-Recommendations

I tried your model with the minimal change of making the priors gaussians. Also I assume f is a fraction so I declared it as real<lower=0, upper=1> f; in the parameters block. Here are the priors I picked:

  t0 ~ normal(0., 1000.);   //priors
te  ~ normal(25., 5.);
u0 ~ normal(0.5, 1.);
Ibl ~ normal(15., 5.);
f ~ beta(1, 1);


I also subtracted off the initial value of t from the time stamps to make that a little more favorably scaled. The model ran with no warnings and all convergence diagnostics look good. I don’t know what reasonable parameter values would be but here is a traceplot and histograms of all parameters including the unscaled log-probability:

Assuming f is indeed a fraction it appears to be not too well constrained by the data.

2 Likes

Awesome! I also rescaled the time and this is the new stan file I used:

parameters {
real<lower=700,upper=1000> t0;
real<lower=20,upper=30> te;
real<lower=0,upper=1> u0;
real<lower=10,upper=20> Ibl;
real<lower=0,upper=1> f;
}

model {
t0 ~ normal(700, 100.);   //priors
te  ~ normal(25., 5.);
u0 ~ normal(0.5, 1.);
Ibl ~ normal(15., 5.);
f ~ beta(1, 1);

for (i in 1:n)
mags_obs[i] ~ normal(mag(t[i], u0, t0, te, Ibl, f), sigma[i]);   //liklelihood
}


with the following diagnostic:

Information and diagnostics
===========================
Run time (min):                   15.69
Total iter:                       10000
Warmup:                           5000
Thin:                             1
Num chains:                       1
Mean accept stat:                 0.95
Mean tree depth:                  5.7
Mean step size:                   0.0122
Num divergent transitions:        0
Num max tree depth exceeds:       0
Num chains with BFMI warnings:    0
Max Rhat:                         1
Min n.eff:                        641

Model summary
=============
mean           sd          2.5%           50%         97.5% Rhat n.eff
t0     757.4778062 5.120655e-02   757.3806553   757.4778899   757.5768630    1  1375
te      26.4642770 7.995879e-01    24.8716192    26.4625014    28.0214124    1   707
u0       0.7803324 3.780291e-02     0.7107575     0.7788386     0.8584149    1   668
Ibl     15.7188837 8.697862e-05    15.7187119    15.7188841    15.7190559    1  4042
f        0.6171154 5.485088e-02     0.5208967     0.6133327     0.7350194    1   641
lp__ -6657.3830425 1.607298e+00 -6661.4602078 -6657.0617999 -6655.2146914    1   903


where the true parameter values should be:

################### true parameter values:
t0 <- 2458182.353 -  min(dt[,1]); #( t0 = 757.48205)
sigma_t0 <- 0.051

te <- 26.640
sigma_te <- 0.781

u0 <- 0.771
sigma_u0 <- 0.031

f <- 0.602
sigma_f <- 0.051

Ibl <- 15.719
##################


I run it with 10000 iters and all other options left by default (starting values chosen near the sought parameter values tho). I see in diagnostic that the “mean accept stat” is 0.95, if it refers to the acceptance rate is indeed a bit high isn’t it? I should change the adapt_delta option right? Again thank you, it seems that a subtle change in the prior would make a lot of difference here.

1 Like