File:Suomen ensimmainen koronavirus aalto kevat 22 ja logistinen kayra ennuste 1.svg

Original file(SVG file, nominally 838 × 491 pixels, file size: 71 KB)

Captions

Captions

First COVID-19 wave in Finland and logistic curve prediction

Summary

edit
Description
Suomi: Suomen kevään 2020 koronavirusaallon kasautuneiden koronavirustapausten määrä verrattuna logistiseen käyrään . Näytetapaukset alkavat tässä 15 päivää ennen epidemian alkua ja näytedata ulottuu 60 päivän ajalle. Tämä on epidemian mitassa melko pitkä aikaväli. Tällä perusteella laskettu logistinen käyrä osuu melko lähelle aallon myöhempien koronavirustapausten todellista määrää.
English: First COVID-19 wave in Finland and logistic curve prediction. Eamined cases span day -15 from first case of epidemy. Base data for predition spans 60 days. Prediction is simple logistic curve.
Date
Source Own work
Author Merikanto

Python code to produce this image

    1. cumulative covid-19 cases and
    2. attempt to predict ca. 2 months old wave with logistic curve
    3. 12.1.2021
    4. 0000.0001

import numpy as np import numpy.random as npr import matplotlib.pyplot as plt from scipy.optimize import leastsq import math as math import pandas as pd import matplotlib.pyplot as plt import matplotlib.ticker as ticker import locale from datetime import datetime, timedelta import matplotlib.dates as mdates from statsmodels.nonparametric.kernel_regression import KernelReg from scipy.signal import savgol_filter

from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,

                              AutoMinorLocator)

def logistic4(x, A, B, C, D):

   """4PL lgoistic equation."""
   return ((A-D)/(1.0+((x/C)**B))) + D

def residuals(p, y, x):

   """Deviations of data from fitted 4PL curve"""
   A,B,C,D = p
   err = y-logistic4(x, A, B, C, D)
   return err

def peval(x, p):

   """Evaluated value at x with current parameters."""
   A,B,C,D = p
   return logistic4(x, A, B, C, D)

dfin = pd.read_csv('https://datahub.io/core/covid-19/r/countries-aggregated.csv', parse_dates=['Date']) countries = ['Finland'] dfin = dfin[dfin['Country'].isin(countries)]

selected_columns = dfin"Date", "Confirmed", "Recovered", "Deaths"

df2 = selected_columns.copy()

df2.to_csv (r'kovadata1.csv', index = True, header=True, sep=';')

df = pd.read_csv(r'kovadata1.csv', delimiter=';')

len1=len(df["Date"]) aktiv2= [None] * len1 for n in range(0,len1-1): aktiv2[n]=0


dates=df['Date'] rekov1=df['Recovered'] konf1=df['Confirmed'] death1=df['Deaths']

dailycases1= [0] * len1 dailydeaths1= [0] * len1

for n in range(1,(len1-1)): dailycases1[n]=konf1[n]-konf1[n-1] if (dailycases1[n]<0): dailycases1[n]=0

for n in range(1,(len1-1)): dailydeaths1[n]=death1[n]-death1[n-1] if (dailydeaths1[n]<0): dailydeaths1[n]=0

locale.setlocale(locale.LC_TIME, "fi_FI") dates_a = [datetime.strptime(d,'%Y-%m-%d').date() for d in dates]

dates_aaa = pd.date_range(dates_a[0], periods=len1, freq='1D') dates_aa=np.array(dates_aaa)

    1. try to predict covid-19 cases
    2. logistic distribution
    1. item to begin specimen

nalku1=20 ## 15 pv ennen 1. tapausta

print ("Alkupvm ", dates_a[nalku1])

konf2=konf1[nalku1:] dates_b=dates_a[nalku1:]

nayte_alku=0

    1. length of specimen to

nayte_loppu=60 ## 2 kk nayte_maara=nayte_loppu-nayte_alku ennuste_alku=0 ennuste_loppu=175 ennuste_maara=ennuste_loppu-ennuste_alku

x = np.linspace(0,nayte_maara,nayte_maara) x2=np.linspace(0,ennuste_maara,ennuste_maara) x3=np.linspace(0,len1,len1) x4=np.linspace(0,len1-nalku1,len1-nalku1)

dates_c=dates_a[nalku1:nalku1+nayte_maara]

dates_ddd=pd.date_range(dates_c[0], periods=ennuste_maara, freq='1D') dates_d=np.array(dates_ddd)

A,B,C,D = 0.5,2.5,8,7.3

  1. y_true = logistic4(x, A, B, C, D)

y_meas=konf2[nayte_alku:nayte_loppu]

y_meas2 = savgol_filter(y_meas, 15, 2)

  1. Initial guess for parameters

p0 = [0, 1, 1, 1]

  1. plsq = leastsq(residuals, p0, args=(y_meas, x))

plsq = leastsq(residuals, p0, args=(y_meas2, x))

y2=peval(x2,plsq[0])

  1. plt.plot(x,y_meas,'bo',x2,y2, "g--", x4,konf2,'r+')

plt.plot(dates_c,y_meas,'ro', dates_aa,konf1,'bx', dates_d,y2, 'g--')

  1. plt.plot(dates_b,y_meas,'bo', x2,y2, "g--",dates_b,konf2,'r+')

plt.title('Kasautuneet koronavirustapaukset verrattuna logistiseen käyrään', fontsize=12)

  1. plt.legend()

plt.legend(['Tutkitut tapaukset \n Jakso: alku 15 pv ennen 1. tapausta, \n siitä eteenpäin 60 päivää', 'Todetut tapaukset', 'Ennuste (logistinen käyrä)'], loc='upper left')

  1. for i, (param, actual, est) in enumerate(zip('ABCD', [A,B,C,D], plsq[0])):
  2. plt.text(10, 3-i*0.5, '%s = %.2f, est(%s) = %.2f' % (param, actual, param, est))

plt.show()

  1. plt.savefig('logistic.svg')

Licensing

edit
I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current17:03, 4 August 2020Thumbnail for version as of 17:03, 4 August 2020838 × 491 (71 KB)Merikanto (talk | contribs)Uploaded own work with UploadWizard

There are no pages that use this file.

Metadata