Groups | Search | Server Info | Login | Register


Groups > de.sci.electronics > #353191

Re: random Statistik

From Helmut Schellong <var@schellong.biz>
Newsgroups de.sci.electronics
Subject Re: random Statistik
Date 2024-06-10 17:05 +0200
Message-ID <v474od$1f40q$1@solani.org> (permalink)
References <v41mi1$1ct79$1@solani.org> <6666C63C.5953B476@proton.me>

Show all headers | View raw


Carla Schneider wrote:
> Helmut Schellong wrote:
[...]
> also hier mal ein alternativer Zugang mit chatgpt
> 
> Erster Versuch:
> -----
> write a c program that reads lines from stdin and converts the first two space
> separated items in each line to integers and calls a function fuff with these Integers as parameters
> -----
> 
> 
> Er gibt mir ein Programm das genau das tut:
> ------
[...]
> ------
> 
> 
> Ich wollte das programm jetzt so modifizieren dass er ein Histogramm von num2 macht...
> Aber warum nicht chatgpt noch mehr Arbeit uebertragen:
> 
> --------
> treat num2 as a random variable with the values 1 2 3 4 5 6 and put some
> tests in the orogram that tests if it its distribution
> -------
> 
> Das hat er dann leider falsch verstanden...
> Also habe ich ihm noch geschrieben:
> -------
> do not generate random numbers but test if  the input numbers are random
> -------
> Er gibt mir folgendes Programm:
> --------
> #include <stdio.h>
> #include <stdlib.h>
> 
> // Function prototype
> void fuff(int a, int b);
> 
> int main() {
>      char line[256];
>      int counts[6] = {0}; // Array to count occurrences of 1, 2, 3, 4, 5, 6
>      int totalLines = 0;
> 
>      // Read lines from stdin
>      while (fgets(line, sizeof(line), stdin)) {
>          int num1, num2;
> 
>          // Extract the first two integers
>          if (sscanf(line, "%d %d", &num1, &num2) == 2) {
>              // Check if num2 is within the valid range (1-6)
>              if (num2 >= 1 && num2 <= 6) {
>                  // Increment the count for this num2 value
>                  counts[num2 - 1]++;
>                  
>                  // Call the function fuff with these integers
>                  fuff(num1, num2);
> 
>                  // Increment the total number of lines processed
>                  totalLines++;
>              } else {
>                  printf("Invalid num2 value: %d (must be between 1 and 6)\n", num2);
>              }
>          } else {
>              printf("Invalid input line: %s", line);
>          }
>      }
> 
>      // Print the counts for each num2 value
>      printf("Distribution of num2 values:\n");
>      for (int i = 0; i < 6; i++) {
>          printf("%d: %d times\n", i + 1, counts[i]);
>      }
> 
>      // Calculate the expected count for a uniform distribution
>      double expected = totalLines / 6.0;
>      double chi_squared = 0.0;
> 
>      // Perform the chi-squared test
>      for (int i = 0; i < 6; i++) {
>          double observed = counts[i];
>          chi_squared += (observed - expected) * (observed - expected) / expected;
>      }
> 
>      printf("Chi-squared statistic: %f\n", chi_squared);
> 
>      // Chi-squared critical value for 5 degrees of freedom at 0.05 significance level is 11.070
>      if (chi_squared < 11.070) {
>          printf("The distribution appears to be uniform.\n");
>      } else {
>          printf("The distribution does not appear to be uniform.\n");
>      }
> 
>      return 0;
> }
> 
> // Define the function fuff
> void fuff(int a, int b) {
>      // Example implementation: just print the numbers
>      printf("fuff called with: %d and %d\n", a, b);
> }
> --------
> 
> Der gesamte Chat ist hier einsehbar:
> https://chatgpt.com/share/c513b39e-53eb-49ce-acf5-c7491bf52995
> 
> Die Funktion fuff() habe ich aus dem Programm entfernt und das dann auf deine Zahlen losgelassen:
> 
> 
> cat inputdat.txt | ./wrfltst
> Das ist das Ergebnis:
> -------
> Distribution of num2 values:
> 1: 492 times
> 2: 479 times
> 3: 486 times
> 4: 513 times
> 5: 532 times
> 6: 498 times
> Chi-squared statistic: 3.796000
> The distribution appears to be uniform.
> -------

Wenn ich die Zahlenfolge heuristisch betrachte, finde ich sie auch Okay.
"5 degrees of freedom" finde ich ziemlich großzügig.

> Zum Test habe ich jetzt mal die Eingangszahlen verfaelscht, indem jede 6 6 6 Folge
> zu einer 6 6 1 Folge gemacht wird:
> 
> Also das Programm veraendert:
> -------
> -------
> 
> Und heraus kommt:
> 
> -------
> Distribution of num2 values:
> 1: 515 times
> 2: 479 times
> 3: 486 times
> 4: 513 times
> 5: 532 times
> 6: 475 times
> Chi-squared statistic: 5.360000
> The distribution appears to be uniform.
> --------
> D.h. das merkt er nicht dazu sind 3000 Samples zu wenig.

Ja, 475 unterscheidet sich kaum von 479.
Und 515 ist auch noch im Rahmen.
(Bei mehr Samples gäbe aber auch mehr # times.)

> Wenn ich aber alle 6 6 Folgen durch 6 1 ersetze merkt er es:

Es gibt viel mehr solche Folgen.

> --------
> Distribution of num2 values:
> 1: 557 times
> 2: 479 times
> 3: 486 times
> 4: 513 times
> 5: 532 times
> 6: 433 times
> Chi-squared statistic: 19.136000
> The distribution does not appear to be uniform.
> --------

433 ist nun doch zu niedrig - Ausreißer.
Komplementär ist 557 ebenfalls ein Ausreißer.


-- 
Mit freundlichen Grüßen
Helmut Schellong   var@schellong.biz
http://www.schellong.de/c.htm  http://www.schellong.de/c2x.htm  http://www.schellong.de/c_padding_bits.htm
http://www.schellong.de/htm/bishmnk.htm  http://www.schellong.de/htm/rpar.bish.html  http://www.schellong.de/htm/sieger.bish.html
http://www.schellong.de/htm/audio_proj.htm  http://www.schellong.de/htm/audio_unsinn.htm  http://www.schellong.de/htm/tuner.htm
http://www.schellong.de/htm/string.htm  http://www.schellong.de/htm/string.c.html  http://www.schellong.de/htm/deutsche_bahn.htm
http://www.schellong.de/htm/schaltungen.htm  http://www.schellong.de/htm/math87.htm  http://www.schellong.de/htm/dragon.c.html

Back to de.sci.electronics | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-10 11:24 +0200
  Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-10 17:05 +0200
    Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-11 11:48 +0200
      Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-11 13:00 +0200
        Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-11 15:50 +0200
          Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-11 16:26 +0200
            Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-11 17:51 +0200
      Re: random Statistik Rolf Bombach <rolfnospambombach@invalid.invalid> - 2024-06-11 14:31 +0200
      Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-11 15:45 +0200
      Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-12 05:04 +0200
        Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-12 08:43 +0200
          Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-12 16:36 +0200
            Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-12 21:41 +0200
              Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-13 21:01 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-14 10:13 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-14 12:36 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-15 00:44 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-15 13:05 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-15 15:10 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-16 11:17 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-16 22:59 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-17 12:10 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-17 15:05 +0200
                Re: random Statistik Rolf Bombach <rolfnospambombach@invalid.invalid> - 2024-06-15 20:34 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-15 23:12 +0200
                Re: random Statistik Rolf Bombach <rolfnospambombach@invalid.invalid> - 2024-06-17 15:16 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-17 16:40 +0200
                Re: random Statistik - Windows PowerShell Helmut Schellong <var@schellong.biz> - 2024-06-18 00:17 +0200
            Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-13 09:43 +0200
              Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-13 12:55 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-13 14:05 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-13 16:11 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-13 16:57 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-13 20:47 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-18 10:59 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-18 17:37 +0200

csiph-web