CORRELATIONS: Properly deal with case weights.
[pspp-builds.git] / tests / command / correlation.sh
1 #!/bin/sh
2
3 # This program tests the CORRELATIONS 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      rm -rf $TEMPDIR
30 }
31
32
33 fail()
34 {
35     echo $activity
36     echo FAILED
37     cleanup;
38     exit 1;
39 }
40
41
42 no_result()
43 {
44     echo $activity
45     echo NO RESULT;
46     cleanup;
47     exit 2;
48 }
49
50 pass()
51 {
52     cleanup;
53     exit 0;
54 }
55
56 mkdir -p $TEMPDIR
57
58 cd $TEMPDIR
59
60 activity="create program 1"
61 cat << EOF > $TESTFILE
62 set format = F11.3.
63 data list notable list /foo * bar * wiz * bang *.
64 begin data.
65 1   0   3   1
66 3   9 -50   5
67 3   4   3 203
68 4  -9   0  -4
69 98 78 104   2
70 3  50 -49 200
71 .   4   4   4
72 5   3   0   .
73 end data.
74
75 correlations 
76         variables = foo bar wiz bang
77         /print nosig
78         /missing = listwise
79         .
80
81 correlations 
82         variables = bar wiz
83         /print nosig
84         /missing = listwise
85         .
86
87 correlations 
88         variables = foo bar wiz bang
89         /print nosig
90         /missing = pairwise
91         .
92 EOF
93 if [ $? -ne 0 ] ; then no_result ; fi
94
95
96 activity="run program 1"
97 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
98 if [ $? -ne 0 ] ; then no_result ; fi
99
100 activity="compare results 1"
101 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
102 diff -b  $TEMPDIR/pspp.list - << EOF
103 1.1 CORRELATIONS.  Correlations
104 #========================#=====#=====#=====#=====#
105 #                        #foo  |bar  |wiz  |bang #
106 #----+-------------------#-----+-----+-----+-----#
107 #foo |Pearson Correlation#1.000| .802| .890|-.308#
108 #    |Sig. (2-tailed)    #     | .055| .017| .553#
109 #----+-------------------#-----+-----+-----+-----#
110 #bar |Pearson Correlation# .802|1.000| .519| .118#
111 #    |Sig. (2-tailed)    # .055|     | .291| .824#
112 #----+-------------------#-----+-----+-----+-----#
113 #wiz |Pearson Correlation# .890| .519|1.000|-.344#
114 #    |Sig. (2-tailed)    # .017| .291|     | .505#
115 #----+-------------------#-----+-----+-----+-----#
116 #bang|Pearson Correlation#-.308| .118|-.344|1.000#
117 #    |Sig. (2-tailed)    # .553| .824| .505|     #
118 #====#===================#=====#=====#=====#=====#
119 2.1 CORRELATIONS.  Correlations
120 #=======================#=====#=====#
121 #                       #bar  |wiz  #
122 #---+-------------------#-----+-----#
123 #bar|Pearson Correlation#1.000| .497#
124 #   |Sig. (2-tailed)    #     | .210#
125 #---+-------------------#-----+-----#
126 #wiz|Pearson Correlation# .497|1.000#
127 #   |Sig. (2-tailed)    # .210|     #
128 #===#===================#=====#=====#
129 3.1 CORRELATIONS.  Correlations
130 #========================#=====#=====#=====#=====#
131 #                        #foo  |bar  |wiz  |bang #
132 #----+-------------------#-----+-----+-----+-----#
133 #foo |Pearson Correlation#1.000| .805| .883|-.308#
134 #    |Sig. (2-tailed)    #     | .029| .008| .553#
135 #    |N                  #    7|    7|    7|    6#
136 #----+-------------------#-----+-----+-----+-----#
137 #bar |Pearson Correlation# .805|1.000| .497| .164#
138 #    |Sig. (2-tailed)    # .029|     | .210| .725#
139 #    |N                  #    7|    8|    8|    7#
140 #----+-------------------#-----+-----+-----+-----#
141 #wiz |Pearson Correlation# .883| .497|1.000|-.337#
142 #    |Sig. (2-tailed)    # .008| .210|     | .460#
143 #    |N                  #    7|    8|    8|    7#
144 #----+-------------------#-----+-----+-----+-----#
145 #bang|Pearson Correlation#-.308| .164|-.337|1.000#
146 #    |Sig. (2-tailed)    # .553| .725| .460|     #
147 #    |N                  #    6|    7|    7|    7#
148 #====#===================#=====#=====#=====#=====#
149 EOF
150 if [ $? -ne 0 ] ; then fail ; fi
151
152
153 # Now test that weights are properly handled.
154
155 activity="create program 2"
156 cat << EOF > $TESTFILE
157 set format = F11.3.
158 data list notable list /foo * bar * wiz * bang * w *.
159 begin data.
160 1   0   3   1  1
161 3   9 -50   5  2
162 3   4   3 203  1
163 4  -9   0  -4  1
164 98 78 104   2  3
165 3  50 -49 200  1
166 end data.
167
168 weight by w.
169
170 correlations 
171         variables = foo bar wiz bang
172         /statistics=descriptives xprod
173         .
174
175 EOF
176 if [ $? -ne 0 ] ; then no_result ; fi
177
178
179 activity="run program 2"
180 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
181 if [ $? -ne 0 ] ; then no_result ; fi
182
183 activity="copy results"
184 cp $TEMPDIR/pspp.list $TEMPDIR/weighted
185 if [ $? -ne 0 ] ; then no_result ; fi
186
187 activity="create program 3"
188 cat << EOF > $TESTFILE
189 set format = F11.3.
190 data list notable list /foo * bar * wiz * bang * w *.
191 begin data.
192 1   0   3   1  1
193 3   9 -50   5  1
194 3   9 -50   5  1
195 3   4   3 203  1
196 4  -9   0  -4  1
197 98 78 104   2  1
198 98 78 104   2  1
199 98 78 104   2  1
200 3  50 -49 200  1
201 end data.
202
203 weight by w.
204
205 correlations 
206         variables = foo bar wiz bang
207         /statistics=descriptives xprod
208         .
209
210 EOF
211 if [ $? -ne 0 ] ; then no_result ; fi
212
213 activity="run program 3"
214 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
215 if [ $? -ne 0 ] ; then no_result ; fi
216
217 activity="Compare weighted and unweighted results"
218 diff $TEMPDIR/pspp.list $TEMPDIR/weighted
219 if [ $? -ne 0 ] ; then fail ; fi
220
221 pass;