Page 2 of 2

Re: How to use Markov Chain Monte Carlo in Vensim?

Posted: Tue Sep 18, 2018 5:44 pm
by WayneZhou2009
Hi Tom, thank you so much for your further reply. As mentioned yesterday, I have attached a slightly revised model which should reflect the (hypothetical) application context better than the model yesterday.

Basically the situation is that I have a dataset representing vehicle inventory as a function of time (day). For day 0, the inventory has 1000 cars, then with daily scrappage, the inventory decreases. So, for day 1, the remaining number of cars is 999, day 2 is 996, day 3 is 990, and so on, all the way till day 100 when the inventory becomes 0.

The curve looks like the reliability profile of Weibull function, i.e. 1-CDF. Now I want to calibrate my Weibull function against this dataset so as to estimate the shape parameter and scale parameter of the Weibull. Meanwhile, suppose prior knowledge and/or expert opinion suggests that prior distributions should be applied to shape and scale of Weibull, then I use lognormal for the shape parameter and uniform for the scale parameter. Essentially the priors in this model are the same as yesterday's.

I use a stock to represent the model of vehicle stock (which is compared with the dataset) and a flow to represent the scrappage rate. Note that the scrappage profile is the failure rate of Weibull, which is a formula involving shape and scale.

I believe this model should look clearer than yesterday's model and its purpose can be shown more explicitly? But again, the same question that I'd like to discuss with you - how to manage the SD of errors so that I can be sure that the log likelihood of the data points (namely, -(Model of vehicle stock-Data of vehicle inventory)/SD of errors)^2/2 ) will have the same (comparable) order of magnitude as the log likelihood of the prior PDFs and thus their sum makes sense in the maximization process?

For the iteration of the SD of the error, is there a way to do it "endogenously", i.e. making it part of the model simulation?

Clearly the SD plays a key role as the total log likelihood is sensitive to the SD (given fixed prior weight, e.g. 1). And so are the resultant shape and scale parameters.

Thank you so much for your time.

Re: How to use Markov Chain Monte Carlo in Vensim?

Posted: Tue Sep 18, 2018 9:45 pm
by tomfid
I haven't had a chance to look, but this might be useful:
http://metasd.com/2017/10/bernoulli-poisson-bar/
http://metasd.com/2011/04/delay-sandbox/

Re: How to use Markov Chain Monte Carlo in Vensim?

Posted: Wed Sep 19, 2018 2:05 pm
by WayneZhou2009
Many thanks for sharing the links Tom. They are useful. Meanwhile, I would be very grateful if you could take a look at the model and offer some advice (please see my questions above). Thank you so much for your time.

Re: How to use Markov Chain Monte Carlo in Vensim?

Posted: Wed Sep 19, 2018 5:01 pm
by tomfid
This gets a beyond my area of expertise. I know there's a whole literature on hazard rate estimation that's relevant here.

My naive implementation would be something like the following:
- the Weibull distribution gives you the expected failure rate and surviving population at any given point in time
- if the process were first order, the actual failures would have a Binomial distribution where n=survivors and p = expected failures/survivors.
- so, you could use the Binomial likelihood (rather than a Normal mean/sd) to evaluate the fit
However, the process isn't really first order. The Weibull distribution probably implies some internal distribution of states, but I don't know what it is. I'd be inclined to ignore the problem and use Poisson (mean = variance) as an approximation.

It makes more sense to me to switch to a distribution with a clearer physical interpretation (Erlang = Delay N) - hence the link.

Re: How to use Markov Chain Monte Carlo in Vensim?

Posted: Wed Sep 19, 2018 5:07 pm
by tomfid
The other problem with using Weibull is that it makes scrap=f(time) which is not robust or generally applicable. If you're planning to use the scrap submodel in more general conditions, you really need scrap=f(state). Options would be:
- an explicit stock-flow aging chain,
- DELAY N as a shortcut for that
- DELAY PROFILE for a more general delays structure (but harder to parameterize)

The most general approach would be to use an array for the aging chain, with distinct loss rates for each age class.

Re: How to use Markov Chain Monte Carlo in Vensim?

Posted: Wed Sep 19, 2018 8:59 pm
by WayneZhou2009
Hi Tom, thank you so much for your advice, all of which is very enlightening. I did read one of you articles which was regarding dynamic cohorts and I found it very inspiring. Actually I knew my model about the scrappage is very much over-simplified but I just wanted to use it to serve as a context where my questions can be asked and understood more clearly hopefully. I guess the model being over-simplified would not affect the understanding of the general calibration principle and techniques. It just provides a context, a background.

My real question is still about the weight, i.e. how to manage the SD of errors so that I can be sure that the log likelihood of the data points (namely, -(Model of vehicle stock-Data of vehicle inventory)/SD of errors)^2/2 ) will have the same (comparable) order of magnitude as the log likelihood of the prior PDFs and thus their sum makes sense in the maximization process? If the SD of errors is significantly unreasonably set, then the sum of the log-likelihood of data points and the prior PDFs will not make sense because they probably are at significantly different orders of magnitude, right?

If iteration of the SD of the errors is considered a good practice, is there a way to do it "endogenously"/"automatically"?

Thank you so much.

Re: How to use Markov Chain Monte Carlo in Vensim?

Posted: Thu Sep 20, 2018 6:16 pm
by tomfid
If there's a statistically principled way to do this, I'm not familiar with it.

I would model the losses as an approximation, with sd error = sqrt(losses/unit losses).

I think there's another issue, which is that errors are integrated into the stock of survivors, so you should be using the Kalman filter. But that's not exactly right either, because its disturbances are modeled as Gaussian, when they should be Poisson or Binomial.

Re: How to use Markov Chain Monte Carlo in Vensim?

Posted: Mon Sep 24, 2018 8:33 pm
by WayneZhou2009
Hi Tom, I have given more thoughts to your advice on using Binomial or Poisson for likelihood function, rather than Gaussian for likelihood function. According to Payoff Element Types in Reference Manual, for Binomial, the payoff contribution is:

log( model p success^data_n_successes * (1-model p success)^(n_trials-data_n_successes) )

My question is: in the context of vehicle scrappage, does the "model p success" represent the ratio of modelled remaining vehicle at a give time (e.g. 800 in day 10) to the total number of vehicle at the initial time when no scrappage takes place, i.e. 1000 vehicle? Accordingly, does "data_n_successes" represent the data remaining vehicle at a given time (e.g. 780 for day 10) ? As for "n_trials", it is the total number of vehicle at the initial time when no scrappage takes place, i.e. 1000 vehicle?

Thank you so much.
tomfid wrote: Wed Sep 19, 2018 5:01 pm This gets a beyond my area of expertise. I know there's a whole literature on hazard rate estimation that's relevant here.

My naive implementation would be something like the following:
- the Weibull distribution gives you the expected failure rate and surviving population at any given point in time
- if the process were first order, the actual failures would have a Binomial distribution where n=survivors and p = expected failures/survivors.
- so, you could use the Binomial likelihood (rather than a Normal mean/sd) to evaluate the fit
However, the process isn't really first order. The Weibull distribution probably implies some internal distribution of states, but I don't know what it is. I'd be inclined to ignore the problem and use Poisson (mean = variance) as an approximation.

It makes more sense to me to switch to a distribution with a clearer physical interpretation (Erlang = Delay N) - hence the link.

Re: How to use Markov Chain Monte Carlo in Vensim?

Posted: Mon Sep 24, 2018 10:07 pm
by tomfid
The Poisson & Binomial distributions only make sense for flows.

In this case, the data_n_success would be the # scrapped in an interval, n_trials = model_surviving (stock), and model_p_success = model_scrap/model_surviving.

This is still wrong, in a sense, because the Weibull distribution implies a multistage process, but the above formulation assumes a single stage.