Allow hyphens in {sub}command names.
[pspp-builds.git] / tests / command / npar-binomial.sh
1 #!/bin/sh
2
3 # This program tests the BINOMIAL subcommand of the NPAR TESTS command.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_srcdir and top_builddir  are absolute
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 top_srcdir=`cd $top_srcdir; pwd`
12 top_builddir=`cd $top_builddir; pwd`
13
14 PSPP=$top_builddir/src/ui/terminal/pspp
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 LANG=C
20 export LANG
21
22
23 cleanup()
24 {
25      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
26         echo "NOT cleaning $TEMPDIR"
27         return ; 
28      fi
29      cd /
30      rm -rf $TEMPDIR
31 }
32
33
34 fail()
35 {
36     echo $activity
37     echo FAILED
38     cleanup;
39     exit 1;
40 }
41
42
43 no_result()
44 {
45     echo $activity
46     echo NO RESULT;
47     cleanup;
48     exit 2;
49 }
50
51 pass()
52 {
53     cleanup;
54     exit 0;
55 }
56
57 mkdir -p $TEMPDIR
58
59 cd $TEMPDIR
60
61
62 # Tests for exact calculations
63 activity="create file 1"
64 cat <<EOF > $TESTFILE
65 ECHO 'P < 0.5; N1/N2 < 1' .
66
67 NEW FILE.
68
69 DATA LIST LIST NOTABLE /x * w *.
70 BEGIN DATA.
71 1   6
72 2   15
73 END DATA.
74
75 WEIGHT BY w.
76
77 NPAR TESTS
78         /BINOMIAL(0.3) = x
79         .
80
81
82 ECHO 'P < 0.5; N1/N2 > 1' .
83
84 NEW FILE.
85
86 DATA LIST LIST NOTABLE /x * w *.
87 BEGIN DATA.
88 1   7
89 2   6
90 END DATA.
91
92 WEIGHT BY w.
93
94 NPAR TESTS
95         /BINOMIAL(0.4) = x
96         .
97
98
99
100 ECHO 'P < 0.5; N1/N2 = 1' .
101
102 NEW FILE.
103
104 DATA LIST LIST NOTABLE /x * w *.
105 BEGIN DATA.
106 1   8
107 2   8
108 END DATA.
109
110 WEIGHT BY w.
111
112 NPAR TESTS
113         /BINOMIAL(0.4) = x
114         .
115
116 ECHO 'P > 0.5; N1/N2 < 1' .
117
118 NEW FILE.
119
120 DATA LIST LIST NOTABLE /x * w *.
121 BEGIN DATA.
122 1   11
123 2   12
124 END DATA.
125
126 WEIGHT BY w.
127
128 NPAR TESTS
129         /BINOMIAL(0.6) = x
130         .
131
132
133 ECHO 'P > 0.5; N1/N2 > 1' .
134
135 NEW FILE.
136
137 DATA LIST LIST NOTABLE /x * w *.
138 BEGIN DATA.
139 1   11
140 2   9
141 END DATA.
142
143 WEIGHT BY w.
144
145 NPAR TESTS
146         /BINOMIAL(0.6) = x
147
148 ECHO 'P > 0.5; N1/N2 == 1' .
149
150 NEW FILE.
151
152 DATA LIST LIST NOTABLE /x * w *.
153 BEGIN DATA.
154 1   11
155 2   11
156 END DATA.
157
158 WEIGHT BY w.
159
160 NPAR TESTS
161         /BINOMIAL(0.6) = x
162         .
163
164 ECHO 'P == 0.5; N1/N2 < 1' .
165
166 NEW FILE.
167
168 DATA LIST LIST NOTABLE /x * w *.
169 BEGIN DATA.
170 1   8
171 2   15
172 END DATA.
173
174 WEIGHT BY w.
175
176 NPAR TESTS
177         /BINOMIAL(0.5) = x
178         .
179
180
181 ECHO 'P == 0.5; N1/N2 > 1' .
182
183 NEW FILE.
184
185 DATA LIST LIST NOTABLE /x * w *.
186 BEGIN DATA.
187 1   12
188 2   6
189 END DATA.
190
191 WEIGHT BY w.
192
193 NPAR TESTS
194         /BINOMIAL(0.5) = x
195
196 ECHO 'P == 0.5; N1/N2 == 1' .
197
198 NEW FILE.
199
200 DATA LIST LIST NOTABLE /x * w *.
201 BEGIN DATA.
202 1   10
203 2   10
204 END DATA.
205
206 WEIGHT BY w.
207
208 NPAR TESTS
209         /BINOMIAL(0.5) = x
210         .
211 EOF
212 if [ $? -ne 0 ] ; then no_result ; fi
213
214
215 activity="run program 1"
216 $SUPERVISOR $PSPP --testing-mode $TESTFILE
217 if [ $? -ne 0 ] ; then no_result ; fi
218
219 activity="compare output 1"
220 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
221 diff -b $TEMPDIR/pspp.list - << EOF
222 P < 0.5; N1/N2 < 1
223 1.1 NPAR TESTS.  Binomial Test
224 +-+------#--------+--+--------------+----------+---------------------+
225 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
226 +-+------#--------+--+--------------+----------+---------------------+
227 |x|Group1#    1.00| 6|          .286|      .300|                 .551|
228 | |Group2#    2.00|15|          .714|          |                     |
229 | |Total #        |21|          1.00|          |                     |
230 +-+------#--------+--+--------------+----------+---------------------+
231 P < 0.5; N1/N2 > 1
232 2.1 NPAR TESTS.  Binomial Test
233 +-+------#--------+--+--------------+----------+---------------------+
234 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
235 +-+------#--------+--+--------------+----------+---------------------+
236 |x|Group1#    1.00| 7|          .538|      .400|                 .229|
237 | |Group2#    2.00| 6|          .462|          |                     |
238 | |Total #        |13|          1.00|          |                     |
239 +-+------#--------+--+--------------+----------+---------------------+
240 P < 0.5; N1/N2 = 1
241 3.1 NPAR TESTS.  Binomial Test
242 +-+------#--------+--+--------------+----------+---------------------+
243 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
244 +-+------#--------+--+--------------+----------+---------------------+
245 |x|Group1#    1.00| 8|          .500|      .400|                 .284|
246 | |Group2#    2.00| 8|          .500|          |                     |
247 | |Total #        |16|          1.00|          |                     |
248 +-+------#--------+--+--------------+----------+---------------------+
249 P > 0.5; N1/N2 < 1
250 4.1 NPAR TESTS.  Binomial Test
251 +-+------#--------+--+--------------+----------+---------------------+
252 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
253 +-+------#--------+--+--------------+----------+---------------------+
254 |x|Group1#    1.00|11|          .478|      .600|                 .164|
255 | |Group2#    2.00|12|          .522|          |                     |
256 | |Total #        |23|          1.00|          |                     |
257 +-+------#--------+--+--------------+----------+---------------------+
258 P > 0.5; N1/N2 > 1
259 5.1 NPAR TESTS.  Binomial Test
260 +-+------#--------+--+--------------+----------+---------------------+
261 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
262 +-+------#--------+--+--------------+----------+---------------------+
263 |x|Group1#    1.00|11|          .550|      .600|                 .404|
264 | |Group2#    2.00| 9|          .450|          |                     |
265 | |Total #        |20|          1.00|          |                     |
266 +-+------#--------+--+--------------+----------+---------------------+
267 P > 0.5; N1/N2 == 1
268 6.1 NPAR TESTS.  Binomial Test
269 +-+------#--------+--+--------------+----------+---------------------+
270 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
271 +-+------#--------+--+--------------+----------+---------------------+
272 |x|Group1#    1.00|11|          .500|      .600|                 .228|
273 | |Group2#    2.00|11|          .500|          |                     |
274 | |Total #        |22|          1.00|          |                     |
275 +-+------#--------+--+--------------+----------+---------------------+
276 P == 0.5; N1/N2 < 1
277 7.1 NPAR TESTS.  Binomial Test
278 +-+------#--------+--+--------------+----------+---------------------+
279 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
280 +-+------#--------+--+--------------+----------+---------------------+
281 |x|Group1#    1.00| 8|          .348|      .500|                 .210|
282 | |Group2#    2.00|15|          .652|          |                     |
283 | |Total #        |23|          1.00|          |                     |
284 +-+------#--------+--+--------------+----------+---------------------+
285 P == 0.5; N1/N2 > 1
286 8.1 NPAR TESTS.  Binomial Test
287 +-+------#--------+--+--------------+----------+---------------------+
288 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
289 +-+------#--------+--+--------------+----------+---------------------+
290 |x|Group1#    1.00|12|          .667|      .500|                 .238|
291 | |Group2#    2.00| 6|          .333|          |                     |
292 | |Total #        |18|          1.00|          |                     |
293 +-+------#--------+--+--------------+----------+---------------------+
294 P == 0.5; N1/N2 == 1
295 9.1 NPAR TESTS.  Binomial Test
296 +-+------#--------+--+--------------+----------+---------------------+
297 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
298 +-+------#--------+--+--------------+----------+---------------------+
299 |x|Group1#    1.00|10|          .500|      .500|                1.000|
300 | |Group2#    2.00|10|          .500|          |                     |
301 | |Total #        |20|          1.00|          |                     |
302 +-+------#--------+--+--------------+----------+---------------------+
303 EOF
304 if [ $? -ne 0 ] ; then fail ; fi
305
306
307 pass;