Histogramm: Unterschied zwischen den Versionen

Aus FLBK-Wiki
Zur Navigation springen Zur Suche springen
 
(10 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 15: Zeile 15:
</gallery>
</gallery>
===Histogramm der Binomialverteilung===
===Histogramm der Binomialverteilung===
html>
Die folgende interaktive Grafik zeigt das Histogramm der [[Binomialverteilung|<math>B(n;p;k)</math>]]-verteilten [[Zufallsvariable|Zufallsvariablen]] <math>X</math> sowie eine grafische Darstellung der [[Binomialverteilung#Sigmaregeln|Sigmaregeln]]. Dabei gilt
<head>
*<math>P\left(\mu-\sigma\leq X\leq \mu+\sigma\right)=P(|X-\mu|\leq \sigma)\approx0,683</math>, d. h. die Werte der Zufallsvariablen <math>X</math> liegen mit einer Wahrscheinlichkeit von ungefähr 68,3 % im Intervall <math>[\mu-\sigma;\mu+\sigma]</math>.
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsxgraph/1.4.6/jsxgraphcore.js"></script>
*<math>P\left(\mu-2\sigma\leq X\leq \mu+2\sigma\right)=P(|X-\mu|\leq 2\sigma)\approx0,955</math>, d. h. die Werte der Zufallsvariablen <math>X</math> liegen mit einer Wahrscheinlichkeit von ungefähr 95,5 % im Intervall <math>[\mu-2\sigma;\mu+2\sigma]</math>. 
*<math>P\left(\mu-3\sigma\leq X\leq\mu+3\sigma\right)=P(|X-\mu|\leq 3\sigma)\approx0,997</math> mit <math>\sigma \geq 3</math> , d. h. die Werte der Zufallsvariablen <math>X</math> liegen mit einer Wahrscheinlichkeit von ungefähr 99,7 % im Intervall <math>[\mu-3\sigma;\mu+3\sigma]</math>. Die Wahrscheinlichkeit <math>P(X \leq k)</math> wird berechnet, indem die Höhen aller Säulen, die zu Werten gehören, die kleiner oder gleich <math>k</math> sind, addiert werden.
<html>
<div id="binomBoard" style="width: 90vw; max-width: 600px; height: 60vw; max-height: 500px; margin-top:20px;"></div>
<script type="text/javascript" src="https://jsxgraph.org/distrib/jsxgraphcore.js"></script>


</head>
<script type="text/javascript">
<body>
    JXG.Options.text.useMathJax = true;
    <div id="box2" style="width: 90vw; max-width: 400px; height: 60vw; max-height: 300px; margin-top:20px;"></div>
    // Board initialisieren
    <script type="text/javascript">
    var brd = JXG.JSXGraph.initBoard('binomBoard', {
        JXG.Options.text.useMathJax = true;      
        axis: true,
        // JSXGraph-Board erstellen
        boundingbox: [-6.5, 0.2, 50, -0.05],
        var board = JXG.JSXGraph.initBoard('box2', {
        showCopyright: false,
            boundingbox: [-5, 5, 10, -5], // Angepasste Boundingbox für die Skalierung
        showNavigation: false,
            axis: true,
        defaultAxes: {
            showCopyright: false,
            x: {
            showNavigation: true,
                withLabel: true,
            grid: true, // Gitternetz aktivieren
                name: 'k',
            defaultAxes: {
                label: {
                x: {
                    position: 'rt',
                    withLabel: true,
                    offset: [5, 15],
                    name: '\\[t\\]',
                    fontSize: 12
                    label: {
                }
                        position: 'rt',
            },
                        offset: [-5, 20],
            y: {
                        fontSize: 14,
                withLabel: true,
                        anchorX: 'right'
                name: 'P(X = k)',
                    },
                label: {
                    ticks: {
                    position: 'rt',
                        ticksDistance: 1,
                    offset: [-45, -5],
                        minorTicks: 0
                    fontSize: 12
                    }
                },
                y: {
                    withLabel: true,
                    name: '\\[f(t)\\]',
                    label: {
                        position: 'rt',
                        offset: [5, 20],
                        fontSize: 14,
                        anchorY: 'right'
                    },
                    ticks: {
                        ticksDistance: 1,
                        minorTicks: 0
                    }
                 }
                 }
             }
             }
         });
         }
    });
 
    // --- Slider ---
    // n-Slider
    var nSlider = brd.create('slider', [[5, 0.185], [40, 0.185], [50, 150, 200]], {
        name: 'n',
        snapWidth: 1,
        fillColor: 'white',
        strokeColor: '#3498db',
        highlightStrokeColor: '#3498db',
        baseline: {strokeColor: '#3498db', strokeWidth: 2},
        highline: {strokeColor: '#2980b9', strokeWidth: 3}
    });
 
    // p-Slider
    var pSlider = brd.create('slider', [[5, 0.175], [40, 0.175], [0, 0.1, 0.2]], {
        name: 'p',
        snapWidth: 0.01,
        fillColor: 'white',
        strokeColor: '#e74c3c',
        highlightStrokeColor: '#e74c3c',
        baseline: {strokeColor: '#e74c3c', strokeWidth: 2},
        highline: {strokeColor: '#c0392b', strokeWidth: 3}
    });
 
    // k-Slider (neu)
    var kSlider = brd.create('slider', [[5, 0.165], [40, 0.165], [0, 10, 50]], {
        name: 'k',
        snapWidth: 1,
        fillColor: 'white',
        strokeColor: '#2ecc71',
        highlightStrokeColor: '#2ecc71',
        baseline: {strokeColor: '#2ecc71', strokeWidth: 2},
        highline: {strokeColor: '#27ae60', strokeWidth: 3}
    });
 
    // --- Hilfsfunktionen ---
    function binomProb(n, k, p) {
        var x, p1 = 1,
        p2 = 1,
        coeff = 1;
        for (x = n - k + 1; x < n + 1; x++) {
            coeff *= x;
        }
        for (x = 1; x < k + 1; x++) {
            coeff /= x;
        }
        for (x = 0; x < k; x++) {
            p1 *= p;
        }
        for (x = 0; x < n - k; x++) {
            p2 *= (1 - p);
        }
        return coeff * p1 * p2;
    }
 
    // Berechne Erwartungswert und Standardabweichung
    function getMu() {
        var n = Math.round(nSlider.Value());
        var p = pSlider.Value();
        return n * p;
    }
 
    function getSigma() {
        var n = Math.round(nSlider.Value());
        var p = pSlider.Value();
        return Math.sqrt(n * p * (1 - p));
    }
 
    // --- Balken vorbereiten ---
    var maxBars = 200;
    var bars = [];
    for (let k = 0; k <= maxBars; k++) {
        let heightF = function() {
            var n = Math.round(nSlider.Value());
            var p = pSlider.Value();
            if (k > n || k > 75) return 0;
            return binomProb(n, k, p);
        };


         // Funktion erstellen
         // Alle Balken in orange
         var c1 = board.create('functiongraph', [function(t) {
         let colorF = function() {
             return (Math.pow(t, 5) / 24 - Math.pow(t, 3) / 2 + t);
             return '#ffaa44';
         }]);
         };


        // Integral erstellen
         var poly = brd.create('polygon', [
         var i1 = board.create('integral', [
             [k - 0.5, 0],
             [-2.0, 2.0], c1
            [k - 0.5, heightF],
            [k + 0.5, heightF],
            [k + 0.5, 0]
         ], {
         ], {
             withLabel: true,
             withLines: true,
             label: {
             borders: {strokeWidth: 1, strokeColor: '#cc8800'},
                fontSize: 14,
            fillOpacity: 0.7,
                offset: [0, 50],
            fillColor: colorF,
                digits: 4,
             vertices: {visible: false},
                intl: {
             visible: function() {
                    enabled: false,
              if (k <= Math.round(nSlider.Value())) {
                    options: {}
                  return k <= 75;
                }
              }
            },
              return false;
             baseLeft: {   // Start point
                visible: true,
                fixed: false,
                withLabel: true,
                name: 'a'
            },
             baseRight: {   // End point
                visible: true,
                fixed: false,
                withLabel: true,
                name: 'b'
             }
             }
         });
         });


         // Integral-Label anpassen
         bars.push(poly);
         i1.label.setText(() => {
    }
            const a = i1.baseLeft.X().toFixed(2); // Untere Grenze
 
            const b = i1.baseRight.X().toFixed(2); // Obere Grenze
    // --- Sigmaregeln Visualisierung ---
            const value = i1.Value().toFixed(4); // Wert des Integrals
    // Vertikale Linien für μ, μ±σ, μ±2σ, μ±3σ (nur unterhalb der x-Achse)
            return `\\[\\int_{${a}}^{${b}} f(t) \\, dt = ${value}\\]`;
    var muLine = brd.create('segment', [
         });
         function() { return [getMu(), 0]; },
        function() { return [getMu(), -0.005]; }
    ], {
        strokeColor: '#0000ff',
        strokeWidth: 2,
        dash: 1
    });
 
    var muPlusSigmaLine = brd.create('segment', [
        function() { return [getMu() + getSigma(), 0]; },
        function() { return [getMu() + getSigma(), -0.015]; }
    ], {
        strokeColor: '#007700',
        strokeWidth: 2,
        dash: 1
    });
 
    var muMinusSigmaLine = brd.create('segment', [
        function() { return [getMu() - getSigma(), 0]; },
        function() { return [getMu() - getSigma(), -0.015]; }
    ], {
        strokeColor: '#007700',
        strokeWidth: 2,
        dash: 1
    });
 
    var muPlus2SigmaLine = brd.create('segment', [
        function() { return [getMu() + 2 * getSigma(), 0]; },
        function() { return [getMu() + 2 * getSigma(), -0.025]; }
    ], {
        strokeColor: '#aa5500',
        strokeWidth: 2,
        dash: 1
    });
 
    var muMinus2SigmaLine = brd.create('segment', [
        function() { return [getMu() - 2 * getSigma(), 0]; },
        function() { return [getMu() - 2 * getSigma(), -0.025]; }
    ], {
        strokeColor: '#aa5500',
        strokeWidth: 2,
        dash: 1
    });
 
    var muPlus3SigmaLine = brd.create('segment', [
        function() { return [getMu() + 3 * getSigma(), 0]; },
        function() { return [getMu() + 3 * getSigma(), -0.035]; }
    ], {
        strokeColor: '#aa0000',
        strokeWidth: 2,
        dash: 1
    });
 
    var muMinus3SigmaLine = brd.create('segment', [
        function() { return [getMu() - 3 * getSigma(), 0]; },
        function() { return [getMu() - 3 * getSigma(), -0.035]; }
    ], {
        strokeColor: '#aa0000',
        strokeWidth: 2,
        dash: 1
    });
 
    // Beschriftungen für die Sigmaregeln (nach unten versetzt)
    brd.create('text', [function() { return getMu(); }, -0.0075, 'μ'], {
        anchorX: 'middle',
        fontSize: 12,
        strokeColor: '#0000ff'
    });
   
    brd.create('text', [function() { return getMu() + getSigma(); }, -0.0175, 'μ+σ'], {
        anchorX: 'middle',
        fontSize: 12,
        strokeColor: '#007700'
    });
   
    brd.create('text', [function() { return getMu() - getSigma(); }, -0.0175, 'μ-σ'], {
        anchorX: 'middle',
        fontSize: 12,
        strokeColor: '#007700'
    });
   
    brd.create('text', [function() { return getMu() + 2 * getSigma(); }, -0.0275, 'μ+2σ'], {
        anchorX: 'middle',
        fontSize: 12,
        strokeColor: '#aa5500'
    });
   
    brd.create('text', [function() { return getMu() - 2 * getSigma(); }, -0.0275, 'μ-2σ'], {
        anchorX: 'middle',
        fontSize: 12,
        strokeColor: '#aa5500'
    });
   
    brd.create('text', [function() { return getMu() + 3 * getSigma(); }, -0.0375, 'μ+3σ'], {
        anchorX: 'middle',
        fontSize: 12,
        strokeColor: '#aa0000'
    });
   
    brd.create('text', [function() { return getMu() - 3 * getSigma(); }, -0.0375, 'μ-3σ'], {
        anchorX: 'middle',
        fontSize: 12,
        strokeColor: '#aa0000'
    });
 
    // Anzeige von P(X=k), μ und σ (oben rechts)
    brd.create('text', [30, 0.15, function() {
        var n = Math.round(nSlider.Value());
        var p = pSlider.Value();
        var k = Math.round(kSlider.Value());
        return 'P(X = ' + k + ') = ' + binomProb(n, k, p).toFixed(6);
    }], {
        anchorX: 'left',
        fontSize: 12,
        fixed: true
    });
   
    brd.create('text', [30, 0.14, function() { return 'μ = n·p=' + getMu().toFixed(2); }], {
        anchorX: 'left',
        fontSize: 12,
        fixed: true
    });
   
    brd.create('text', [30, 0.13, function() { return 'σ = √(n·p·(1-p))=' + getSigma().toFixed(2); }], {
        anchorX: 'left',
        fontSize: 12,
        fixed: true
    });
 
brd.create('text', [30, 0.12, function() { return 'P(|X-' + getMu().toFixed(2) + '|\u2264' + getSigma().toFixed(2) + ') \u2248 0,683';}], {
        anchorX: 'left',
        fontSize: 12,
        fixed: true,
        strokeColor: '#007700'
    });
 
brd.create('text', [30, 0.11, function() { return 'P(|X-' + getMu().toFixed(2) + '|\u2264 2·' + getSigma().toFixed(2) + ') \u2248 0,955';}], {
        anchorX: 'left',
        fontSize: 12,
        fixed: true,
         strokeColor: '#aa5500'
    });


        // Beschriftung der Funktion mit f
brd.create('text', [30, 0.1, function() { return 'P(|X-' + getMu().toFixed(2) + '|\u2264 3·' + getSigma().toFixed(2) + ') \u2248 0,997';}], {
        board.create('text', [3.5, 3, '\\[f\\]'], {
        anchorX: 'left',
            fontSize: 14,
        fontSize: 12,
            fixed: true,
        fixed: true,
            anchorX: 'left',
        strokeColor: '#aa0000'
            anchorY: 'bottom',
    });
            color: 'blue'
</script>
        });
    </script>
</body>
</html>
</html>
<html><iframe width="280" height="157.5" src="https://www.youtube.com/embed/Lc_R0vBSKHw?si=V72WfOUjhQRQlrN9" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></html>
<html><iframe width="280" height="157.5" src="https://www.youtube.com/embed/Lc_R0vBSKHw?si=V72WfOUjhQRQlrN9" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></html>


[[Kategorie:Wahrscheinlichkeitsrechnung]]
[[Kategorie:Wahrscheinlichkeitsrechnung]]
[[Kategorie:FHR_WuV_Mathe]]
[[Kategorie:FHR_WuV_Mathe]]
[[Kategorie:AHR_WuV_Mathe_GK]]

Aktuelle Version vom 31. August 2025, 12:24 Uhr

Die Wahrscheinlichkeitsverteilung eines Zufallsexperiments wird durch ein Histogramm visualisiert.

Definition

Es sei die Wahrscheinlichkeitsverteilung zu einem Zufallsexperiment gegeben. Ein Säulendiagramm, bei dem der Flächeninhalt einer Säule die Wahrscheinlichkeit des dazugehörigen Ergebnisses ist, heißt Histogramm. Die Höhe einer Säule wird als Wahrscheinlichkeitsdichte [math]\displaystyle{ \rho }[/math] (roh) bezeichnet. Die Breite einer Säule gibt an, wie viele Ergebnisse durch die Säule repräsentiert werden. Somit ergibt die Wahrscheinlichkeitsdichte [math]\displaystyle{ \rho_K }[/math] multipliziert mit der Breite [math]\displaystyle{ b_K }[/math] die Wahrscheinlichkeit des Ereignisses [math]\displaystyle{ K }[/math]; [math]\displaystyle{ P(K)=\rho_K\cdot b_K }[/math].

Beispiel

Histogramm zum dreifachen Münzwurf

Die folgenden beiden Histogramme visualisieren die Wahrscheinlichkeiten zum Zufallsexperiment des dreifachen Münzwurfs.

Histogramm der Binomialverteilung

Die folgende interaktive Grafik zeigt das Histogramm der [math]\displaystyle{ B(n;p;k) }[/math]-verteilten Zufallsvariablen [math]\displaystyle{ X }[/math] sowie eine grafische Darstellung der Sigmaregeln. Dabei gilt

  • [math]\displaystyle{ P\left(\mu-\sigma\leq X\leq \mu+\sigma\right)=P(|X-\mu|\leq \sigma)\approx0,683 }[/math], d. h. die Werte der Zufallsvariablen [math]\displaystyle{ X }[/math] liegen mit einer Wahrscheinlichkeit von ungefähr 68,3 % im Intervall [math]\displaystyle{ [\mu-\sigma;\mu+\sigma] }[/math].
  • [math]\displaystyle{ P\left(\mu-2\sigma\leq X\leq \mu+2\sigma\right)=P(|X-\mu|\leq 2\sigma)\approx0,955 }[/math], d. h. die Werte der Zufallsvariablen [math]\displaystyle{ X }[/math] liegen mit einer Wahrscheinlichkeit von ungefähr 95,5 % im Intervall [math]\displaystyle{ [\mu-2\sigma;\mu+2\sigma] }[/math].
  • [math]\displaystyle{ P\left(\mu-3\sigma\leq X\leq\mu+3\sigma\right)=P(|X-\mu|\leq 3\sigma)\approx0,997 }[/math] mit [math]\displaystyle{ \sigma \geq 3 }[/math] , d. h. die Werte der Zufallsvariablen [math]\displaystyle{ X }[/math] liegen mit einer Wahrscheinlichkeit von ungefähr 99,7 % im Intervall [math]\displaystyle{ [\mu-3\sigma;\mu+3\sigma] }[/math]. Die Wahrscheinlichkeit [math]\displaystyle{ P(X \leq k) }[/math] wird berechnet, indem die Höhen aller Säulen, die zu Werten gehören, die kleiner oder gleich [math]\displaystyle{ k }[/math] sind, addiert werden.