Logistic curve fitting in epidemiology: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (added Arturo) |
(Added XPL0 example.) |
||
Line 1,411: | Line 1,411: | ||
<pre> |
<pre> |
||
r = 0.1123021757, R0 = 3.84827928 |
r = 0.1123021757, R0 = 3.84827928 |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
{{trans|C}} |
|||
<syntaxhighlight lang "XPL0">def K = 7.8e9; |
|||
def N0 = 27.; |
|||
real Actual; |
|||
int ActualSize; |
|||
func real Func(R); |
|||
real R; |
|||
real Sq, Eri, Guess, Diff; |
|||
int I; |
|||
[Sq:= 0.; |
|||
for I:= 0 to ActualSize-1 do |
|||
[Eri:= Exp(R * float(I)); |
|||
Guess:= N0 * Eri / (1. + N0 * (Eri-1.) / K); |
|||
Diff:= Guess - Actual(I); |
|||
Sq:= Sq + Diff*Diff; |
|||
]; |
|||
return Sq; |
|||
]; |
|||
func real Solve(Guess, Epsilon); |
|||
real Guess, Epsilon; |
|||
real Delta, F0, Factor, NF; |
|||
[Delta:= if Guess # 0. then Guess else 1.; |
|||
F0:= Func(Guess); |
|||
Factor:= 2.; |
|||
while Delta > Epsilon and Guess # Guess-Delta do |
|||
[NF:= Func(Guess - Delta); |
|||
if NF < F0 then |
|||
[F0:= NF; |
|||
Guess:= Guess - Delta; |
|||
] |
|||
else |
|||
[NF:= Func(Guess + Delta); |
|||
if NF < F0 then |
|||
[F0:= NF; |
|||
Guess:= Guess + Delta; |
|||
] |
|||
else Factor:= 0.5; |
|||
]; |
|||
Delta:= Delta * Factor; |
|||
]; |
|||
return Guess; |
|||
]; |
|||
real R, R0; |
|||
[Actual:= [ |
|||
27., 27., 27., 44., 44., 59., 59., 59., 59., 59., 59., 59., 59., 60., 60., |
|||
61., 61., 66., 83., 219., 239., 392., 534., 631., 897., 1350., 2023., 2820., |
|||
4587., 6067., 7823., 9826., 11946., 14554., 17372., 20615., 24522., 28273., |
|||
31491., 34933., 37552., 40540., 43105., 45177., 60328., 64543., 67103., |
|||
69265., 71332., 73327., 75191., 75723., 76719., 77804., 78812., 79339., |
|||
80132., 80995., 82101., 83365., 85203., 87024., 89068., 90664., 93077., |
|||
95316., 98172., 102133., 105824., 109695., 114232., 118610., 125497., |
|||
133852., 143227., 151367., 167418., 180096., 194836., 213150., 242364., |
|||
271106., 305117., 338133., 377918., 416845., 468049., 527767., 591704., |
|||
656866., 715353., 777796., 851308., 928436., 1000249., 1082054., 1174652.]; |
|||
ActualSize:= 97; |
|||
R:= Solve(0.5, 0.0); |
|||
R0:= Exp(12.*R); |
|||
Text(0, "R = "); RlOut(0, R); CrLf(0); |
|||
Text(0, "R0 = "); RlOut(0, R0); CrLf(0); |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
R = 0.11230 |
|||
R0 = 3.84828 |
|||
</pre> |
</pre> |