Download presentation
Presentation is loading. Please wait.
Published byAnnabel Goodwin Modified over 8 years ago
1
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 1 7. Stochastic concepts in LIAM2
2
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 2 Random functions Choice Logit_score Align Align_abs Logit_regr Other regressions Concepts
3
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 3 LIAM2 includes support for many random number generator functions. For details, see LIAM2 User Guide. Examples: uniform(): uniform in [0, 1) normal(): standard normal (mean=0, std=1) randint(0, 10): random integer between 0 and 10 excluded Random functions
4
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 4 Stochastic simulation relies on random numbers, but true random numbers generators do not exist Advantage of pseudo-random generators: speed and reproducibility Fortunately, Monte-Carlo is not too picky in that department – as long as u is “random enough” Python (and thus LIAM2) uses the Mersenne Twister (Matsumoto and Nishimura, 1997). Use “random_seed: to fix the sequence of random numbers In the latest version of LIAM2 (0.10.3) this can also be done in mid- simulation Random functions
5
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 5 Suppose event Y with two possible outcomes: 0 and 1 Pr[Y=1] = p Pr[Y=0] = 1 - p Draw a uniform random number u i If u i < p then the event is realized and Y i becomes 1 Example: Demo06 Gender (at birth) = choice([options],[probabilities]) = choice([False, True],[0.51, 0.49]) = choice([MALE, FEMALE],[0.51, 0.49]) Choice
6
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 6 Logit_score and logit_regr
7
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 7 Example: we want to simulate whether an individual is being born in or outside Belgium, and suppose that this depends on whether the individual is 50 years or over, or not. immigrant= False (Born in Belgium) True (born outside Belgium) old = False (age < 50) True (age ≥ 50) birth= -0.190136 -1.607228 oldlogistic regression on SILC Belgium for 2013 How can this be simulated? Take the inverse logit of the regression results and compare with a uniform stochast - a: -0.190136 -1.607228 * old - interm: exp(a) / (1+exp(a)) - immigrant: interm > uniform() Or use the fact that logit_score(a) = logistic(a - logit(u)) - interm2: logit_score(-0.190136 -1.607228 * old) - immigrant: interm2 > 0.5 Or use the fact that logit_regr is a combination of logit_score and the evaluation condition - immigrant: logit_regr(a) - immigrant: logit_regr(-0.190136 -1.607228 * old) Logit_score and logit_regr
8
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 8 Alignment is used when we want that the number of events occuring per category matches an exogenous proportion. The methodology used for now by LIAM2 is called “alignment by sorting”, that is, for each category, the N individuals with the highest scores are selected. The score computation has to be computed by the modeller (with logit_score() for example) Stochastic simulation using alignment
9
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 9 Example: we want to simulate whether an individual is being born in or outside Belgium immigrant= False (Born in Belgium) True (33.75%) old = False (age < 50) True (age ≥ 50; 36%) birth: logit_regr(-0.190136 -1.607228 * old) But now we want the proporion of immigrants to be exactly x% - birth: logit_regr(-0.190136 -1.607228 * old, align=0.3375) Suppose that %(old | immigrant) = 15.26% in the SILC data Stochastic simulation using alignment
10
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 10 score proportions filter (optional arguments) take (optional arguments) leave (optional arguments) expressions (optional arguments) possible_values (optional arguments) frac_need (optional arguments) Align – structural form
11
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 11 It must be an expression (or a simple variable) returning a numerical value. It will be used to rank individuals. One will usually use logit_score() to compute the score, but it can be computed in any other way a modeller choose. Note that the score is not modified in any way within the align() function, so if one wants a random factor, it should be added manually. Align - score
12
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 12 It must be an expression (or a simple variable) returning a numerical value. It will be used to rank individuals. One will usually use logit_score() to compute the score, but it can be computed in any other way a modeller choose. Note that the score is not modified in any way within the align() function, so if one wants a random factor, it should be added manually. Examples; using logit_regr -immigrant4: logit_regr(-0.190136 -1.607228 * old, align=0.3375) is equivalent to -log_interm= logit_score(-0.190136 -1.607228 * old) -immigrant4: align(log_interm, 0.33775) Then why is the below expression wrong? -immigrant4: align(-0.190136 -1.607228 * old, 0.33775) Align - score
13
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 13 take: an expression specifying individuals which should always be selected, regardless of their score. leave: an expression specifying individuals which should never be selected, regardless of their score. Example: suppose that we want to model that in any period, exactly 5% of the population has a cat, and nobody older than 50 has a cat. - interm: logit_score(0.0) - has_a_cat: align(interm, 0.05, leave = old) Align – take and leave
14
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 14 The take and leave conditions are the only conditions that give the distribution of individual characteristics priority over the alignment totals. Example: suppose that we want to model that in any period, exactly 5% of the population has a cat, and anybody older than 50 has a cat. - interm: logit_score(0.0) - has_a_cat: align(interm, 0.05, take = old) Hence all old = 1 (about 36% of the sample) will all have a cat, and not 5% Question: is there a better, “softer” way in modeling this? Align – take and leave
15
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 15 align_abs is equivalent to align(), except that it aligns to absolute numbers instead of proportions. It also supports a few additional arguments to work on a linked entity. Chénard’s (2001) algorithm Align_abs
16
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 16 score need filter (optional arguments) take (optional arguments) leave (optional arguments) expressions (optional arguments) possible_values (optional arguments) frac_need (optional arguments) link (optional arguments) secondary_axis (optional arguments) errors (optional arguments) Align_abs – structural form
17
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 17 Align_abs – specific arguments Align_abs(…, need, link=link name to entity level 2, …) e.g. align_abs(…,200, link=persons, …) called on the level of the household Select observations on entity level 1 In order to get a close as possible to alignment targets ‘need’ that pertain to entity level 2 Used on entity level 1
18
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 18 Continuous (expr + normal(0, 1) * mult + error_var): cont_regr(expr[, filter=None, mult=0.0, error_var=None]) Clipped continuous (always positive): clip_regr(expr[, filter=None, mult=0.0, error_var=None]) Log continuous (exponential of continuous): log_regr(expr[, filter=None, mult=0.0, error_var=None]) Other regressions
19
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 19 Exercises
20
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 20 Stochastic simulation using choice Exercise 1 Can you simulate the eye colour (eye_colour) of newborns, using the following probabilities Brown: 55% Blue: 8% Green: 2% Other: 35% (hazel, amber, …) Source: “Eye color worldwide” (https://www.quora.com/Whats-the-distribution-of-eye-colors-in-the-world) [06/11/2015]https://www.quora.com/Whats-the-distribution-of-eye-colors-in-the-world
21
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 21 Exercise 2 In the current setting, only the married woman decides to divorce. - divorce: logit_regr(0.6713593 * nb_children - 0.0785202 * dur_in_couple + 0.1429621 * agediff - 0.0088308 * agediff **2 - 4.546278, filter=ISFEMALE and ISMARRIED and (dur_in_couple > 0), align='al_p_divorce.csv') Suppose that you want to use two estimated logistic regression models, one for women with and without children. The two (fictitious!) models are -4.0 - 0.01 * dur_in_couple + 0.2 * agediff - 0.01 * agediff **2 for women without children - 4.0 - 0.005 * dur_in_couple + 0.2 * agediff - 0.01 * age_youngest_child for women who live with children in the household Stochastic simulation using logistic regressions
22
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 22 Exercise 3 Suppose that we want to implement a mandatory period of inactivity for one year for women following child birth. How would you implement this in Demo08.yml? Stochastic simulation using logistic regressions
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.