In this exercise we will examine the predictability (short-time autocorrelations) of political polls. If the scaling of the time-averaged mean squared displacement (TAMSD) is steeper than linear, it implies correlated dynamics, linear implies uncorrelated (random walk - not predictable) and slower-than-linear implies anti-correlations.
We use polling data for the approval ratings of Angela Merkel during the time she was chancellor of Germany. It can be found at the website of Forschungsgruppe Wahlen https://www.forschungsgruppe.de/Umfragen/Politbarometer/Langzeitentwicklung_-_Themen_im_Ueberblick/Politik-Archiv_1/Legislatur_2017_-_2021/Arbeit_Merkel_2021.xlsx. Import the data using the following python code with the URL as filename
from io import BytesIO
import openpyxl
import urllib.request
datasource = urllib.request.urlopen( filename ).read()
file = openpyxl.load_workbook(filename = BytesIO(datasource), data_only=True)
tabelle = file["Tabelle1"]
allCells = np.array([[cell.value for cell in row] for row in tabelle.iter_rows()])
data = allCells[ 9:296 , 1:4 ] #cells in which the data can be found
x = data[:,1]
Alternatively, you can save the data in a .txt
-file and use the function np.loadtxt
to import it.