dnl PSPP - a program for statistical analysis.
dnl Copyright (C) 2017, 2020 Free Software Foundation, Inc.
dnl
dnl This program is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation, either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
dnl
AT_BANNER([ONEWAY procedure])

AT_SETUP([ONEWAY basic operation])
AT_KEYWORDS([categorical categoricals])
AT_DATA([oneway.sps],
  [DATA LIST NOTABLE LIST /QUALITY * BRAND * .
BEGIN DATA
7  3
4  3
3  1
2  1
1  1
4  2
2  2
3  2
5  3
1  1
4  1
5  2
2  2
3  3
6  3
END DATA

VARIABLE LABELS brand 'Manufacturer'.
VARIABLE LABELS quality 'Breaking Strain'.

VALUE LABELS /brand 1 'Aspeger' 2 'Bloggs' 3 'Charlies'.

ONEWAY
	quality BY brand
	/STATISTICS descriptives homogeneity
	/CONTRAST =  -2 1 1
	/CONTRAST = 0 -1 1
	.
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt oneway.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Descriptives
,Manufacturer,N,Mean,Std. Deviation,Std. Error,95% Confidence Interval for Mean,,Minimum,Maximum
,,,,,,Lower Bound,Upper Bound,,
Breaking Strain,Aspeger,5,2.20,1.30,.58,.58,3.82,1.00,4.00
,Bloggs,5,3.20,1.30,.58,1.58,4.82,2.00,5.00
,Charlies,5,5.00,1.58,.71,3.04,6.96,3.00,7.00
,Total,15,3.47,1.77,.46,2.49,4.45,1.00,7.00

Table: Test of Homogeneity of Variances
,Levene Statistic,df1,df2,Sig.
Breaking Strain,.09,2,12,.913

Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
Breaking Strain,Between Groups,20.13,2,10.07,5.12,.025
,Within Groups,23.60,12,1.97,,
,Total,43.73,14,,,

Table: Contrast Coefficients
Contrast,Manufacturer,,
,Aspeger,Bloggs,Charlies
1,-2,1,1
2,0,-1,1

Table: Contrast Tests
,,Contrast,Value of Contrast,Std. Error,t,df,Sig. (2-tailed)
Breaking Strain,Assume equal variances,1,3.80,1.54,2.47,12.00,.029
,,2,1.80,.89,2.03,12.00,.065
,Does not assume equal variances,1,3.80,1.48,2.56,8.74,.031
,,2,1.80,.92,1.96,7.72,.086
])
AT_CLEANUP


AT_SETUP([ONEWAY with splits])
AT_KEYWORDS([categorical categoricals])
AT_DATA([oneway-splits.sps],
[DATA LIST NOTABLE LIST /QUALITY * BRAND * S *.
BEGIN DATA
3 1 1
2 1 1
1 1 1
1 1 1
4 1 1
5 2 1
2 2 1
4 2 2
2 2 2
3 2 2
7  3 2
4  3 2
5  3 2
3  3 2
6  3 2
END DATA

VARIABLE LABELS brand 'Manufacturer'.
VARIABLE LABELS quality 'Breaking Strain'.

VALUE LABELS /brand 1 'Aspeger' 2 'Bloggs' 3 'Charlies'.

SPLIT FILE by s.

ONEWAY
	quality BY brand
	/STATISTICS descriptives homogeneity
	/CONTRAST =  -2 2
	/CONTRAST = -1 1
	.
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt oneway-splits.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Split Values
Variable,Value
S,1.00

Table: Descriptives
,Manufacturer,N,Mean,Std. Deviation,Std. Error,95% Confidence Interval for Mean,,Minimum,Maximum
,,,,,,Lower Bound,Upper Bound,,
Breaking Strain,Aspeger,5,2.20,1.30,.58,.58,3.82,1.00,4.00
,Bloggs,2,3.50,2.12,1.50,-15.56,22.56,2.00,5.00
,Total,7,2.57,1.51,.57,1.17,3.97,1.00,5.00

Table: Test of Homogeneity of Variances
,Levene Statistic,df1,df2,Sig.
Breaking Strain,1.09,1,5,.345

Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
Breaking Strain,Between Groups,2.41,1,2.41,1.07,.349
,Within Groups,11.30,5,2.26,,
,Total,13.71,6,,,

Table: Contrast Coefficients
Contrast,Manufacturer,
,Aspeger,Bloggs
1,-2,2
2,-1,1

Table: Contrast Tests
,,Contrast,Value of Contrast,Std. Error,t,df,Sig. (2-tailed)
Breaking Strain,Assume equal variances,1,2.60,2.52,1.03,5.00,.349
,,2,1.30,1.26,1.03,5.00,.349
,Does not assume equal variances,1,2.60,3.22,.81,1.32,.539
,,2,1.30,1.61,.81,1.32,.539

Table: Split Values
Variable,Value
S,2.00

Table: Descriptives
,Manufacturer,N,Mean,Std. Deviation,Std. Error,95% Confidence Interval for Mean,,Minimum,Maximum
,,,,,,Lower Bound,Upper Bound,,
Breaking Strain,Bloggs,3,3.00,1.00,.58,.52,5.48,2.00,4.00
,Charlies,5,5.00,1.58,.71,3.04,6.96,3.00,7.00
,Total,8,4.25,1.67,.59,2.85,5.65,2.00,7.00

Table: Test of Homogeneity of Variances
,Levene Statistic,df1,df2,Sig.
Breaking Strain,.92,1,6,.374

Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
Breaking Strain,Between Groups,7.50,1,7.50,3.75,.101
,Within Groups,12.00,6,2.00,,
,Total,19.50,7,,,

Table: Contrast Coefficients
Contrast,Manufacturer,
,Bloggs,Charlies
1,-2,2
2,-1,1

Table: Contrast Tests
,,Contrast,Value of Contrast,Std. Error,t,df,Sig. (2-tailed)
Breaking Strain,Assume equal variances,1,4.00,2.07,1.94,6.00,.101
,,2,2.00,1.03,1.94,6.00,.101
,Does not assume equal variances,1,4.00,1.83,2.19,5.88,.072
,,2,2.00,.91,2.19,5.88,.072
])
AT_CLEANUP


AT_SETUP([ONEWAY with missing values])
AT_KEYWORDS([categorical categoricals])
dnl Check that missing are treated properly
AT_DATA([oneway-missing1.sps],
[DATA LIST NOTABLE LIST /v1 * v2 * dep * vn *.
BEGIN DATA
. .  1  4
3 3  1  2
2 2  1  2
1 1  1  2
1 1  1  2
4 4  1  2
5 5  2  2
2 2  2  2
4 4  2  2
2 2  2  2
3 3  2  2
7 7  3  2
4 4  3  2
5 5  3  2
3 3  3  2
6 6  3  2
END DATA

ONEWAY
	v1 v2 BY dep
	/STATISTICS descriptives homogeneity
	/MISSING ANALYSIS
	.
])

AT_DATA([oneway-missing2.sps],
[DATA LIST NOTABLE LIST /v1 * v2 * dep * vn * .
BEGIN DATA
4 .  1  2
3 3  1  2
2 2  1  2
1 1  1  2
1 1  1  2
4 4  1  2
5 5  2  2
2 2  2  2
4 4  2  2
2 2  2  2
3 3  2  2
7 7  3  2
4 4  3  2
5 5  3  2
3 3  3  2
6 6  3  2
END DATA

ONEWAY
	v1 v2 BY dep
	/STATISTICS descriptives homogeneity
	/MISSING LISTWISE
	.
])



AT_CHECK([pspp -O format=csv oneway-missing1.sps > first.out], [0])

AT_CHECK([pspp -O format=csv oneway-missing2.sps > second.out], [0])

AT_CHECK([diff first.out second.out], [0], [])

dnl Now a test with missing values in the independent variable
AT_DATA([oneway-missing3.sps],
[DATA LIST NOTABLE LIST /v1 * v2 * dep * vn * .
BEGIN DATA
4 2  .  2
3 3  1  2
2 2  1  2
1 1  1  2
1 1  1  2
4 4  1  2
5 5  2  2
2 2  2  2
4 4  2  2
2 2  2  2
3 3  2  2
7 7  3  2
4 4  3  2
5 5  3  4
3 3  3  2
6 6  3  2
END DATA

ONEWAY
	v1 v2 BY dep
	/STATISTICS descriptives homogeneity
	/MISSING ANALYSIS
	.
])

AT_CHECK([pspp -O format=csv oneway-missing3.sps > third.out], [0])

AT_CHECK([diff first.out third.out], [0], [])

AT_CLEANUP





AT_SETUP([ONEWAY descriptives subcommand])
AT_KEYWORDS([categorical categoricals])

AT_DATA([oneway-descriptives.sps],
  [DATA LIST NOTABLE LIST /QUALITY * BRAND * .
BEGIN DATA
13 11
12 11
11 11
11 11
14 11
15 25
12 25
14 25
12 25
13 25
17  301
14  301
15  301
13  301
16  301
END DATA


ONEWAY
	quality BY brand
	/STATISTICS descriptives
	.
])

AT_CHECK([pspp -O format=csv oneway-descriptives.sps], [0],
[Table: Descriptives
,BRAND,N,Mean,Std. Deviation,Std. Error,95% Confidence Interval for Mean,,Minimum,Maximum
,,,,,,Lower Bound,Upper Bound,,
QUALITY,11.00,5,12.20,1.30,.58,10.58,13.82,11.00,14.00
,25.00,5,13.20,1.30,.58,11.58,14.82,12.00,15.00
,301.00,5,15.00,1.58,.71,13.04,16.96,13.00,17.00
,Total,15,13.47,1.77,.46,12.49,14.45,11.00,17.00

Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
QUALITY,Between Groups,20.13,2,10.07,5.12,.025
,Within Groups,23.60,12,1.97,,
,Total,43.73,14,,,
])

AT_CLEANUP



AT_SETUP([ONEWAY homogeneity subcommand])
AT_KEYWORDS([categorical categoricals])

AT_DATA([oneway-homogeneity.sps],
  [DATA LIST NOTABLE LIST /QUALITY * BRAND * .
BEGIN DATA
13 11
12 11
11 11
11 11
14 11
15 25
12 25
14 25
12 25
13 25
17  301
14  301
15  301
13  301
16  301
END DATA


ONEWAY
	quality BY brand
	/STATISTICS homogeneity
	.
])

AT_CHECK([pspp -O format=csv oneway-homogeneity.sps], [0],
[Table: Test of Homogeneity of Variances
,Levene Statistic,df1,df2,Sig.
QUALITY,.09,2,12,.913

Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
QUALITY,Between Groups,20.13,2,10.07,5.12,.025
,Within Groups,23.60,12,1.97,,
,Total,43.73,14,,,
])

AT_CLEANUP



AT_SETUP([ONEWAY multiple variables])
AT_KEYWORDS([categorical categoricals])
dnl check that everything works ok when several different dependent variables are specified.
dnl This of course does not mean that we're doing a multivariate analysis.  It's just like
dnl running several tests at once.
AT_DATA([multivar.sps],
[DATA LIST notable LIST /x * y * z * g *.
begin data.
1 1 0 10
1 1 9 10
9 1 2 10
1 1 3 20
1 1 8 20
1 1 1 20
1 1 2 20
0 1 3 20
1 1 4 30
0 1 5 30
1 1 6 30
0 1 7 30
1 2 8 30
2 2 9 30
1 2 1 30
1 2 0 30
1 2 2 40
8 2 3 40
1 2 4 40
1 2 9 40
9 2 8 40
7 3 7 40
2 3 6 40
3 3 5 40
end data.

ONEWAY x y z by g
	/STATISTICS = DESCRIPTIVES HOMOGENEITY
	/CONTRAST 3  2 0 -5
	/CONTRAST 2 -9 7  0
	.
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt multivar.sps])

dnl Some machines return 3.88 instead of 3.87 below (see bug #31611).
AT_CHECK([sed -e 's/^,Within Groups,3.88/,Within Groups,3.87/' pspp.csv], [0],
  [Table: Descriptives
,g,N,Mean,Std. Deviation,Std. Error,95% Confidence Interval for Mean,,Minimum,Maximum
,,,,,,Lower Bound,Upper Bound,,
x,10.00,3,3.67,4.62,2.67,-7.81,15.14,1.00,9.00
,20.00,5,.80,.45,.20,.24,1.36,.00,1.00
,30.00,8,.88,.64,.23,.34,1.41,.00,2.00
,40.00,8,4.00,3.42,1.21,1.14,6.86,1.00,9.00
,Total,24,2.25,2.83,.58,1.05,3.45,.00,9.00
y,10.00,3,1.00,.00,.00,1.00,1.00,1.00,1.00
,20.00,5,1.00,.00,.00,1.00,1.00,1.00,1.00
,30.00,8,1.50,.53,.19,1.05,1.95,1.00,2.00
,40.00,8,2.38,.52,.18,1.94,2.81,2.00,3.00
,Total,24,1.63,.71,.15,1.32,1.93,1.00,3.00
z,10.00,3,3.67,4.73,2.73,-8.07,15.41,.00,9.00
,20.00,5,3.40,2.70,1.21,.05,6.75,1.00,8.00
,30.00,8,5.00,3.21,1.13,2.32,7.68,.00,9.00
,40.00,8,5.50,2.45,.87,3.45,7.55,2.00,9.00
,Total,24,4.67,2.99,.61,3.40,5.93,.00,9.00

Table: Test of Homogeneity of Variances
,Levene Statistic,df1,df2,Sig.
x,18.76,3,20,.000
y,71.41,3,20,.000
z,.89,3,20,.463

Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
x,Between Groups,56.16,3,18.72,2.92,.059
,Within Groups,128.34,20,6.42,,
,Total,184.50,23,,,
y,Between Groups,7.75,3,2.58,13.33,.000
,Within Groups,3.87,20,.19,,
,Total,11.63,23,,,
z,Between Groups,17.47,3,5.82,.62,.610
,Within Groups,187.87,20,9.39,,
,Total,205.33,23,,,

Table: Contrast Coefficients
Contrast,g,,,
,10.00,20.00,30.00,40.00
1,3,2,0,-5
2,2,-9,7,0

Table: Contrast Tests
,,Contrast,Value of Contrast,Std. Error,t,df,Sig. (2-tailed)
x,Assume equal variances,1,-7.40,6.67,-1.11,20.00,.280
,,2,6.26,12.32,.51,20.00,.617
,Does not assume equal variances,1,-7.40,10.04,-.74,4.53,.497
,,2,6.26,5.85,1.07,2.87,.366
y,Assume equal variances,1,-6.88,1.16,-5.94,20.00,.000
,,2,3.50,2.14,1.63,20.00,.118
,Does not assume equal variances,1,-6.88,.91,-7.51,7.00,.000
,,2,3.50,1.32,2.65,7.00,.033
z,Assume equal variances,1,-9.70,8.07,-1.20,20.00,.243
,,2,11.73,14.91,.79,20.00,.440
,Does not assume equal variances,1,-9.70,9.57,-1.01,3.64,.373
,,2,11.73,14.53,.81,9.88,.438
])

AT_CLEANUP



dnl Tests that everything treats weights properly
AT_SETUP([ONEWAY vs. weights])
AT_KEYWORDS([categorical categoricals])

AT_DATA([oneway-unweighted.sps],
[DATA LIST NOTABLE LIST /QUALITY * BRAND * W *.
BEGIN DATA
3  1   1
2  1   1
1  1   1
1  1   1
4  1   1
5  2   1
2  2   1
4  2   1
4  2   1
4  2   1
2  2   1
2  2   1
3  2   1
7  3   1
4  3   1
5  3   1
5  3   1
3  3   1
6  3   1
END DATA.

WEIGHT BY W.

ONEWAY
	quality BY brand
	/STATISTICS descriptives homogeneity
	.
])

AT_CHECK([pspp -o pspp-unweighted.csv oneway-unweighted.sps], [0], [ignore], [ignore])

AT_DATA([oneway-weighted.sps],
[DATA LIST NOTABLE LIST /QUALITY * BRAND * W *.
BEGIN DATA
3  1   1
2  1   1
1  1   2
4  1   1
5  2   1
2  2   1
4  2   3
2  2   2
3  2   1
7  3   1
4  3   1
5  3   2
3  3   1
6  3   1
END DATA.

WEIGHT BY W.

ONEWAY
	quality BY brand
	/STATISTICS descriptives homogeneity
	.
])

AT_CHECK([pspp -o pspp-weighted.csv oneway-weighted.sps], [0], [ignore], [ignore])

AT_CHECK([diff pspp-weighted.csv pspp-unweighted.csv], [0])

AT_CLEANUP



AT_SETUP([ONEWAY posthoc LSD and BONFERRONI])
AT_KEYWORDS([categorical categoricals])
AT_DATA([oneway-pig.sps],[dnl
SET FORMAT F12.3.
data list notable list /pigmentation * family *.
begin data.
36 1
39 1
43 1
38 1
37 1
46 2
47 2
47 2
47 2
43 2
40 3
50 3
44 3
48 3
50 3
45 4
53 4
56 4
52 4
56 4
end data.


oneway pigmentation by family
	/statistics = descriptives
	/posthoc = lsd bonferroni alpha (0.05)
	 .
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt oneway-pig.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Descriptives
,family,N,Mean,Std. Deviation,Std. Error,95% Confidence Interval for Mean,,Minimum,Maximum
,,,,,,Lower Bound,Upper Bound,,
pigmentation,1.000,5,38.600,2.702,1.208,35.245,41.955,36.000,43.000
,2.000,5,46.000,1.732,.775,43.849,48.151,43.000,47.000
,3.000,5,46.400,4.336,1.939,41.016,51.784,40.000,50.000
,4.000,5,52.400,4.506,2.015,46.806,57.994,45.000,56.000
,Total,20,45.850,5.967,1.334,43.057,48.643,36.000,56.000

Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
pigmentation,Between Groups,478.950,3,159.650,12.927,.000
,Within Groups,197.600,16,12.350,,
,Total,676.550,19,,,

Table: Multiple Comparisons (pigmentation)
,(I) Family,(J) Family,Mean Difference (I - J),Std. Error,Sig.,95% Confidence Interval,
,,,,,,Lower Bound,Upper Bound
LSD,1.000,2.000,-7.400,2.223,.004,-12.112,-2.688
,,3.000,-7.800,2.223,.003,-12.512,-3.088
,,4.000,-13.800,2.223,.000,-18.512,-9.088
,2.000,1.000,7.400,2.223,.004,2.688,12.112
,,3.000,-.400,2.223,.859,-5.112,4.312
,,4.000,-6.400,2.223,.011,-11.112,-1.688
,3.000,1.000,7.800,2.223,.003,3.088,12.512
,,2.000,.400,2.223,.859,-4.312,5.112
,,4.000,-6.000,2.223,.016,-10.712,-1.288
,4.000,1.000,13.800,2.223,.000,9.088,18.512
,,2.000,6.400,2.223,.011,1.688,11.112
,,3.000,6.000,2.223,.016,1.288,10.712
Bonferroni,1.000,2.000,-7.400,2.223,.025,-14.086,-.714
,,3.000,-7.800,2.223,.017,-14.486,-1.114
,,4.000,-13.800,2.223,.000,-20.486,-7.114
,2.000,1.000,7.400,2.223,.025,.714,14.086
,,3.000,-.400,2.223,1.000,-7.086,6.286
,,4.000,-6.400,2.223,.065,-13.086,.286
,3.000,1.000,7.800,2.223,.017,1.114,14.486
,,2.000,.400,2.223,1.000,-6.286,7.086
,,4.000,-6.000,2.223,.095,-12.686,.686
,4.000,1.000,13.800,2.223,.000,7.114,20.486
,,2.000,6.400,2.223,.065,-.286,13.086
,,3.000,6.000,2.223,.095,-.686,12.686
])
AT_CLEANUP


AT_SETUP([ONEWAY posthoc Tukey HSD and Games-Howell])
AT_KEYWORDS([categorical categoricals])
AT_DATA([oneway-tukey.sps],[dnl
set format = f11.3.
data list notable list /libido * dose *.
begin data.
3 0
2 0
1 0
1 0
4 0
5 1
2 1
4 1
2 1
3 1
7 2
4 2
5 2
3 2
6 2
end data.

variable label dose 'Dose of Viagra'.

add value labels dose 0 'Placebo' 1 '1 Dose' 2 '2 Doses'.

oneway libido by dose
	/posthoc tukey gh.
])

AT_CHECK([pspp -o pspp.csv -o pspp.txt oneway-tukey.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
libido,Between Groups,20.133,2,10.067,5.119,.025
,Within Groups,23.600,12,1.967,,
,Total,43.733,14,,,

Table: Multiple Comparisons (libido)
,(I) Family,(J) Family,Mean Difference (I - J),Std. Error,Sig.,95% Confidence Interval,
,,,,,,Lower Bound,Upper Bound
Tukey HSD,Placebo,1 Dose,-1.000,.887,.516,-3.366,1.366
,,2 Doses,-2.800,.887,.021,-5.166,-.434
,1 Dose,Placebo,1.000,.887,.516,-1.366,3.366
,,2 Doses,-1.800,.887,.147,-4.166,.566
,2 Doses,Placebo,2.800,.887,.021,.434,5.166
,,1 Dose,1.800,.887,.147,-.566,4.166
Games-Howell,Placebo,1 Dose,-1.000,.887,.479,-3.356,1.356
,,2 Doses,-2.800,.887,.039,-5.439,-.161
,1 Dose,Placebo,1.000,.887,.479,-1.356,3.356
,,2 Doses,-1.800,.887,.185,-4.439,.839
,2 Doses,Placebo,2.800,.887,.039,.161,5.439
,,1 Dose,1.800,.887,.185,-.839,4.439
])

AT_CLEANUP

AT_SETUP([ONEWAY posthoc Sidak])
AT_KEYWORDS([categorical categoricals])
AT_DATA([oneway-sidak.sps],[dnl
SET FORMAT F20.4.

DATA LIST notable LIST /program score.
BEGIN DATA.
1   9
1  12
1  14
1  11
1  13
2  10
2   6
2   9
2   9
2  10
3  12
3  14
3  11
3  13
3  11
4   9
4   8
4  11
4   7
4   8
END DATA.

ONEWAY
  score BY program
  /MISSING ANALYSIS
  /POSTHOC = SIDAK.
])

AT_CHECK([pspp -O format=csv oneway-sidak.sps], [0],
[Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
score,Between Groups,54.9500,3,18.3167,7.0449,.003
,Within Groups,41.6000,16,2.6000,,
,Total,96.5500,19,,,

Table: Multiple Comparisons (score)
,(I) Family,(J) Family,Mean Difference (I - J),Std. Error,Sig.,95% Confidence Interval,
,,,,,,Lower Bound,Upper Bound
Šidák,1.0000,2.0000,3.0000,1.0198,.056,-.0575,6.0575
,,3.0000,-.4000,1.0198,.999,-3.4575,2.6575
,,4.0000,3.2000,1.0198,.038,.1425,6.2575
,2.0000,1.0000,-3.0000,1.0198,.056,-6.0575,.0575
,,3.0000,-3.4000,1.0198,.025,-6.4575,-.3425
,,4.0000,.2000,1.0198,1.000,-2.8575,3.2575
,3.0000,1.0000,.4000,1.0198,.999,-2.6575,3.4575
,,2.0000,3.4000,1.0198,.025,.3425,6.4575
,,4.0000,3.6000,1.0198,.017,.5425,6.6575
,4.0000,1.0000,-3.2000,1.0198,.038,-6.2575,-.1425
,,2.0000,-.2000,1.0198,1.000,-3.2575,2.8575
,,3.0000,-3.6000,1.0198,.017,-6.6575,-.5425
])

AT_CLEANUP

AT_SETUP([ONEWAY posthoc Scheffe])
AT_KEYWORDS([categorical categoricals])
AT_DATA([oneway-scheffe.sps],[dnl
set format = f11.3.
data list notable list /usage * group *.
begin data.
21.00     1
19.00     1
18.00     1
25.00     1
14.00     1
13.00     1
24.00     1
19.00     1
20.00     1
21.00     1
15.00     2
10.00     2
13.00     2
16.00     2
14.00     2
24.00     2
16.00     2
14.00     2
18.00     2
16.00     2
10.00     3
 7.00     3
13.00     3
20.00     3
  .00     3
 8.00     3
 6.00     3
 1.00     3
12.00     3
14.00     3
18.00     4
15.00     4
 3.00     4
27.00     4
 6.00     4
14.00     4
13.00     4
11.00     4
 9.00     4
18.00     4
end data.

variable label usage 'Days of Use'.

add value labels group 0 'none' 1 'one' 2 'two' 3 'three' 4 'four'.

oneway usage by group
	/posthoc scheffe.
])

AT_CHECK([pspp -O format=csv oneway-scheffe.sps], [0],
[Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
Days of Use,Between Groups,555.275,3,185.092,6.663,.001
,Within Groups,1000.100,36,27.781,,
,Total,1555.375,39,,,

Table: Multiple Comparisons (Days of Use)
,(I) Family,(J) Family,Mean Difference (I - J),Std. Error,Sig.,95% Confidence Interval,
,,,,,,Lower Bound,Upper Bound
Scheffé,one,two,3.800,2.357,.467,-3.112,10.712
,,three,10.300,2.357,.001,3.388,17.212
,,four,6.000,2.357,.110,-.912,12.912
,two,one,-3.800,2.357,.467,-10.712,3.112
,,three,6.500,2.357,.072,-.412,13.412
,,four,2.200,2.357,.832,-4.712,9.112
,three,one,-10.300,2.357,.001,-17.212,-3.388
,,two,-6.500,2.357,.072,-13.412,.412
,,four,-4.300,2.357,.358,-11.212,2.612
,four,one,-6.000,2.357,.110,-12.912,.912
,,two,-2.200,2.357,.832,-9.112,4.712
,,three,4.300,2.357,.358,-2.612,11.212
])

AT_CLEANUP


AT_SETUP([ONEWAY bad contrast count])
AT_KEYWORDS([categorical categoricals])

AT_DATA([oneway-bad-contrast.sps],[dnl
DATA LIST NOTABLE LIST /height * weight * temperature * sex *.
BEGIN DATA.
1884     88.6       39.97     0
1801     90.9       39.03     0
1801     91.7       38.98     0
1607     56.3       36.26     1
1608     46.3       46.26     1
1607     55.9       37.84     1
1604     56.6       36.81     1
1606     56.1       34.56     1
END DATA.

ONEWAY /VARIABLES= height weight temperature BY sex
 /CONTRAST = -1  1
 /CONTRAST = -3  3
 /CONTRAST =  2 -2  1
 /CONTRAST = -9  9
 .
])


AT_CHECK([pspp -o pspp.csv -o pspp.txt oneway-bad-contrast.sps], [0], [dnl
oneway-bad-contrast.sps:18: warning: ONEWAY: In contrast list 3, the number of coefficients (3) does not equal the number of groups (2). This contrast list will be ignored.
])
AT_CHECK([cat pspp.csv], [0], [dnl
"oneway-bad-contrast.sps:18: warning: ONEWAY: In contrast list 3, the number of coefficients (3) does not equal the number of groups (2). This contrast list will be ignored."

Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
height,Between Groups,92629.63,1,92629.63,120.77,.000
,Within Groups,4601.87,6,766.98,,
,Total,97231.50,7,,,
weight,Between Groups,2451.65,1,2451.65,174.59,.000
,Within Groups,84.25,6,14.04,,
,Total,2535.90,7,,,
temperature,Between Groups,1.80,1,1.80,.13,.733
,Within Groups,84.55,6,14.09,,
,Total,86.36,7,,,

Table: Contrast Coefficients
Contrast,sex,
,.00,1.00
1,-1,1
2,-3,3
3,-9,9

Table: Contrast Tests
,,Contrast,Value of Contrast,Std. Error,t,df,Sig. (2-tailed)
height,Assume equal variances,1,-222.27,20.23,-10.99,6.00,.000
,,2,-666.80,60.68,-10.99,6.00,.000
,,3,-2000.40,182.03,-10.99,6.00,.000
,Does not assume equal variances,1,-222.27,27.67,-8.03,2.00,.015
,,2,-666.80,83.02,-8.03,2.00,.015
,,3,-2000.40,249.07,-8.03,2.00,.015
weight,Assume equal variances,1,-36.16,2.74,-13.21,6.00,.000
,,2,-108.48,8.21,-13.21,6.00,.000
,,3,-325.44,24.63,-13.21,6.00,.000
,Does not assume equal variances,1,-36.16,2.19,-16.48,5.42,.000
,,2,-108.48,6.58,-16.48,5.42,.000
,,3,-325.44,19.75,-16.48,5.42,.000
temperature,Assume equal variances,1,-.98,2.74,-.36,6.00,.733
,,2,-2.94,8.22,-.36,6.00,.733
,,3,-8.83,24.67,-.36,6.00,.733
,Does not assume equal variances,1,-.98,2.07,-.47,4.19,.660
,,2,-2.94,6.22,-.47,4.19,.660
,,3,-8.83,18.66,-.47,4.19,.660
])
AT_CLEANUP


AT_SETUP([ONEWAY crash on single category independent variable])
AT_KEYWORDS([categorical categoricals])
AT_DATA([crash.sps],[
input program.
loop #i = 1 to 10.
compute test = #i.
end case.
end loop.
end file.
end input program.

compute x = 1.

oneway test by x.
])

AT_CHECK([pspp -O format=csv crash.sps], [0], [ignore])

AT_CLEANUP



AT_SETUP([ONEWAY crash on missing dependent variable])
AT_KEYWORDS([categorical categoricals])
AT_DATA([crash2.sps],[dnl
data list notable list /dv1 * dv2  *  y * .
begin data.
2  .  2
1  .  2
1  .  1
2  .  4
3  .  4
4  .  4
5  .  4
end data.

ONEWAY
       /VARIABLES= dv1 dv2  BY y
       /STATISTICS = DESCRIPTIVES
       /POSTHOC = BONFERRONI LSD SCHEFFE SIDAK TUKEY
       /MISSING = ANALYSIS
       .
])

AT_CHECK([pspp -O format=csv crash2.sps], [0], [ignore])

AT_CLEANUP




AT_SETUP([ONEWAY Games-Howell test with few cases])
AT_KEYWORDS([categorical categoricals])
AT_DATA([crash3.sps],[dnl
data list notable list /dv * y * .
begin data.
2 2
1 2
1 1
2 4
3 4
end data.

ONEWAY
 /VARIABLES= dv BY y
 /POSTHOC = GH
 .
])

AT_CHECK([pspp -O format=csv crash3.sps], [0], [ignore])

AT_CLEANUP


AT_SETUP([ONEWAY Crash on empty data])
AT_KEYWORDS([categorical categoricals])
AT_DATA([crash4.sps],[dnl
DATA LIST NOTABLE LIST /height * weight * temperature * sex *.
BEGIN DATA.
1801     .       .     0
1606     .       .     1
END DATA.

ONEWAY /VARIABLES= height weight temperature BY sex
 /CONTRAST = -1  1
 /CONTRAST = -3  3
 /CONTRAST =  2 -2  1
 /CONTRAST = -9  9
 .
])

AT_CHECK([pspp -O format=csv crash4.sps], [0], [ignore])

AT_CLEANUP



AT_SETUP([ONEWAY Crash on invalid dependent variable])
AT_KEYWORDS([categorical categoricals])
AT_DATA([crash5.sps],[dnl
data list notable list /a * b *.
begin data.
3 0
2 0
6 2
end data.

oneway a"by b.

])

AT_CHECK([pspp -O format=csv crash5.sps], [1], [ignore])

AT_CLEANUP




AT_SETUP([ONEWAY Crash on unterminated string])
AT_KEYWORDS([categorical categoricals])

AT_DATA([crash6.sps], [dnl
DATA LIST NOTABLE LIST /height * weight * temperature * sex *.
BEGIN DATA.
1801     .       .     0
1606     .   0   .     1
END DATA.

ONEWAY /VARIABLES= height weight temperature BY sex
 /CONTRAST =" 2 -2  1
 .
])

AT_CHECK([pspp -O format=csv crash6.sps], [1], [ignore])

AT_CLEANUP


AT_SETUP([ONEWAY contrast bug])

AT_KEYWORDS([categorical categoricals])



dnl this example comes from: https://case.truman.edu/files/2015/06/SPSS-One-Way-ANOVA.pdf
AT_DATA([contrasts.sps],
[
SET FORMAT=F10.3.

DATA LIST notable LIST /relieftime drugs *.
begin data.
12 0
15 0
18 0
16 0
20 0
20 1
21 1
22 1
19 1
20 1
17 2
16 2
19 2
15 2
19 2
14 3
13 3
12 3
14 3
11 3
end data.

ONEWAY relieftime by drugs
	/CONTRAST 3 -1 -1 -1
	/CONTRAST 0 2 -1 -1
        /CONTRAST 0 0 1 -1
	.
])

AT_CHECK([pspp -O format=csv contrasts.sps], [0], [Table: ANOVA
,,Sum of Squares,df,Mean Square,F,Sig.
relieftime,Between Groups,146.950,3,48.983,12.723,.000
,Within Groups,61.600,16,3.850,,
,Total,208.550,19,,,

Table: Contrast Coefficients
Contrast,drugs,,,
,.000,1.000,2.000,3.000
1,3,-1,-1,-1
2,0,2,-1,-1
3,0,0,1,-1

Table: Contrast Tests
,,Contrast,Value of Contrast,Std. Error,t,df,Sig. (2-tailed)
relieftime,Assume equal variances,1,-1.800,3.040,-.592,16.000,.562
,,2,10.800,2.149,5.025,16.000,.000
,,3,4.400,1.241,3.546,16.000,.003
,Does not assume equal variances,1,-1.800,4.219,-.427,4.611,.689
,,2,10.800,1.421,7.599,10.158,.000
,,3,4.400,.990,4.445,7.315,.003
])
AT_CLEANUP

AT_SETUP([ONEWAY syntax errors])
AT_DATA([oneway.sps], [dnl
DATA LIST LIST NOTABLE/x y z.
ONEWAY/ **.
ONEWAY **.
ONEWAY x **.
ONEWAY x BY **.
ONEWAY x BY y/STATISTICS=**.
ONEWAY x BY y/POSTHOC=ALPHA **.
ONEWAY x BY y/POSTHOC=ALPHA(**).
ONEWAY x BY y/POSTHOC=ALPHA(123 **).
ONEWAY x BY y/POSTHOC=**.
ONEWAY x BY y/CONTRAST=**.
ONEWAY x BY y/MISSING=**.
ONEWAY x BY y/ **.
])
AT_CHECK([pspp -O format=csv oneway.sps], [1], [dnl
"oneway.sps:2.9-2.10: error: ONEWAY: Syntax error expecting VARIABLES.
    2 | ONEWAY/ **.
      |         ^~"

"oneway.sps:3.8-3.9: error: ONEWAY: Syntax error expecting variable name.
    3 | ONEWAY **.
      |        ^~"

"oneway.sps:4.10-4.11: error: ONEWAY: Syntax error expecting `BY'.
    4 | ONEWAY x **.
      |          ^~"

"oneway.sps:5.13-5.14: error: ONEWAY: Syntax error expecting variable name.
    5 | ONEWAY x BY **.
      |             ^~"

"oneway.sps:6.26-6.27: error: ONEWAY: Syntax error expecting DESCRIPTIVES or HOMOGENEITY.
    6 | ONEWAY x BY y/STATISTICS=**.
      |                          ^~"

"oneway.sps:7.29-7.30: error: ONEWAY: Syntax error expecting `('.
    7 | ONEWAY x BY y/POSTHOC=ALPHA **.
      |                             ^~"

"oneway.sps:8.29-8.30: error: ONEWAY: Syntax error expecting number.
    8 | ONEWAY x BY y/POSTHOC=ALPHA(**).
      |                             ^~"

"oneway.sps:9.33-9.34: error: ONEWAY: Syntax error expecting `)'.
    9 | ONEWAY x BY y/POSTHOC=ALPHA(123 **).
      |                                 ^~"

"oneway.sps:10.23-10.24: error: ONEWAY: Unknown post hoc analysis method.
   10 | ONEWAY x BY y/POSTHOC=**.
      |                       ^~"

"oneway.sps:11.24-11.25: error: ONEWAY: Syntax error expecting number.
   11 | ONEWAY x BY y/CONTRAST=**.
      |                        ^~"

"oneway.sps:12.23-12.24: error: ONEWAY: Syntax error expecting INCLUDE, EXCLUDE, LISTWISE, or ANALYSIS.
   12 | ONEWAY x BY y/MISSING=**.
      |                       ^~"

"oneway.sps:13.16-13.17: error: ONEWAY: Syntax error expecting STATISTICS, POSTHOC, CONTRAST, or MISSING.
   13 | ONEWAY x BY y/ **.
      |                ^~"
])
AT_CLEANUP