From 402383f289e3a5193b4403891bf713cea39d1a1a Mon Sep 17 00:00:00 2001 From: dev weycloud Date: Sun, 17 Oct 2021 08:20:44 +0200 Subject: [PATCH] stat2 vl3 --- Sonstiges/STAT2/vl3-standardfehler.csv | 6 +++ Sonstiges/STAT2/vl3-standardfehler.py | 75 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 Sonstiges/STAT2/vl3-standardfehler.csv create mode 100644 Sonstiges/STAT2/vl3-standardfehler.py diff --git a/Sonstiges/STAT2/vl3-standardfehler.csv b/Sonstiges/STAT2/vl3-standardfehler.csv new file mode 100644 index 0000000..de5f97a --- /dev/null +++ b/Sonstiges/STAT2/vl3-standardfehler.csv @@ -0,0 +1,6 @@ +x,freq +1,3 +2,3 +3,5 +4,3 +5,6 \ No newline at end of file diff --git a/Sonstiges/STAT2/vl3-standardfehler.py b/Sonstiges/STAT2/vl3-standardfehler.py new file mode 100644 index 0000000..04a9585 --- /dev/null +++ b/Sonstiges/STAT2/vl3-standardfehler.py @@ -0,0 +1,75 @@ +import pandas as pd +import numpy as np + +df = pd.read_csv('/home/pi/Documents/Code/Python/ProgrammierungUndDatenanalyse/Sonstiges/STAT2/vl3-standardfehler.csv') + +# Dataframe +print(df) + +print(df.sum()) + +sums = df.sum() +print('Summierte Häufigkeit: ', sums['freq']) + + +# Calculate Mean, respecting frequencies +rowSum = 0 +for index, row in df.iterrows(): + rowSum = rowSum + row.x * row.freq +mean = rowSum / sums.freq +print("mean: ", mean) + +# Geschätzte Populationsvarianz, unter Beachtung der Häufigkeiten +# Sample Variance: ^σ² = (1 / n - 1) * Σ(freq*(x - mean)²) +variancePart1 = (1 / (sums.freq - 1)) +summeQuadrierteAbweichungen = 0 +for index, row in df.iterrows(): + summeQuadrierteAbweichungen = summeQuadrierteAbweichungen + (row.freq * (row.x - mean)**2) + print(row['x'], row['freq'], 'summe²abweichungen: ', summeQuadrierteAbweichungen) +variance = variancePart1 * summeQuadrierteAbweichungen +print("variance: ", variance) + +standardDev = variance**(1/2) # √n = n^1/2 +print("Standardabweichung: ", standardDev) + +standardfehler = standardDev / sums.freq**(1/2) # √n = n^1/2 +print("Standardfehler des Mittelwerts: ", standardfehler) + +# Mittelwertsverteilung bei 2 Würfeln +print() +import random +i=0 +sum=0 +# Augen: (0,1,)2,3,4,5,6,7,8,9,10,11,12 Häufigkeitsliste: +freqList = [0,0,0,0,0,0,0,0,0,0,0,0,0] +while i < 1000: + tempSum = 0 + wuerfel1 = random.randrange(1,7) # 1. Würfel {1,2,3,4,5,6} + wuerfel2 = random.randrange(1,7) # 2. Würfel {1,2,3,4,5,6} + tempSum = tempSum + wuerfel1 + wuerfel2 + if tempSum == 2: + freqList[2] = freqList[2] + 1 + elif tempSum == 3: + freqList[3] = freqList[3] + 1 + elif tempSum == 4: + freqList[4] = freqList[4] + 1 + elif tempSum == 5: + freqList[5] = freqList[5] + 1 + elif tempSum == 6: + freqList[6] = freqList[6] + 1 + elif tempSum == 7: + freqList[7] = freqList[7] + 1 + elif tempSum == 8: + freqList[8] = freqList[8] + 1 + elif tempSum == 9: + freqList[9] = freqList[9] + 1 + elif tempSum == 10: + freqList[10] = freqList[10] + 1 + elif tempSum == 11: + freqList[11] = freqList[11] + 1 + elif tempSum == 12: + freqList[12] = freqList[12] + 1 + sum = sum + tempSum + i = i+1 +print("Mittelwert bei 2 Würfeln: ", sum / 1000) +print(freqList) \ No newline at end of file