[npl] / trunk / NationalProblemLibrary / Rochester / setStatistics7MultinomialContingency / ur_stt_7_5.pg Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

View of /trunk/NationalProblemLibrary/Rochester/setStatistics7MultinomialContingency/ur_stt_7_5.pg

Tue May 9 13:07:16 2006 UTC (7 years ago) by jjholt
File size: 2584 byte(s)

1 ## DESCRIPTION
2 ##   Multinomial Contingency
3 ## ENDDESCRIPTION
4
5 ## KEYWORDS('Multinomial', 'Contingency', 'Hypothesis', 'Test Statistic', 'Critical Value', 'Chi Squared', 'Rejection', 'Region')
6 ## Tagged by nhamblet
7
8 ## DBsubject('Statistics')
9 ## DBchapter('Hypothesis Testing')
10 ## DBsection('Multinomial Contingency')
11 ## Date('')
12 ## Author('')
13 ## Institution('Rochester')
14 ## TitleText1('')
15 ## EditionText1('')
16 ## AuthorText1('')
17 ## Section1('')
18 ## Problem1('')
19
20 DOCUMENT();        # This should be the first executable line in the problem.
21
23 "PG.pl",
24 "PGbasicmacros.pl",
25 "PGchoicemacros.pl",
27 "PGgraphmacros.pl",
28 "PGnumericalmacros.pl",
29 "PGstatisticsmacros.pl"
30 );
31
32 TEXT(beginproblem());
33 $showPartialCorrectAnswers = 1; 34 35$alpha = random(.01,.05,.04);
36
37 $totx = 0; 38$toty = 0;
39 $totz = 0; 40 41 for($i=0; $i<3;$i++) {
42   $x[$i] = random(40,80,1);
43   $y[$i] = random(40,80,1);
44   $z[$i] = random(40,80,1);
45   $xyz[$i] = $x[$i]+$y[$i]+$z[$i];
46   $totx =$totx + $x[$i];
47   $toty =$toty + $y[$i];
48   $totz =$totz + $z[$i];
49 }
50 $n =$totx+$toty+$totz;
51
52 for($i=0;$i<3; $i++) { 53$ex[$i] = ($xyz[$i]*$totx)/$n; 54$ey[$i] = ($xyz[$i]*$toty)/$n; 55$ez[$i] = ($xyz[$i]*$totz)/$n; 56 } 57 58$chi = 0;
59 for($i=0;$i<3; $i++) { 60$chi =
61   $chi+(($x[$i]-$ex[$i])**2/$ex[$i])+(($y[$i]-$ey[$i])**2/$ey[$i])+(($z[$i]-$ez[$i])**2/$ez[$i]); 62 } 63 64$rej = chisqrdistr(4,$alpha); 65 66$mc = new_multiple_choice();
67
68 @ans = ("We can reject the null hypothesis that A and B are independent and accept that A and B are
69   dependent. ",
70   "There is not sufficient evidence to reject the null hypothesis that A and B are independent. ");
71
72 if ($chi >$rej ) {$tag = 0;} else {$tag = 1;}
73
74 $mc -> qa('The final conclustion is',$ans[$tag]); 75 76$mc -> extra($ans[1-$tag]);
77
78 BEGIN_TEXT
79 Test the null hypothesis of independence of the two classifications, A and B, of the $$3 \times 3$$
80 contingency table shown below.  Test using $$\alpha = alpha$$ $BR 81 \{begintable(5)\} 82 \{row("$$\$$", "$$B_1$$", "$$B_2$$", "$$B_3$$", "Total")\} 83 \{row("$$A_1$$", "$$x[0]$$", "$$y[0]$$", "$$z[0]$$", "$$xyz[0]$$")\} 84 \{row("$$A_2$$", "$$x[1]$$", "$$y[1]$$", "$$z[1]$$", "$$xyz[1]$$")\} 85 \{row("$$A_3$$", "$$x[2]$$", "$$y[2]$$", "$$z[2]$$", "$$xyz[2]$$")\} 86 \{row("Total", "$$totx$$", "$$toty$$", "$$totz$$", "$$n$$")\} 87 \{endtable()\} 88$PAR
89
90 $$\chi^2 =$$ \{ans_rule(20)\} $PAR 91 rejection region is $$\chi^2 >$$ \{ans_rule(20)\} 92 93 \{$mc->print_q()\}
94 \{$mc->print_a()\} 95 96 END_TEXT 97 ANS(num_cmp($chi));
98 ANS(num_cmp($rej)); 99 ANS(radio_cmp($mc->correct_ans));
100
101
102 ENDDOCUMENT();       # This should be the last executable line in the problem.
103