This program shows you the use of the four field test. One of the simple tests from statistics , to compare two groups. (For example women and men smoking or not smoking. ) To get the program going , you need 5 commandbuttons, 1 textarea, 5 textboxes, 4 textlabels and 1 togglebutton.
How does that look alike ? See it here ( in German )
The Code:
' ' Gambas class file PUBLIC SUB Button1_Click() ME.Close END PUBLIC SUB Button2_Click() textbox1.Text = "" textbox2.Text = "" textbox3.Text = "" textbox4.Text = "" textarea2.Text = "" END PUBLIC SUB Button3_Click() ' Rem Fehlerroutine bei leeren Feldern einbauen DIM N1 AS Float DIM N2 AS Float DIM M1 AS Float DIM M2 AS Float DIM R1 AS Float DIM NN AS Float DIM N AS Float DIM E1 AS Float DIM MM AS Float DIM E2 AS Float DIM R2 AS Float DIM E3 AS Float DIM E4 AS Float DIM D1 AS Float DIM C1 AS Float DIM D2 AS Float DIM C2 AS Float DIM D3 AS Float DIM C3 AS Float DIM D4 AS Float DIM C4 AS Float DIM C AS Float DIM S AS Float DIM P AS Float textarea2.Text = "" N1 = Val(textbox1.Text) N2 = Val(textbox2.Text) M1 = Val(textbox3.Text) M2 = Val(textbox4.Text) 'ERWARTUNGSWERT EN1 R1 = N1 + M1 NN = N1 + N2 N = N1 + N2 + M1 + M2 E1 = R1 * NN / N textarea2.Text = textarea2.Text & "Erwartungswert E1 =" & Str(E1) & Chr(13) & Chr(10) 'Rem ERWARTUNGSWERT EN2 MM = M1 + M2 E2 = R1 * MM / N textarea2.Text = textarea2.Text & "Erwartungswert E2 =" & Str(E2) & Chr(10) & Chr(13) 'Rem ERWARTUNGSWERT EN3 R2 = N2 + M2 E3 = R2 * NN / N textarea2.Text = textarea2.Text & "Erwartungswert E3 =" & Str(E3) & Chr(13) & Chr(10) 'Rem ERWARTUNGSWERT EN4 E4 = R2 * MM / N textarea2.Text = textarea2.Text & "Erwartungswert E4 =" & Str(E4) & Chr(13) & Chr(10) ' Rem PROBE=0? S = E1 + E2 + E3 + E4 P = S - N textarea2.Text = textarea2.Text & "Probe" & Str(S) & "-" & Str(N) & "=" & Str(P) & "=0?" & Chr(13) & Chr(10) ' Rem CHI^2 D1 = (N1 - E1) ^ 2 C1 = D1 / E1 D2 = (M1 - E2) ^ 2 C2 = D2 / E2 D3 = (N2 - E3) ^ 2 C3 = D3 / E3 D4 = (M2 - E4) ^ 2 C4 = D4 / E4 C = C1 + C2 + C3 + C4 textarea2.Text = textarea2.Text & "CHI-QUADRAT=" & Str(C) & Chr(13) & Chr(10) IF C - 3.841 > 0 THEN textarea2.Text = textarea2.Text & "Bei P=0.05 besteht ein signifikanter Unterschied" IF C - 3.841 <= 0 THEN textarea2.Text = textarea2.Text & "Bei P=0.05 besteht kein signifikanter Unterschied " END PUBLIC SUB Button4_Click() Textbox1.text = "20" Textbox2.text = "70" Textbox3.text = "70" Textbox4.text = "25" Textarea2.text = "" END PUBLIC SUB ToggleButton1_Click() DIM Help AS String IF TextArea1.Visible = FALSE THEN ToggleButton1.Text = "Info weglöschen" Help = "R.Hoffmann " & Chr(13) & Chr(10) Help = Help & "http://www.madeasy.de" & Chr(13) & Chr(10) Help = Help & "rho54@gmx.de" TextArea1.Visible = TRUE TextArea1.text = Help ELSE TextArea1.Visible = FALSE ToggleButton1.Text = "Info anschauen" ENDIF END PUBLIC SUB Button5_Click() textarea2.Text = "Der Vierfeldertest dient dazu, " textarea2.Text = textarea2.Text & "die Haeufigkeit eines Merkmals in zwei" & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "unabhaengigen Gruppen zu vergleichen " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Beispiel: " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Man befragt 50 Frauen ( GRUPPE 1) , ob sie rauchen oder nicht. " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Dasselbe macht man mit 50 Maennern ( GRUPPE 2). " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Man erhaelt das Ergebnis :" & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "FRAUEN : 25 Raucher 25 Nichtraucher " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "MAENNER: 30 Raucher 20 Nichtraucher " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Kann man anhand dieser repraesentativen Befragung schon sagen, " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "ob es mehr Nichtraucher unter den Frauen gibt ?" & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Diese Frage beantwortet der Vierfelder Test." & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Dazu muss man die Werte beider Gruppen eingeben und " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "eine Irrtumswahrscheinlichkeit waehlen. ( Hier p = 0.05 )" & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Wollen Sie das Ergebnis testen ? " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Dann druecken Sie auf die Taste SIGNIFIKANZBERECHNUNG !" & Chr$(13) & Chr$(10) textbox1.Text = "25" textbox2.Text = "25" textbox3.Text = "30" textbox4.Text = "20" ' Rem G11 = 25: G12 = 25 ' Rem G21 = 30: G22 = 20 END PUBLIC SUB Button6_Click() textarea2.Text = "" textarea2.Text = "Bei P=0.05 besteht kein signifikanter Unterschied. " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Zwei Schlussfolgerungen kann man aus diesem Ergebnis ziehen : " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "---------------------------------------------------------- " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Entweder es gibt tatsaechlich keinen Unterschied ODER" & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "die Stichproben aus beiden Gruppen waren zu klein" & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Probieren Sie dieselben Werte, nur alle mal 10 genommen." & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "FRAUEN : 250 Raucher 250 Nichtraucher " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "MAENNER: 300 Raucher 200 Nichtraucher " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "----------------------------------------------------------" & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Wollen Sie noch einmal testen ? " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Dann druecken Sie auf die Taste SIGNIFIKANZBERECHNUNG !" & Chr$(13) & Chr$(10) textbox1.Text = "250" textbox2.Text = "250" textbox3.Text = "300" textbox4.Text = "200" textarea2.Text = textarea2.Text & "Dann sieht das Ergebnis anders aus. " & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "Wenn man kleine aber signifikante Unterschiede finden will," & Chr$(13) & Chr$(10) textarea2.Text = textarea2.Text & "braucht man also grosse Zahlen in den Stichproben." END
-- ReinerHoffmann - 22 Sep 2004