1 @c PSPP - a program for statistical analysis.
2 @c Copyright (C) 2017, 2020, 2021 Free Software Foundation, Inc.
3 @c Permission is granted to copy, distribute and/or modify this document
4 @c under the terms of the GNU Free Documentation License, Version 1.3
5 @c or any later version published by the Free Software Foundation;
6 @c with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
7 @c A copy of the license is included in the section entitled "GNU
8 @c Free Documentation License".
13 Some @pspp{} procedures work with matrices by producing numeric
14 matrices that report results of data analysis, or by consuming
15 matrices as a basis for further analysis. This chapter documents the
16 format of data files that store these matrices and commands for
17 working with them, as well as @pspp{}'s general-purpose facility for
24 A matrix file is an SPSS system file that conforms to the dictionary
25 and case structure described in this section. Procedures that read
26 matrices from files expect them to be in the matrix file format.
27 Procedures that write matrices also use this format.
29 Text files that contain matrices can be converted to matrix file
30 format. @xref{MATRIX DATA}, for a command to read a text file as a
33 A matrix file's dictionary must have the following variables in the
38 Zero or more numeric split variables. These are included by
39 procedures when @cmd{SPLIT FILE} is active. @cmd{MATRIX DATA} assigns
40 split variables format F4.0.
43 @code{ROWTYPE_}, a string variable with width 8. This variable
44 indicates the kind of matrix or vector that a given case represents.
45 The supported row types are listed below.
48 Zero or more numeric factor variables. These are included by
49 procedures that divide data into cells. For within-cell data, factor
50 variables are filled with non-missing values; for pooled data, they
51 are missing. @cmd{MATRIX DATA} assigns factor variables format F4.0.
54 @code{VARNAME_}, a string variable. Matrix data includes one row per
55 continuous variable (see below), naming each continuous variable in
56 order. This column is blank for vector data. @cmd{MATRIX DATA} makes
57 @code{VARNAME_} wide enough for the name of any of the continuous
58 variables, but at least 8 bytes.
61 One or more numeric continuous variables. These are the variables
62 whose data was analyzed to produce the matrices. @cmd{MATRIX DATA}
63 assigns continuous variables format F10.4.
66 Case weights are ignored in matrix files.
69 @anchor{Matrix File Row Types}
71 Matrix files support a fixed set of types of matrix and vector data.
72 The @code{ROWTYPE_} variable in each case of a matrix file indicates
75 The supported matrix row types are listed below. Each type is listed
76 with the keyword that identifies it in @code{ROWTYPE_}. All supported
77 types of matrices are square, meaning that each matrix must include
78 one row per continuous variable, with the @code{VARNAME_} variable
79 indicating each continuous variable in turn in the same order as the
84 Correlation coefficients.
87 Covariance coefficients.
90 General-purpose matrix.
99 The supported vector row types are listed below, along with their
100 associated keyword. Vector row types only require a single row, whose
101 @code{VARNAME_} is blank:
123 Only the row types listed above may appear in matrix files. The
124 @cmd{MATRIX DATA} command, however, accepts the additional row types
125 listed below, which it changes into matrix file row types as part of
126 its conversion process:
133 Synonym for @code{STDDEV}.
136 Accepts a single number from the @code{MATRIX DATA} input and writes
137 it as an @code{N} row with the number replicated across all the
138 continuous variables.
147 VARIABLES=@var{variables}
148 [FILE=@{'@var{file_name}' | INLINE@}
149 [/FORMAT=[@{LIST | FREE@}]
150 [@{UPPER | LOWER | FULL@}]
151 [@{DIAGONAL | NODIAGONAL@}]]
152 [/SPLIT=@var{split_vars}]
153 [/FACTORS=@var{factor_vars}]
156 The following subcommands are only needed when ROWTYPE_ is not
157 specified on the VARIABLES subcommand:
158 [/CONTENTS=@{CORR,COUNT,COV,DFE,MAT,MEAN,MSE,
159 N_MATRIX,N|N_VECTOR,N_SCALAR,PROX,SD|STDDEV@}]
160 [/CELLS=@var{n_cells}]
163 The @cmd{MATRIX DATA} command convert matrices and vectors from text
164 format into the matrix file format (@xref{Matrix Files}) for use by
165 procedures that read matrices. It reads a text file or inline data
166 and outputs to the active file, replacing any data already in the
167 active dataset. The matrix file may then be used by other commands
168 directly from the active file, or it may be written to a @file{.sav}
169 file using the @cmd{SAVE} command.
171 The text data read by @cmd{MATRIX DATA} can be delimited by spaces or
172 commas. A plus or minus sign, except immediately following a @samp{d}
173 or @samp{e}, also begins a new value. Optionally, values may be
174 enclosed in single or double quotes.
176 @cmd{MATRIX DATA} can read the types of matrix and vector data
177 supported in matrix files (@pxref{Matrix File Row Types}).
179 The @subcmd{FILE} subcommand specifies the source of the command's
180 input. To read input from a text file, specify its name in quotes.
181 To supply input inline, omit @subcmd{FILE} or specify @code{INLINE}.
182 Inline data must directly follow @code{MATRIX DATA}, inside @cmd{BEGIN
183 DATA} (@pxref{BEGIN DATA}).
185 @subcmd{VARIABLES} is the only required subcommand. It names the
186 variables present in each input record in the order that they appear.
187 (@cmd{MATRIX DATA} reorders the variables in the matrix file it
188 produces, if needed to fit the matrix file format.) The variable list
189 must include split variables and factor variables, if they are present
190 in the data, in addition to the continuous variables that form matrix
191 rows and columns. It may also include a special variable named
194 Matrix data may include split variables or factor variables or both.
195 List split variables, if any, on the @subcmd{SPLIT} subcommand and
196 factor variables, if any, on the @subcmd{FACTORS} subcommand. Split
197 and factor variables must be numeric. Split and factor variables must
198 also be listed on @subcmd{VARIABLES}, with one exception: if
199 @subcmd{VARIABLES} does not include @code{ROWTYPE_}, then
200 @subcmd{SPLIT} may name a single variable that is not in
201 @subcmd{VARIABLES} (@pxref{MATRIX DATA Example 8}).
203 The @subcmd{FORMAT} subcommand accepts settings to describe the format
207 @item @code{LIST} (default)
209 LIST requires each row to begin at the start of a new input line.
210 FREE allows rows to begin in the middle of a line. Either setting
211 allows a single row to continue across multiple input lines.
213 @item @code{LOWER} (default)
216 With LOWER, only the lower triangle is read from the input data and
217 the upper triangle is mirrored across the main diagonal. UPPER
218 behaves similarly for the upper triangle. FULL reads the entire
221 @item @code{DIAGONAL} (default)
222 @itemx @code{NODIAGONAL}
223 With DIAGONAL, the main diagonal is read from the input data. With
224 NODIAGONAL, which is incompatible with FULL, the main diagonal is not
225 read from the input data but instead set to 1 for correlation matrices
226 and system-missing for others.
229 The @subcmd{N} subcommand is a way to specify the size of the
230 population. It is equivalent to specifying an @code{N} vector with
231 the specified value for each split file.
233 @cmd{MATRIX DATA} supports two different ways to indicate the kinds of
234 matrices and vectors present in the data, depending on whether a
235 variable with the special name @code{ROWTYPE_} is present in
236 @code{VARIABLES}. The following subsections explain @cmd{MATRIX DATA}
237 syntax and behavior in each case.
239 @node MATRIX DATA with ROWTYPE_
240 @subsection With @code{ROWTYPE_}
242 If @code{VARIABLES} includes @code{ROWTYPE_}, each case's
243 @code{ROWTYPE_} indicates the type of data contained in the row.
244 @xref{Matrix File Row Types}, for a list of supported row types.
246 @subsubheading Example 1: Defaults with @code{ROWTYPE_}
247 @anchor{MATRIX DATA Example 1}
249 This example shows a simple use of @cmd{MATRIX DATA} with
250 @code{ROWTYPE_} plus 8 variables named @code{var01} through
253 Because @code{ROWTYPE_} is the first variable in @subcmd{VARIABLES},
254 it appears first on each line. The first three lines in the example
255 data have @code{ROWTYPE_} values of @samp{MEAN}, @samp{SD}, and
256 @samp{N}. These indicate that these lines contain vectors of means,
257 standard deviations, and counts, respectively, for @code{var01}
258 through @code{var08} in order.
260 The remaining 8 lines have a ROWTYPE_ of @samp{CORR} which indicates
261 that the values are correlation coefficients. Each of the lines
262 corresponds to a row in the correlation matrix: the first line is for
263 @code{var01}, the next line for @code{var02}, and so on. The input
264 only contains values for the lower triangle, including the diagonal,
265 since @code{FORMAT=LOWER DIAGONAL} is the default.
267 With @code{ROWTYPE_}, the @code{CONTENTS} subcommand is optional and
268 the @code{CELLS} subcommand may not be used.
272 VARIABLES=ROWTYPE_ var01 TO var08.
274 MEAN 24.3 5.4 69.7 20.1 13.4 2.7 27.9 3.7
275 SD 5.7 1.5 23.5 5.8 2.8 4.5 5.4 1.5
276 N 92 92 92 92 92 92 92 92
280 CORR .36 .31 -.14 1.00
281 CORR .27 .16 -.12 .22 1.00
282 CORR .33 .15 -.17 .24 .21 1.00
283 CORR .50 .29 -.20 .32 .12 .38 1.00
284 CORR .17 .29 -.05 .20 .27 .20 .04 1.00
288 @subsubheading Example 2: @code{FORMAT=UPPER NODIAGONAL}
290 This syntax produces the same matrix file as example 1, but it uses
291 @code{FORMAT=UPPER NODIAGONAL} to specify the upper triangle and omit
292 the diagonal. Because the matrix's @code{ROWTYPE_} is @code{CORR},
293 @pspp{} automatically fills in the diagonal with 1.
297 VARIABLES=ROWTYPE_ var01 TO var08
298 /FORMAT=UPPER NODIAGONAL.
300 MEAN 24.3 5.4 69.7 20.1 13.4 2.7 27.9 3.7
301 SD 5.7 1.5 23.5 5.8 2.8 4.5 5.4 1.5
302 N 92 92 92 92 92 92 92 92
303 CORR .17 .50 -.33 .27 .36 -.22 .18
304 CORR .29 .29 -.20 .32 .12 .38
305 CORR .05 .20 -.15 .16 .21
306 CORR .20 .32 -.17 .12
313 @subsubheading Example 3: @subcmd{N} subcommand
315 This syntax uses the @subcmd{N} subcommand in place of an @code{N}
316 vector. It produces the same matrix file as examples 1 and 2.
320 VARIABLES=ROWTYPE_ var01 TO var08
321 /FORMAT=UPPER NODIAGONAL
324 MEAN 24.3 5.4 69.7 20.1 13.4 2.7 27.9 3.7
325 SD 5.7 1.5 23.5 5.8 2.8 4.5 5.4 1.5
326 CORR .17 .50 -.33 .27 .36 -.22 .18
327 CORR .29 .29 -.20 .32 .12 .38
328 CORR .05 .20 -.15 .16 .21
329 CORR .20 .32 -.17 .12
336 @subsubheading Example 4: Split variables
337 @anchor{MATRIX DATA Example 4}
339 This syntax defines two matrices, using the variable @samp{s1} to
340 distinguish between them. Notice how the order of variables in the
341 input matches their order on @subcmd{VARIABLES}. This example also
342 uses @code{FORMAT=FULL}.
346 VARIABLES=s1 ROWTYPE_ var01 TO var04
367 @subsubheading Example 5: Factor variables
368 @anchor{MATRIX DATA Example 5}
370 This syntax defines a matrix file that includes a factor variable
371 @samp{f1}. The data includes mean, standard deviation, and count
372 vectors for two values of the factor variable, plus a correlation
373 matrix for pooled data.
377 VARIABLES=ROWTYPE_ f1 var01 TO var04
393 @node MATRIX DATA without ROWTYPE_
394 @subsection Without @code{ROWTYPE_}
396 If @code{VARIABLES} does not contain @code{ROWTYPE_}, the
397 @subcmd{CONTENTS} subcommand defines the row types that appear in the
398 file and their order. If @subcmd{CONTENTS} is omitted,
399 @code{CONTENTS=CORR} is assumed.
401 Factor variables without @code{ROWTYPE_} introduce special
402 requirements, illustrated below in Examples 8 and 9.
404 @subsubheading Example 6: Defaults without @code{ROWTYPE_}
406 This example shows a simple use of @cmd{MATRIX DATA} with 8 variables
407 named @code{var01} through @code{var08}, without @code{ROWTYPE_}.
408 This yields the same matrix file as Example 1 (@pxref{MATRIX DATA
413 VARIABLES=var01 TO var08
414 /CONTENTS=MEAN SD N CORR.
416 24.3 5.4 69.7 20.1 13.4 2.7 27.9 3.7
417 5.7 1.5 23.5 5.8 2.8 4.5 5.4 1.5
418 92 92 92 92 92 92 92 92
423 .27 .16 -.12 .22 1.00
424 .33 .15 -.17 .24 .21 1.00
425 .50 .29 -.20 .32 .12 .38 1.00
426 .17 .29 -.05 .20 .27 .20 .04 1.00
430 @subsubheading Example 7: Split variables with explicit values
432 This syntax defines two matrices, using the variable @code{s1} to
433 distinguish between them. Each line of data begins with @code{s1}.
434 This yields the same matrix file as Example 4 (@pxref{MATRIX DATA
439 VARIABLES=s1 var01 TO var04
442 /CONTENTS=MEAN SD N CORR.
461 @subsubheading Example 8: Split variable with sequential values
462 @anchor{MATRIX DATA Example 8}
464 Like this previous example, this syntax defines two matrices with
465 split variable @code{s1}. In this case, though, @code{s1} is not
466 listed in @subcmd{VARIABLES}, which means that its value does not
467 appear in the data. Instead, @cmd{MATRIX DATA} reads matrix data
468 until the input is exhausted, supplying 1 for the first split, 2 for
469 the second, and so on.
473 VARIABLES=var01 TO var04
476 /CONTENTS=MEAN SD N CORR.
495 @subsubsection Factor variables without @code{ROWTYPE_}
497 Without @subcmd{ROWTYPE_}, factor variables introduce two new wrinkles
498 to @cmd{MATRIX DATA} syntax. First, the @subcmd{CELLS} subcommand
499 must declare the number of combinations of factor variables present in
500 the data. If there is, for example, one factor variable for which the
501 data contains three values, one would write @code{CELLS=3}; if there
502 are two (or more) factor variables for which the data contains five
503 combinations, one would use @code{CELLS=5}; and so on.
505 Second, the @subcmd{CONTENTS} subcommand must distinguish within-cell
506 data from pooled data by enclosing within-cell row types in
507 parentheses. When different within-cell row types for a single factor
508 appear in subsequent lines, enclose the row types in a single set of
509 parentheses; when different factors' values for a given within-cell
510 row type appear in subsequent lines, enclose each row type in
511 individual parentheses.
513 Without @subcmd{ROWTYPE_}, input lines for pooled data do not include
514 factor values, not even as missing values, but input lines for
517 The following examples aim to clarify this syntax.
519 @subsubheading Example 9: Factor variables, grouping within-cell records by factor
521 This syntax defines the same matrix file as Example 5 (@pxref{MATRIX
522 DATA Example 5}), without using @code{ROWTYPE_}. It declares
523 @code{CELLS=2} because the data contains two values (0 and 1) for
524 factor variable @code{f1}. Within-cell vector row types @code{MEAN},
525 @code{SD}, and @code{N} are in a single set of parentheses on
526 @subcmd{CONTENTS} because they are grouped together in subsequent
527 lines for a single factor value. The data lines with the pooled
528 correlation matrix do not have any factor values.
532 VARIABLES=f1 var01 TO var04
535 /CONTENTS=(MEAN SD N) CORR.
550 @subsubheading Example 10: Factor variables, grouping within-cell records by row type
552 This syntax defines the same matrix file as the previous example. The
553 only difference is that the within-cell vector rows are grouped
554 differently: two rows of means (one for each factor), followed by two
555 rows of standard deviations, followed by two rows of counts.
559 VARIABLES=f1 var01 TO var04
562 /CONTENTS=(MEAN) (SD) (N) CORR.
584 [IN(@{@samp{*}|'@var{file}'@})]
585 [OUT(@{@samp{*}|'@var{file}'@})]]
586 [/@{REPLACE,APPEND@}].
589 The @cmd{MCONVERT} command converts matrix data from a correlation
590 matrix and a vector of standard deviations into a covariance matrix,
593 By default, @cmd{MCONVERT} both reads and writes the active file. Use
594 the @cmd{MATRIX} subcommand to specify other files. To read a matrix
595 file, specify its name inside parentheses following @code{IN}. To
596 write a matrix file, specify its name inside parentheses following
597 @code{OUT}. Use @samp{*} to explicitly specify the active file for
600 When @cmd{MCONVERT} reads the input, by default it substitutes a
601 correlation matrix and a vector of standard deviations each time it
602 encounters a covariance matrix, and vice versa. Specify
603 @code{/APPEND} to instead have @cmd{MCONVERT} add the other form of
604 data without removing the existing data. Use @code{/REPLACE} to
605 explicitly request removing the existing data.
607 The @cmd{MCONVERT} command requires its input to be a matrix file.
608 Use @cmd{MATRIX DATA} to convert text input into matrix file format.
609 @xref{MATRIX DATA}, for details.
616 @node Matrix Overview
621 @dots{}@i{matrix commands}@dots{}
626 The following basic matrix commands are supported:
629 @t{COMPUTE} @i{variable}[(@i{index}[,@i{index}])]=@i{expression}.
630 @t{CALL} @i{procedure}(@i{argument}, @dots{}).
631 @t{PRINT} [@i{expression}]
632 [/@t{FORMAT}=@i{format}]
633 [/@t{TITLE}=@i{title}]
634 [/@t{SPACE}=@{@t{NEWPAGE} @math{|} @i{n}@}]
635 [@{/@t{RLABELS}=@i{string}@dots{} @math{|} /@t{RNAMES}=@i{expression}@}]
636 [@{/@t{CLABELS}=@i{string}@dots{} @math{|} /@t{CNAMES}=@i{expression}@}].
640 The following matrix commands offer support for flow control:
643 @t{DO IF} @i{expression}.
644 @dots{}@i{matrix commands}@dots{}
645 [@t{ELSE IF} @i{expression}.
646 @dots{}@i{matrix commands}@dots{}]@dots{}
648 @dots{}@i{matrix commands}@dots{}]
651 @t{LOOP} [@i{var}=@i{first} @t{TO} @i{last} [@t{BY} @i{step}]] [@t{IF} @i{expression}].
652 @dots{}@i{matrix commands}@dots{}
653 @t{END LOOP} [@t{IF} @i{expression}].
659 The following matrix commands support matrix input and output:
662 @t{READ} @i{variable}[(@i{index}[,@i{index}])]
664 /@t{FIELD}=@i{first} @t{TO} @i{last} [@t{BY} @i{width}]
665 [/@t{SIZE}=@i{expression}]
666 [/@t{MODE}=@{@t{RECTANGULAR} @math{|} @t{SYMMETRIC}@}]
668 [/@t{FORMAT}=@i{format}].
669 @t{WRITE} @i{expression}
670 [/@t{OUTFILE}=@i{file}]
671 /@t{FIELD}=@i{first} @t{TO} @i{last} [@t{BY} @i{width}]
672 [/@t{MODE}=@{@t{RECTANGULAR} @math{|} @t{TRIANGULAR}@}]
674 [/@t{FORMAT}=@i{format}].
675 @t{GET} @i{variable}[(@i{index}[,@i{index}])]
676 [/@t{FILE}=@{@i{file} @math{|} @t{*}@}]
677 [/@t{VARIABLES}=@i{variable}@dots{}]
678 [/@t{NAMES}=@i{expression}]
679 [/@t{MISSING}=@{@t{ACCEPT} @math{|} @t{OMIT} @math{|} @i{number}@}]
680 [/@t{SYSMIS}=@{@t{OMIT} @math{|} @i{number}@}].
681 @t{SAVE} @i{expression}
682 [/@t{OUTFILE}=@{@i{file} @math{|} @t{*}@}]
683 [/@t{VARIABLES}=@i{variable}@dots{}]
684 [/@t{NAMES}=@i{expression}]
685 [/@t{STRINGS}=@i{variable}@dots{}].
686 @t{MGET} [/@t{FILE}=@i{file}]
687 [/@t{TYPE}=@{@t{COV} @math{|} @t{CORR} @math{|} @t{MEAN} @math{|} @t{STDDEV} @math{|} @t{N} @math{|} @t{COUNT}@}].
688 @t{MSAVE} @i{expression}
689 /@t{TYPE}=@{@t{COV} @math{|} @t{CORR} @math{|} @t{MEAN} @math{|} @t{STDDEV} @math{|} @t{N} @math{|} @t{COUNT}@}
690 [/@t{OUTFILE}=@i{file}]
691 [/@t{VARIABLES}=@i{variable}@dots{}]
692 [/@t{SNAMES}=@i{variable}@dots{}]
693 [/@t{SPLIT}=@i{expression}]
694 [/@t{FNAMES}=@i{variable}@dots{}]
695 [/@t{FACTOR}=@i{expression}].
699 The following matrix commands provide additional support:
702 @t{DISPLAY} [@{@t{DICTIONARY} @math{|} @t{STATUS}@}].
703 @t{RELEASE} @i{variable}@dots{}.
706 @node Matrix Introduction
707 @subsection Introduction
709 @code{MATRIX} and @code{END MATRIX} enclose a special @pspp{}
710 sub-language, called the matrix language. The matrix language does
711 not require an active dataset to be defined and only a few of the
712 matrix language commands work with any datasets that are defined.
713 Each instance of @code{MATRIX}@dots{}@code{END MATRIX} is a separate
714 program whose state is independent of any instance, so that variables
715 declared within a matrix program are forgotten at its end.
717 The matrix language works with matrices, where a @dfn{matrix} is a
718 rectangular array of real numbers. An @math{@var{n}@times{}@var{m}}
719 matrix has @var{n} rows and @var{m} columns. Some special cases are
720 important: a @math{@var{n}@times{}1} matrix is a @dfn{column vector},
721 a @math{1@times{}@var{n}} is a @dfn{row vector}, and a
722 @math{1@times{}1} matrix is a @dfn{scalar}.
724 The matrix language also has limited support for matrices that contain
725 8-byte strings instead of numbers. Strings longer than 8 bytes are
726 truncated, and shorter strings are padded with spaces. String
727 matrices are mainly useful for labeling rows and columns when printing
728 numerical matrices with the @code{MATRIX PRINT} command. Arithmetic
729 operations on string matrices will not produce useful results. The
730 user should not mix strings and numbers within a matrix.
732 The matrix language does not work with cases. A variable in the
733 matrix language represents a single matrix.
735 The matrix language does not support missing values.
737 @node Matrix Expressions
738 @subsection Matrix Expressions
740 Many matrix commands use expressions. A matrix expression may use the
741 following operators, listed in descending order of operator
745 @item @t{(@dots{})} @t{@{@dots{}@}}
747 @item @t{(}@i{index}[@t{,} @i{index}]@t{)}
759 @item @t{< <= = >= > <>}
768 Each of these operators is described in more detail below.
770 @node Matrix Construction Operator
771 @subsubsection The Matrix Construction Operator @t{@{@}}
773 Use the @t{@{}@t{@}} operator to construct matrices. Within
774 the curly braces, commas separate elements within a row and semicolons
775 separate rows. The following examples show a @math{2@times{}3}
776 matrix, a @math{1@times{}4} row vector, a @math{3@times{}1} column
777 vector, and a scalar.
779 @multitable @columnfractions .4 .05 .4
780 @item @t{@{1, 2, 3; 4, 5, 6@}}
784 @t{[1 2 3] @* [4 5 6]}
787 @math{\left(\matrix{1 & 2 & 3 \cr 4 & 5 & 6}\right)}
790 @item @t{@{3.14, 6.28, 9.24, 12.57@}}
794 [3.14 6.28 9.42 12.57]
797 @math{(\matrix{3.14 & 6.28 & 9.42 & 12.57})}
800 @item @t{@{1.41; 1.73; 2@}}
804 @t{[1.41] @* [1.73] @* [2.00]}
807 @math{(\matrix{1.41 & 1.73 & 2.00})}
815 Curly braces are not limited to holding numeric literals. They can
816 contain calculations, and they can paste together matrices and vectors
817 in any way as long as the result is rectangular. For example, if
818 @samp{m} is matrix @code{@{1, 2; 3, 4@}}, @samp{r} is row vector
819 @code{@{5, 6@}}, and @samp{c} is column vector @code{@{7, 8@}}, then
820 curly braces can be used as follows:
822 @multitable @columnfractions .4 .05 .4
823 @item @t{@{m, c; r, 10@}}
827 @t{[1 2 7] @* [3 4 8] @* [5 6 10]}
830 @math{\left(\matrix{1 & 2 & 7 \cr 3 & 4 & 8 \cr 5 & 6 & 10}\right)}
833 @item @t{@{c, 2 * c, T(r)@}}
837 @t{[7 14 5] @* [8 16 6]}
840 @math{\left(\matrix{7 & 14 & 5 \cr 8 & 16 & 6}\right)}
844 The final example above uses the transposition function @code{T}.
846 @node Matrix Sequence Operator
847 @subsubsection The Integer Sequence Operator @samp{:}
849 The syntax @code{@var{first}:@var{last}:@var{step}} yields a row
850 vector of consecutive integers from @var{first} to @var{last} counting
851 by @var{step}. The final @code{:@var{step}} is optional and
852 defaults to 1 when omitted.
854 Each of @var{first}, @var{last}, and @var{step} must be a scalar and
855 should be an integer (any fractional part is discarded). Because
856 @samp{:} has a high precedence, operands other than numeric literals
857 must usually be parenthesized.
859 When @var{step} is positive (or omitted) and @math{@var{end} <
860 @var{start}}, or if @var{step} is negative and @math{@var{end} >
861 @var{start}}, then the result is an empty matrix. If @var{step} is 0,
862 then @pspp{} reports an error.
864 Here are some examples:
866 @multitable @columnfractions .4 .05 .4
867 @item @t{1:6} @tab @result{} @tab @t{@{1, 2, 3, 4, 5, 6@}}
868 @item @t{1:6:2} @tab @result{} @tab @t{@{1, 3, 5@}}
869 @item @t{-1:-5:-1} @tab @result{} @tab @t{@{-1, -2, -3, -4, -5@}}
870 @item @t{-1:-5} @tab @result{} @tab @t{@{@}}
871 @item @t{2:1:0} @tab @result{} @tab (error)
874 @node Matrix Index Operator
875 @subsubsection The Index Operator @code{()}
877 The result of the submatrix or indexing operator, written
878 @code{@var{m}(@var{rindex}, @var{cindex})}, contains the rows of
879 @var{m} whose indexes are given in vector @var{rindex} and the columns
880 whose indexes are given in vector @var{cindex}.
882 In the simplest case, if @var{rindex} and @var{cindex} are both
883 scalars, the result is also a scalar:
885 @multitable @columnfractions .4 .05 .4
886 @item @t{@{10, 20; 30, 40@}(1, 1)} @tab @result{} @tab @t{10}
887 @item @t{@{10, 20; 30, 40@}(1, 2)} @tab @result{} @tab @t{20}
888 @item @t{@{10, 20; 30, 40@}(2, 1)} @tab @result{} @tab @t{30}
889 @item @t{@{10, 20; 30, 40@}(2, 2)} @tab @result{} @tab @t{40}
892 If the index arguments have multiple elements, then the result
893 includes multiple rows or columns:
895 @multitable @columnfractions .4 .05 .4
896 @item @t{@{10, 20; 30, 40@}(1:2, 1)} @tab @result{} @tab @t{@{10; 30@}}
897 @item @t{@{10, 20; 30, 40@}(2, 1:2)} @tab @result{} @tab @t{@{30, 40@}}
898 @item @t{@{10, 20; 30, 40@}(1:2, 1:2)} @tab @result{} @tab @t{@{10, 20; 30, 40@}}
901 The special argument @samp{:} may stand in for all the rows or columns
902 in the matrix being indexed, like this:
904 @multitable @columnfractions .4 .05 .4
905 @item @t{@{10, 20; 30, 40@}(:, 1)} @tab @result{} @tab @t{@{10; 30@}}
906 @item @t{@{10, 20; 30, 40@}(2, :)} @tab @result{} @tab @t{@{30, 40@}}
907 @item @t{@{10, 20; 30, 40@}(:, :)} @tab @result{} @tab @t{@{10, 20; 30, 40@}}
910 The index arguments do not have to be in order, and they may contain
911 repeated values, like this:
913 @multitable @columnfractions .4 .05 .4
914 @item @t{@{10, 20; 30, 40@}(@{2, 1@}, 1)} @tab @result{} @tab @t{@{30; 10@}}
915 @item @t{@{10, 20; 30, 40@}(2, @{2; 2; 1@})} @tab @result{} @tab @t{@{40, 40, 30@}}
916 @item @t{@{10, 20; 30, 40@}(2:1:-1, :)} @tab @result{} @tab @t{@{30, 40; 10, 20@}}
919 When the matrix being indexed is a row or column vector, only a single
920 index argument is needed, like this:
922 @multitable @columnfractions .4 .05 .4
923 @item @t{@{11, 12, 13, 14, 15@}(2:4)} @tab @result{} @tab @t{@{12, 13, 14@}}
924 @item @t{@{11; 12; 13; 14; 15@}(2:4)} @tab @result{} @tab @t{@{12; 13; 14@}}
927 When an index is not an integer, @pspp{} discards the fractional part.
928 It is an error for an index to be less than 1 or greater than the
929 number of rows or columns:
931 @multitable @columnfractions .4 .05 .4
932 @item @t{@{11, 12, 13, 14@}(@{2.5, 4.6@})} @tab @result{} @tab @t{@{12, 14@}}
933 @item @t{@{11; 12; 13; 14@}(0)} @tab @result{} @tab (error)
936 @node Matrix Unary Arithmetic Operators
937 @subsubsection Unary Arithmetic Operators
939 The unary @samp{-} operator inverts the sign of each element in its
940 argument. The unary @samp{+} operator has no effect:
942 @multitable @columnfractions .4 .05 .4
943 @item @t{-@{1, -2; 3, -4@}} @tab @result{} @tab @t{@{-1, 2; -3, 4@}}
944 @item @t{+@{1, -2; 3, -4@}} @tab @result{} @tab @t{@{1, -2; 3, -4@}}
947 @node Matrix Elementwise Operators
948 @subsubsection Elementwise Operators
950 The elementwise operators require their operands to be matrices with
951 the same dimensions. Alternatively, if one operand is a scalar, then
952 its value is treated as if it were duplicated to the dimensions of the
953 other operand. The result is a matrix of the same size as the
954 operands, in which each element is the result of the applying the
955 operator to the corresponding elements of the operands.
957 The elementwise operators are listed below.
961 The arithmetic operators, for familiar arithmetic operations:
971 Multiplication, if one operand is a scalar. (Otherwise this is matrix
972 multiplication, described below.)
974 @item @code{/} or @code{&/}
985 The relational operators, whose results are 1 when a comparison is
986 true and 0 when it is false:
989 @item @code{<} or @code{LT}
992 @item @code{<=} or @code{LE}
995 @item @code{=} or @code{EQ}
998 @item @code{>} or @code{GT}
1001 @item @code{>=} or @code{GE}
1002 Greater than or equal.
1004 @item @code{<>} or @code{~=} or @code{NE}
1009 The logical operators, which treat positive operands as true and
1010 nonpositive operands as false. They yield 0 for false and 1 for true:
1014 True if its single operand is false.
1017 True if both operands are true.
1020 True if at least one operand is true.
1023 True if exactly one operand is true.
1027 @node Matrix Multiplication Operator
1028 @subsubsection The Matrix Multiplication Operator @samp{*}
1030 If @code{A} is an @math{@var{m}@times{}@var{n}} matrix and @code{B} is
1031 an @math{@var{n}@times{}@var{p}} matrix, then @code{A*B} is the
1032 @math{@var{m}@times{}@var{p}} matrix multiplication product @code{C}.
1033 @pspp{} reports an error if the number of columns in @code{A} differs
1034 from the number of rows in @code{B}.
1036 The @code{*} operator performs elementwise multiplication (see above)
1037 if one of its operands is a scalar.
1039 No built-in operator yields the inverse of matrix multiplication.
1040 Instead, multiply by the result of @code{INV} or @code{GINV}.
1044 @multitable @columnfractions .4 .05 .4
1045 @item @t{@{1, 2, 3@} * @{4; 5; 6@}} @tab @result{} @tab @t{32}
1046 @item @t{@{4; 5; 6@} * @{1, 2, 3@}} @tab @result{} @tab @t{@{4,@w{ } 8, 12; @*@w{ }5, 10, 15; @*@w{ }6, 12, 18@}}
1049 @node Matrix Exponentiation Operator
1050 @subsubsection The Matrix Exponentiation Operator @code{**}
1052 The result of @code{A**B} is defined as follows when @code{A} is a
1053 square matrix and @code{B} is an integer scalar:
1057 For @code{B > 0}, @code{A**B} is @code{A*@dots{}*A}, where there are
1058 @code{B} @samp{A}s. (@pspp{} implements this efficiently for large
1059 @code{B}, using exponentiation by squaring.)
1062 For @code{B < 0}, @code{A**B} is @code{INV(A**(-B))}.
1065 For @code{B = 0}, @code{A**B} is the identity matrix.
1069 @pspp{} reports an error if @code{A} is not square or @code{B} is not