I am trying to model a seasonal fluctuation for an immunity fraction
The model setting in months and runs for 60 months
3rd week of January 0.16 and 3rd week of July 0.84 repeating is required
I understand I should have Time as input (shadow variable) into Seasonality
and 0.5-0.34xSIN(?), i.e. (Time, Fraction) 1.75, 0.16, 7.75, 0.84 repeating
0.5-0.34*SIN(Time/1.5) gives me an 8 month cycle around 0.5
I could do it with MOD and a table function but want to do it with SIN
Any help appreciated (I've struggled with SIN for this kind of thing)
Should I have MOD in this equation to create - MODULO (Time,12) for yearly cycle, which I would use with table
or can I do with SIN alone?
Sine wave function for seasonal flue
-
- Junior Member
- Posts: 8
- Joined: Mon Aug 10, 2020 4:54 am
- Vensim version: PLE+
Re: Sine wave function for seasonal flue
You should be able to do it with SIN alone. MODULO won't hurt but isn't needed, since SIN is naturally periodic.
You may find the sample model in the help system useful. It generally installs to C:\Users\Public\Vensim\Models\FunctionExamples
Generally you want amplitude*SIN( (Time-PhaseOffset)/Period*2*Pi ). This will give 0 at Time=PhaseOffset.
A good general approach for this kind of thing is to build a mini-model and play with it in synthesim until it behaves the way you want.
You may find the sample model in the help system useful. It generally installs to C:\Users\Public\Vensim\Models\FunctionExamples
Generally you want amplitude*SIN( (Time-PhaseOffset)/Period*2*Pi ). This will give 0 at Time=PhaseOffset.
A good general approach for this kind of thing is to build a mini-model and play with it in synthesim until it behaves the way you want.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Junior Member
- Posts: 8
- Joined: Mon Aug 10, 2020 4:54 am
- Vensim version: PLE+
Re: Sine wave function for seasonal flue
Thanks Tom
I went with 0.5+0.34*SIN((Time-4.7)/12*(2*3.14159))
I imagine it could simplify or be rearranged
I went with 0.5+0.34*SIN((Time-4.7)/12*(2*3.14159))
I imagine it could simplify or be rearranged
Re: Sine wave function for seasonal flue
That looks right. Generally it's good practice to put the parameters in named variables, so that you can assign and check units.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Junior Member
- Posts: 8
- Joined: Mon Aug 10, 2020 4:54 am
- Vensim version: PLE+
Re: seasonal flue stock bi-flow and MIN
In the attached mdl model (from Erik Pruyt 1806 seasonal flue)
For the seasonal bi-flow the description reads
Background
But not everyone is susceptible to the next seasonal flu virus: people may be immune because
of resistance to a closely related strand or because of the time of the year. The time of the year is
rather important for European flu outbreaks since the virus survives better at lower temperatures
and lower relative humidity –i.e. in winter– and vitamin D produced in human skin exposed to
sunlight reinforces immunity to flu.
Bi-flow equation
Add therefore a flow variable ‘from susceptible to immune and back’ between the susceptible population and the immune population stocks: the susceptible population increases towards the winter and the immune population increases towards the summer.
The flow between these two subpopulations equals the difference between the theoretic immune population and the immune population, divided by the immunity delay. However, the value of this flow cannot be greater than the susceptible population divided by the immunity delay for a net flow from the susceptible to the immune population and cannot be greater than the immune population divided by the immunity delay for a net flow from the immune to the susceptible population. Set the immunity delay equal to the time step.
I used IF THEN ELSE and MIN to represent this
IF THEN ELSE( Susceptible Population>Immune Population, MIN(Susceptible Population/immunity delay, theoretic immune population+Immune Population/immunity delay), MIN(Immune Population/immunity delay, theoretic immune population+Immune Population/immunity delay))
My question is whether the ITE and MIN structure is a correct interpretation. Thanks again. I have not yet run it as is as I need to check overall.
there is a biflow between two stocks of immune population and susceptible population driven by a seasonal fraction (with 1st order delay). For the seasonal bi-flow the description reads
Background
But not everyone is susceptible to the next seasonal flu virus: people may be immune because
of resistance to a closely related strand or because of the time of the year. The time of the year is
rather important for European flu outbreaks since the virus survives better at lower temperatures
and lower relative humidity –i.e. in winter– and vitamin D produced in human skin exposed to
sunlight reinforces immunity to flu.
Bi-flow equation
Add therefore a flow variable ‘from susceptible to immune and back’ between the susceptible population and the immune population stocks: the susceptible population increases towards the winter and the immune population increases towards the summer.
The flow between these two subpopulations equals the difference between the theoretic immune population and the immune population, divided by the immunity delay. However, the value of this flow cannot be greater than the susceptible population divided by the immunity delay for a net flow from the susceptible to the immune population and cannot be greater than the immune population divided by the immunity delay for a net flow from the immune to the susceptible population. Set the immunity delay equal to the time step.
I used IF THEN ELSE and MIN to represent this
IF THEN ELSE( Susceptible Population>Immune Population, MIN(Susceptible Population/immunity delay, theoretic immune population+Immune Population/immunity delay), MIN(Immune Population/immunity delay, theoretic immune population+Immune Population/immunity delay))
My question is whether the ITE and MIN structure is a correct interpretation. Thanks again. I have not yet run it as is as I need to check overall.
Re: Sine wave function for seasonal flue
I would generally be wary of discrete logic from MIN or ITE in a continuous situation like this.
In addition, there's a logical problem with the formulation of 'theoretic immune population' - it allocates 'total population' between the susceptible and immune states. This fails to recognize that part of the population might be in the exposed->recovered states.
I'm not sure it's necessary to fix this, because the susceptible/immune stocks aren't a good representation of seasonality. While there might be a small variation in susceptibility seasonality from things like vitamin D and exercise, the big signal is that people are indoors in close quarters more in winter. That's better modeled by a a multiplier on the transmission rate.
In addition, there's a logical problem with the formulation of 'theoretic immune population' - it allocates 'total population' between the susceptible and immune states. This fails to recognize that part of the population might be in the exposed->recovered states.
I'm not sure it's necessary to fix this, because the susceptible/immune stocks aren't a good representation of seasonality. While there might be a small variation in susceptibility seasonality from things like vitamin D and exercise, the big signal is that people are indoors in close quarters more in winter. That's better modeled by a a multiplier on the transmission rate.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Sine wave function for seasonal flue
Another challenge with the 2 stock formulation is that it imposes a delay between the seasonal peak specified in the Sin function and the actual seasonal peak. This is inconvenient.
Also, the return flow from the Recovered population should really be partitioned into susceptible/immune according to the current fraction immune.
I don't think this is necessary though. You could have something like the following:
- a single stock of potentially susceptible
- susceptible = potentially susceptible * (1-frac immune)
- frac immune = sin wave driver
- infection rate = contact rate*infected fraction*infection rate*Susceptible
It looks like the current infection rate equation might be doubled-up (contact rate*infected fraction*infection rate*Susceptible Population*infection rate*infected fraction*contact rate). A units check should reveal this problem. Defining and checking units catches at least half of all conceptual errors in my experience.
Also, the return flow from the Recovered population should really be partitioned into susceptible/immune according to the current fraction immune.
I don't think this is necessary though. You could have something like the following:
- a single stock of potentially susceptible
- susceptible = potentially susceptible * (1-frac immune)
- frac immune = sin wave driver
- infection rate = contact rate*infected fraction*infection rate*Susceptible
It looks like the current infection rate equation might be doubled-up (contact rate*infected fraction*infection rate*Susceptible Population*infection rate*infected fraction*contact rate). A units check should reveal this problem. Defining and checking units catches at least half of all conceptual errors in my experience.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/