Groups | Search | Server Info | Login | Register


Groups > de.sci.electronics > #353239

Re: random Statistik

From Carla Schneider <carla_schn@proton.me>
Newsgroups de.sci.electronics
Subject Re: random Statistik
Date 2024-06-11 13:00 +0200
Organization Mausgrau
Message-ID <66682E57.14CFF8CF@proton.me> (permalink)
References <v41mi1$1ct79$1@solani.org> <6666C63C.5953B476@proton.me> <v474od$1f40q$1@solani.org> <66681D76.D3844B5F@proton.me>

Show all headers | View raw


Carla Schneider wrote:
> 
> Helmut Schellong wrote:
> >
> > 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.
> 
> Die 5 Freiheitsgrade beziehen sich auf den chi-quadrat test und kommen von den
> 6 Werten die beim Wuerfeln herauskommen.
> Das wird hier erklaert, ist aber leicht mathematisch belastet:
> 
> https://en.wikipedia.org/wiki/Chi-squared_testt#Pearson's_chi-squared_test
> 

Weil die Summe der 6 Zahlen die vorgegebene Gesamtzahl der Experimente ist,
gibts nur 5  Freiheitsgrade.

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