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.
618 @dots{}@i{matrix commands}@dots{}
623 The following basic matrix commands are supported:
626 @t{COMPUTE} @i{variable}[@t{(}@i{index}[@t{,}@i{index}]@t{)}]@t{=}@i{expression}@t{.}
627 @t{CALL} @i{procedure}@t{(}@i{argument}@t{,} @dots{}).
628 @t{PRINT} [@i{expression}]
629 [@t{/FORMAT}@t{=}@i{format}]
630 [@t{/TITLE}@t{=}@i{title}]
631 [@t{/SPACE}@t{=}@{@t{NEWPAGE} @math{|} @i{n}@}]
632 [@{@t{/RLABELS}@t{=}@i{string}@dots{} @math{|} @t{/RNAMES}@t{=}@i{expression}@}]
633 [@{@t{/CLABELS}@t{=}@i{string}@dots{} @math{|} @t{/CNAMES}@t{=}@i{expression}@}]@t{.}
637 The following matrix commands offer support for flow control:
640 @t{DO IF} @i{expression}@t{.}
641 @dots{}@i{matrix commands}@dots{}
642 [@t{ELSE IF} @i{expression}@t{.}
643 @dots{}@i{matrix commands}@dots{}]@dots{}
645 @dots{}@i{matrix commands}@dots{}]
648 @t{LOOP} [@i{var}@t{=}@i{first} @t{TO} @i{last} [@t{BY} @i{step}]] [@t{IF} @i{expression}]@t{.}
649 @dots{}@i{matrix commands}@dots{}
650 @t{END LOOP} [@t{IF} @i{expression}]@t{.}
656 The following matrix commands support matrix input and output:
659 @t{READ} @i{variable}[@t{(}@i{index}[@t{,}@i{index}]@t{)}]
660 [@t{/FILE}@t{=}@i{file}]
661 @t{/FIELD}@t{=}@i{first} @t{TO} @i{last} [@t{BY} @i{width}]
662 [@t{/SIZE}@t{=}@i{expression}]
663 [@t{/MODE}@t{=}@{@t{RECTANGULAR} @math{|} @t{SYMMETRIC}@}]
665 [@t{/FORMAT}@t{=}@i{format}]@t{.}
666 @t{WRITE} @i{expression}
667 [@t{/OUTFILE}@t{=}@i{file}]
668 @t{/FIELD}@t{=}@i{first} @t{TO} @i{last} [@t{BY} @i{width}]
669 [@t{/MODE}@t{=}@{@t{RECTANGULAR} @math{|} @t{TRIANGULAR}@}]
671 [@t{/FORMAT}@t{=}@i{format}]@t{.}
672 @t{GET} @i{variable}[@t{(}@i{index}[@t{,}@i{index}]@t{)}]
673 [@t{/FILE}@t{=}@{@i{file} @math{|} @t{*}@}]
674 [@t{/VARIABLES}@t{=}@i{variable}@dots{}]
675 [@t{/NAMES}@t{=}@i{expression}]
676 [@t{/MISSING}@t{=}@{@t{ACCEPT} @math{|} @t{OMIT} @math{|} @i{number}@}]
677 [@t{/SYSMIS}@t{=}@{@t{OMIT} @math{|} @i{number}@}]@t{.}
678 @t{SAVE} @i{expression}
679 [@t{/OUTFILE}@t{=}@{@i{file} @math{|} @t{*}@}]
680 [@t{/VARIABLES}@t{=}@i{variable}@dots{}]
681 [@t{/NAMES}@t{=}@i{expression}]
682 [@t{/STRINGS}@t{=}@i{variable}@dots{}]@t{.}
683 @t{MGET} [@t{/FILE}@t{=}@i{file}]
684 [@t{/TYPE}@t{=}@{@t{COV} @math{|} @t{CORR} @math{|} @t{MEAN} @math{|} @t{STDDEV} @math{|} @t{N} @math{|} @t{COUNT}@}]@t{.}
685 @t{MSAVE} @i{expression}
686 @t{/TYPE}@t{=}@{@t{COV} @math{|} @t{CORR} @math{|} @t{MEAN} @math{|} @t{STDDEV} @math{|} @t{N} @math{|} @t{COUNT}@}
687 [@t{/OUTFILE}@t{=}@i{file}]
688 [@t{/VARIABLES}@t{=}@i{variable}@dots{}]
689 [@t{/SNAMES}@t{=}@i{variable}@dots{}]
690 [@t{/SPLIT}@t{=}@i{expression}]
691 [@t{/FNAMES}@t{=}@i{variable}@dots{}]
692 [@t{/FACTOR}@t{=}@i{expression}]@t{.}
696 The following matrix commands provide additional support:
699 @t{DISPLAY} [@{@t{DICTIONARY} @math{|} @t{STATUS}@}]@t{.}
700 @t{RELEASE} @i{variable}@dots{}@t{.}
703 @code{MATRIX} and @code{END MATRIX} enclose a special @pspp{}
704 sub-language, called the matrix language. The matrix language does
705 not require an active dataset to be defined and only a few of the
706 matrix language commands work with any datasets that are defined.
707 Each instance of @code{MATRIX}@dots{}@code{END MATRIX} is a separate
708 program whose state is independent of any instance, so that variables
709 declared within a matrix program are forgotten at its end.
711 The matrix language works with matrices, where a @dfn{matrix} is a
712 rectangular array of real numbers. An @math{@var{n}@times{}@var{m}}
713 matrix has @var{n} rows and @var{m} columns. Some special cases are
714 important: a @math{@var{n}@times{}1} matrix is a @dfn{column vector},
715 a @math{1@times{}@var{n}} is a @dfn{row vector}, and a
716 @math{1@times{}1} matrix is a @dfn{scalar}.
718 The matrix language also has limited support for matrices that contain
719 8-byte strings instead of numbers. Strings longer than 8 bytes are
720 truncated, and shorter strings are padded with spaces. String
721 matrices are mainly useful for labeling rows and columns when printing
722 numerical matrices with the @code{MATRIX PRINT} command. Arithmetic
723 operations on string matrices will not produce useful results. The
724 user should not mix strings and numbers within a matrix.
726 The matrix language does not work with cases. A variable in the
727 matrix language represents a single matrix.
729 The matrix language does not support missing values.
731 @code{MATRIX} is a procedure, so it cannot be enclosed inside @code{DO
732 IF}, @code{LOOP}, etc.
734 Macros may be used within a matrix program, and macros may expand to
735 include entire matrix programs. The @code{DEFINE} command may not
736 appear within a matrix program. @xref{DEFINE}, for more information
739 The following sections describe the details of the matrix language:
740 first, the syntax of matrix expressions, then each of the supported
741 commands. The @code{COMMENT} command (@pxref{COMMENT}) is also
744 @node Matrix Operators
745 @subsection Matrix Operators
747 Many matrix commands use expressions. A matrix expression may use the
748 following operators, listed in descending order of operator
749 precedence. Within a single level, operators associate from left to
754 Function call @t{()} and matrix construction @t{@{@}}
760 Unary @t{+} and @t{-}
763 Integer sequence @t{:}
766 Exponentiation @t{**} and @t{&**}
769 Multiplication @t{*} and @t{&*}, and division @t{/} and @t{&/}
772 Addition @t{+} and subtraction @t{-}
775 Relational @t{< <= = >= > <>}
784 Logical @t{OR} and @t{XOR}
787 @xref{Matrix Functions}, for the available matrix functions. The
788 remaining operators are described in more detail below.
790 @node Matrix Construction Operator
791 @subsubsection Matrix Construction Operator @t{@{@}}
793 Use the @t{@{}@t{@}} operator to construct matrices. Within
794 the curly braces, commas separate elements within a row and semicolons
795 separate rows. The following examples show a @math{2@times{}3}
796 matrix, a @math{1@times{}4} row vector, a @math{3@times{}1} column
797 vector, and a scalar.
799 @multitable @columnfractions .4 .05 .4
800 @item @t{@{1, 2, 3; 4, 5, 6@}}
804 @t{[1 2 3] @* [4 5 6]}
807 @math{\left(\matrix{1 & 2 & 3 \cr 4 & 5 & 6}\right)}
810 @item @t{@{3.14, 6.28, 9.24, 12.57@}}
814 [3.14 6.28 9.42 12.57]
817 @math{(\matrix{3.14 & 6.28 & 9.42 & 12.57})}
820 @item @t{@{1.41; 1.73; 2@}}
824 @t{[1.41] @* [1.73] @* [2.00]}
827 @math{(\matrix{1.41 & 1.73 & 2.00})}
835 Curly braces are not limited to holding numeric literals. They can
836 contain calculations, and they can paste together matrices and vectors
837 in any way as long as the result is rectangular. For example, if
838 @samp{m} is matrix @code{@{1, 2; 3, 4@}}, @samp{r} is row vector
839 @code{@{5, 6@}}, and @samp{c} is column vector @code{@{7, 8@}}, then
840 curly braces can be used as follows:
842 @multitable @columnfractions .4 .05 .4
843 @item @t{@{m, c; r, 10@}}
847 @t{[1 2 7] @* [3 4 8] @* [5 6 10]}
850 @math{\left(\matrix{1 & 2 & 7 \cr 3 & 4 & 8 \cr 5 & 6 & 10}\right)}
853 @item @t{@{c, 2 * c, T(r)@}}
857 @t{[7 14 5] @* [8 16 6]}
860 @math{\left(\matrix{7 & 14 & 5 \cr 8 & 16 & 6}\right)}
864 The final example above uses the transposition function @code{T}.
866 @node Matrix Sequence Operator
867 @subsubsection Integer Sequence Operator @samp{:}
869 The syntax @code{@var{first}:@var{last}:@var{step}} yields a row
870 vector of consecutive integers from @var{first} to @var{last} counting
871 by @var{step}. The final @code{:@var{step}} is optional and
872 defaults to 1 when omitted.
874 Each of @var{first}, @var{last}, and @var{step} must be a scalar and
875 should be an integer (any fractional part is discarded). Because
876 @samp{:} has a high precedence, operands other than numeric literals
877 must usually be parenthesized.
879 When @var{step} is positive (or omitted) and @math{@var{end} <
880 @var{start}}, or if @var{step} is negative and @math{@var{end} >
881 @var{start}}, then the result is an empty matrix. If @var{step} is 0,
882 then @pspp{} reports an error.
884 Here are some examples:
886 @multitable @columnfractions .4 .05 .4
887 @item @t{1:6} @tab @result{} @tab @t{@{1, 2, 3, 4, 5, 6@}}
888 @item @t{1:6:2} @tab @result{} @tab @t{@{1, 3, 5@}}
889 @item @t{-1:-5:-1} @tab @result{} @tab @t{@{-1, -2, -3, -4, -5@}}
890 @item @t{-1:-5} @tab @result{} @tab @t{@{@}}
891 @item @t{2:1:0} @tab @result{} @tab (error)
894 @node Matrix Index Operator
895 @subsubsection Index Operator @code{()}
897 The result of the submatrix or indexing operator, written
898 @code{@var{m}(@var{rindex}, @var{cindex})}, contains the rows of
899 @var{m} whose indexes are given in vector @var{rindex} and the columns
900 whose indexes are given in vector @var{cindex}.
902 In the simplest case, if @var{rindex} and @var{cindex} are both
903 scalars, the result is also a scalar:
905 @multitable @columnfractions .4 .05 .4
906 @item @t{@{10, 20; 30, 40@}(1, 1)} @tab @result{} @tab @t{10}
907 @item @t{@{10, 20; 30, 40@}(1, 2)} @tab @result{} @tab @t{20}
908 @item @t{@{10, 20; 30, 40@}(2, 1)} @tab @result{} @tab @t{30}
909 @item @t{@{10, 20; 30, 40@}(2, 2)} @tab @result{} @tab @t{40}
912 If the index arguments have multiple elements, then the result
913 includes multiple rows or columns:
915 @multitable @columnfractions .4 .05 .4
916 @item @t{@{10, 20; 30, 40@}(1:2, 1)} @tab @result{} @tab @t{@{10; 30@}}
917 @item @t{@{10, 20; 30, 40@}(2, 1:2)} @tab @result{} @tab @t{@{30, 40@}}
918 @item @t{@{10, 20; 30, 40@}(1:2, 1:2)} @tab @result{} @tab @t{@{10, 20; 30, 40@}}
921 The special argument @samp{:} may stand in for all the rows or columns
922 in the matrix being indexed, like this:
924 @multitable @columnfractions .4 .05 .4
925 @item @t{@{10, 20; 30, 40@}(:, 1)} @tab @result{} @tab @t{@{10; 30@}}
926 @item @t{@{10, 20; 30, 40@}(2, :)} @tab @result{} @tab @t{@{30, 40@}}
927 @item @t{@{10, 20; 30, 40@}(:, :)} @tab @result{} @tab @t{@{10, 20; 30, 40@}}
930 The index arguments do not have to be in order, and they may contain
931 repeated values, like this:
933 @multitable @columnfractions .4 .05 .4
934 @item @t{@{10, 20; 30, 40@}(@{2, 1@}, 1)} @tab @result{} @tab @t{@{30; 10@}}
935 @item @t{@{10, 20; 30, 40@}(2, @{2; 2; 1@})} @tab @result{} @tab @t{@{40, 40, 30@}}
936 @item @t{@{10, 20; 30, 40@}(2:1:-1, :)} @tab @result{} @tab @t{@{30, 40; 10, 20@}}
939 When the matrix being indexed is a row or column vector, only a single
940 index argument is needed, like this:
942 @multitable @columnfractions .4 .05 .4
943 @item @t{@{11, 12, 13, 14, 15@}(2:4)} @tab @result{} @tab @t{@{12, 13, 14@}}
944 @item @t{@{11; 12; 13; 14; 15@}(2:4)} @tab @result{} @tab @t{@{12; 13; 14@}}
947 When an index is not an integer, @pspp{} discards the fractional part.
948 It is an error for an index to be less than 1 or greater than the
949 number of rows or columns:
951 @multitable @columnfractions .4 .05 .4
952 @item @t{@{11, 12, 13, 14@}(@{2.5, 4.6@})} @tab @result{} @tab @t{@{12, 14@}}
953 @item @t{@{11; 12; 13; 14@}(0)} @tab @result{} @tab (error)
956 @node Matrix Unary Operators
957 @subsubsection Unary Operators
959 The unary operators take a single operand of any dimensions and
960 operate on each of its elements independently. The unary operators
965 Inverts the sign of each element.
971 Logical inversion: each positive value becomes 0 and each zero or
972 negative value becomes 1.
977 @multitable @columnfractions .4 .05 .4
978 @item @t{-@{1, -2; 3, -4@}} @tab @result{} @tab @t{@{-1, 2; -3, 4@}}
979 @item @t{+@{1, -2; 3, -4@}} @tab @result{} @tab @t{@{1, -2; 3, -4@}}
980 @item @t{NOT @{1, 0; -1, 1@}} @tab @result{} @tab @t{@{0, 1; 1, 0@}}
983 @node Matrix Elementwise Binary Operators
984 @subsubsection Elementwise Binary Operators
986 The elementwise binary operators require their operands to be matrices
987 with the same dimensions. Alternatively, if one operand is a scalar,
988 then its value is treated as if it were duplicated to the dimensions
989 of the other operand. The result is a matrix of the same size as the
990 operands, in which each element is the result of the applying the
991 operator to the corresponding elements of the operands.
993 The elementwise binary operators are listed below.
997 The arithmetic operators, for familiar arithmetic operations:
1007 Multiplication, if one operand is a scalar. (Otherwise this is matrix
1008 multiplication, described below.)
1010 @item @code{/} or @code{&/}
1021 The relational operators, whose results are 1 when a comparison is
1022 true and 0 when it is false:
1025 @item @code{<} or @code{LT}
1028 @item @code{<=} or @code{LE}
1031 @item @code{=} or @code{EQ}
1034 @item @code{>} or @code{GT}
1037 @item @code{>=} or @code{GE}
1038 Greater than or equal.
1040 @item @code{<>} or @code{~=} or @code{NE}
1045 The logical operators, which treat positive operands as true and
1046 nonpositive operands as false. They yield 0 for false and 1 for true:
1050 True if both operands are true.
1053 True if at least one operand is true.
1056 True if exactly one operand is true.
1062 @multitable @columnfractions .4 .05 .4
1063 @item @t{1 + 2} @tab @result{} @tab @t{3}
1064 @item @t{1 + @{3; 4@}} @tab @result{} @tab @t{@{4; 5@}}
1065 @item @t{@{66, 77; 88, 99@} + 5} @tab @result{} @tab @t{@{71, 82; 93, 104@}}
1066 @item @t{@{4, 8; 3, 7@} + @{1, 0; 5, 2@}} @tab @result{} @tab @t{@{5, 8; 8, 9@}}
1067 @item @t{@{1, 2; 3, 4@} < @{4, 3; 2, 1@}} @tab @result{} @tab @t{@{1, 1; 0, 0@}}
1068 @item @t{@{1, 3; 2, 4@} >= 3} @tab @result{} @tab @t{@{0, 1; 0, 1@}}
1069 @item @t{@{0, 0; 1, 1@} AND @{0, 1; 0, 1@}} @tab @result{} @tab @t{@{0, 0; 0, 1@}}
1072 @node Matrix Multiplication Operator
1073 @subsubsection Matrix Multiplication Operator @samp{*}
1075 If @code{A} is an @math{@var{m}@times{}@var{n}} matrix and @code{B} is
1076 an @math{@var{n}@times{}@var{p}} matrix, then @code{A*B} is the
1077 @math{@var{m}@times{}@var{p}} matrix multiplication product @code{C}.
1078 @pspp{} reports an error if the number of columns in @code{A} differs
1079 from the number of rows in @code{B}.
1081 The @code{*} operator performs elementwise multiplication (see above)
1082 if one of its operands is a scalar.
1084 No built-in operator yields the inverse of matrix multiplication.
1085 Instead, multiply by the result of @code{INV} or @code{GINV}.
1089 @multitable @columnfractions .4 .05 .4
1090 @item @t{@{1, 2, 3@} * @{4; 5; 6@}} @tab @result{} @tab @t{32}
1091 @item @t{@{4; 5; 6@} * @{1, 2, 3@}} @tab @result{} @tab @t{@{4,@w{ } 8, 12; @*@w{ }5, 10, 15; @*@w{ }6, 12, 18@}}
1094 @node Matrix Exponentiation Operator
1095 @subsubsection Matrix Exponentiation Operator @code{**}
1097 The result of @code{A**B} is defined as follows when @code{A} is a
1098 square matrix and @code{B} is an integer scalar:
1102 For @code{B > 0}, @code{A**B} is @code{A*@dots{}*A}, where there are
1103 @code{B} @samp{A}s. (@pspp{} implements this efficiently for large
1104 @code{B}, using exponentiation by squaring.)
1107 For @code{B < 0}, @code{A**B} is @code{INV(A**(-B))}.
1110 For @code{B = 0}, @code{A**B} is the identity matrix.
1114 @pspp{} reports an error if @code{A} is not square or @code{B} is not
1119 @multitable @columnfractions .4 .05 .4
1120 @item @t{@{2, 5; 1, 4@}**3} @tab @result{} @tab @t{@{48, 165; 33, 114@}}
1121 @item @t{@{2, 5; 1, 4@}**0} @tab @result{} @tab @t{@{1, 0; 0, 1@}}
1122 @item @t{10*@{4, 7; 2, 6@}**-1} @tab @result{} @tab @t{@{6, -7; -2, 4@}}
1125 @node Matrix Functions
1126 @subsection Matrix Functions
1128 The matrix language support numerous functions in multiple categories.
1129 The following subsections document each of the currently supported
1130 functions. The first letter of each parameter's name indicate the
1131 required argument type:
1138 A nonnegative integer scalar. (Non-integers are accepted and silently
1139 rounded down to the nearest integer.)
1142 A row or column vector.
1148 @node Matrix Elementwise Functions
1149 @subsubsection Elementwise Functions
1151 These functions act on each element of their argument independently,
1152 like the elementwise operators (@pxref{Matrix Elementwise Binary
1155 @deffn {Matrix Function} ABS (@var{M})
1156 Takes the absolute value of each element of @var{M}.
1158 @t{ABS(@{-1, 2; -3, 0@}) @result{} @{1, 2; 3, 0@}}
1161 @deffn {Matrix Function} ARSIN (@var{M})
1162 @deffnx {Matrix Function} ARTAN (@var{M})
1163 Computes the inverse sine or tangent, respectively, of each element in
1164 @var{M}. The results are in radians, between @math{-\pi/2} and
1165 @math{+\pi/2}, inclusive.
1167 The value of @math{\pi} can be computed as @code{4*ARTAN(1)}.
1170 @deffn {Matrix Function} COS (@var{M})
1171 @deffnx {Matrix Function} SIN (@var{M})
1172 Computes the cosine or sine, respectively, of each element in @var{M},
1173 which must be in radians.
1176 @deffn {Matrix Function} EXP (@var{M})
1177 Computes @math{e^x} for each element @var{x} in @var{M}.
1180 @deffn {Matrix Function} LG10 (@var{M})
1181 @deffnx {Matrix Function} LN (@var{M})
1182 Takes the logarithm with base 10 or base @math{e}, respectively, of
1183 each element in @var{M}.
1186 @deffn {Matrix Function} MOD (@var{M}, @var{s})
1187 Takes each element in @var{M} modulo nonzero scalar value @var{s},
1188 that is, the remainder of division by @var{s}. The sign of the result
1189 is the same as the sign of the dividend.
1192 @deffn {Matrix Function} RND (@var{M})
1193 @deffnx {Matrix Function} TRUNC (@var{M})
1194 Rounds each element of @var{M} to an integer. @code{RND} rounds to
1195 the nearest integer, with halves rounded to even integers, and
1196 @code{TRUNC} rounds toward zero.
1199 @deffn {Matrix Function} SQRT (@var{M})
1200 Takes the square root of each element of @var{M}, which must not be
1204 @node Matrix Logical Functions
1205 @subsubsection Logical Functions
1207 @deffn {Matrix Function} ALL (@var{M})
1208 Returns a scalar with value 1 if all of the elements in @var{M} are
1209 nonzero, or 0 if at least one element is zero.
1212 @deffn {Matrix Function} ANY (@var{M})
1213 Returns a scalar with value 1 if any of the elements in @var{M} is
1214 nonzero, or 0 if all of them are zero.
1217 @node Matrix Construction Functions
1218 @subsubsection Matrix Construction Functions
1220 @deffn {Matrix Function} BLOCK (@var{M1}, @dots{}, @var{Mn})
1221 Returns a block diagonal matrix with as many rows as the sum of its
1222 arguments' row counts and as many columns as the sum of their columns.
1223 Each argument matrix is placed along the main diagonal of the result,
1224 and all other elements are zero.
1227 @deffn {Matrix Function} IDENT (@var{n})
1228 @deffnx {Matrix Function} IDENT (@var{nr}, @var{nc})
1229 Returns an identity matrix, whose main diagonal elements are one and
1230 whose other elements are zero. The returned matrix has @var{n} rows
1231 and columns or @var{nr} rows and @var{nc} columns, respectively.
1234 @deffn {Matrix Function} MAGIC (@var{n})
1235 Returns an @math{@var{n}@times{}@var{n}} matrix that contains each of
1236 the integers @math{1@dots{}@var{n}} once, in which each column, each
1237 row, and each diagonal sums to @math{n(n^2+1)/2}. There are many
1238 magic squares with given dimensions, but this function always returns
1239 the same one for a given value of @var{n}.
1242 @deffn {Matrix Function} MAKE (@var{nr}, @var{nc}, @var{s})
1243 Returns an @math{@var{nr}@times{}@var{nc}} matrix whose elements are
1247 @deffn {Matrix Function} MDIAG (@var{V})
1248 @anchor{MDIAG} Given @var{n}-element vector @var{V}, returns a
1249 @math{@var{n}@times{}@var{n}} matrix whose main diagonal is copied
1250 from @var{V}. The other elements in the returned vector are zero.
1252 Use @code{CALL SETDIAG} (@pxref{CALL SETDIAG}) to replace the main
1253 diagonal of a matrix in-place.
1256 @deffn {Matrix Function} RESHAPE (@var{M}, @var{nr}, @var{nc})
1257 Returns an @math{@var{nr}@times{}@var{nc}} matrix whose elements come
1258 from @var{M}, which must have the same number of elements as the new
1259 matrix, copying elements from @var{M} to the new matrix row by row.
1262 @deffn {Matrix Function} T (@var{M})
1263 @deffnx {Matrix Function} TRANSPOS (@var{M})
1264 Returns @var{M} with rows exchanged for columns.
1267 @deffn {Matrix Function} UNIFORM (@var{nr}, @var{nc})
1268 Returns a @math{@var{nr}@times{}@var{nc}} matrix in which each element
1269 is randomly chosen from a uniform distribution of real numbers between
1273 @node Matrix Minimum and Maximum and Sum Functions
1274 @subsubsection Minimum, Maximum, and Sum Functions
1276 @deffn {Matrix Function} CMIN (@var{M})
1277 @deffnx {Matrix Function} CMAX (@var{M})
1278 @deffnx {Matrix Function} CSUM (@var{M})
1279 @deffnx {Matrix Function} CSSQ (@var{M})
1280 Returns a row vector with the same number of columns as @var{M}, in
1281 which each element is the minimum, maximum, sum, or sum of squares,
1282 respectively, of the elements in the same column of @var{M}.
1285 @deffn {Matrix Function} MMIN (@var{M})
1286 @deffnx {Matrix Function} MMAX (@var{M})
1287 @deffnx {Matrix Function} MSUM (@var{M})
1288 @deffnx {Matrix Function} MSSQ (@var{M})
1289 Returns the minimum, maximum, sum, or sum of squares, respectively, of
1290 the elements of @var{M}.
1293 @deffn {Matrix Function} RMIN (@var{M})
1294 @deffnx {Matrix Function} RMAX (@var{M})
1295 @deffnx {Matrix Function} RSUM (@var{M})
1296 @deffnx {Matrix Function} RSSQ (@var{M})
1297 Returns a column vector with the same number of rows as @var{M}, in
1298 which each element is the minimum, maximum, sum, or sum of squares,
1299 respectively, of the elements in the same row of @var{M}.
1302 @deffn {Matrix Function} SSCP (@var{M})
1303 Returns @math{@var{M}^T @times{} @var{M}}.
1306 @deffn {Matrix Function} TRACE (@var{M})
1307 Returns the sum of the elements along @var{M}'s main diagonal,
1308 equivalent to @code{MSUM(DIAG(@var{M}))}.
1312 @node Matrix Property Functions
1313 @subsubsection Matrix Property Functions
1315 @deffn {Matrix Function} NROW (@var{M})
1316 @deffnx {Matrix Function} NCOL (@var{M})
1317 Returns the number of row or columns, respectively, in @var{M}.
1320 @deffn {Matrix Function} DIAG (@var{M})
1321 Returns a column vector containing a copy of @var{M}'s main diagonal.
1322 The vector's length is the lesser of @code{NCOL(@var{M})} and
1323 @code{NROW(@var{M})}.
1326 @node Matrix Rank Ordering Functions
1327 @subsubsection Matrix Rank Ordering Functions
1329 The @code{GRADE} and @code{RANK} functions each take a matrix @var{M}
1330 and return a matrix @var{r} with the same dimensions. Each element in
1331 @var{r} ranges between 1 and the number of elements @var{n} in
1332 @var{M}, inclusive. When the elements in @var{M} all have unique
1333 values, both of these functions yield the same results: the smallest
1334 element in @var{M} corresponds to value 1 in @var{r}, the next
1335 smallest to 2, and so on, up to the largest to @var{n}. When multiple
1336 elements in @var{M} have the same value, these functions use different
1337 rules for handling the ties.
1339 @deffn {Matrix Function} GRADE (@var{M})
1340 Returns a ranking of @var{M}, turning duplicate values into sequential
1341 ranks. The returned matrix always contains each of the integers 1
1342 through the number of elements in the matrix exactly once.
1344 @t{GRADE(@{1, 0, 3; 3, 1, 2; 3, 0, 5@})} @result{} @t{@{3, 1, 6; 7, 4, 5; 8, 2, 9@}}
1347 @deffn {Matrix Function} RNKORDER (@var{M})
1348 Returns a ranking of @var{M}, turning duplicate values into the mean
1349 of their sequential ranks.
1351 @t{RNKORDER(@{1, 0, 3; 3, 1, 2; 3, 0, 5@})} @*@w{ }@result{} @t{@{3.5, 1.5, 7; 7, 3.5, 5; 7, 1.5, 9@}}
1355 One may use @code{GRADE} to sort a vector:
1358 COMPUTE v(GRADE(v))=v. /* Sort v in ascending order.
1359 COMPUTE v(GRADE(-v))=v. /* Sort v in descending order.
1362 @node Matrix Algebra Functions
1363 @subsubsection Matrix Algebra Functions
1365 @deffn {Matrix Function} CHOL (@var{M})
1366 Matrix @var{M} must be an @math{@var{n}@times{}@var{n}} symmetric
1367 positive-definite matrix. Returns an @math{@var{n}@times{}@var{n}}
1368 matrix @var{B} such that @math{@var{B}^T@times{}@var{B}=@var{M}}.
1371 @deffn {Matrix Function} DESIGN (@var{M})
1372 Returns a design matrix for @var{M}. The design matrix has the same
1373 number of rows as @var{M}. Each column @var{c} in @var{M}, from left
1374 to right, yields a group of columns in the output. For each unique
1375 value @var{v} in @var{c}, from top to bottom, add a column to the
1376 output in which @var{v} becomes 1 and other values become 0.
1378 @pspp{} issues a warning if a column only contains a single unique value.
1381 @t{DESIGN(@{1; 2; 3@}) @result{} @{1, 0, 0; 0, 1, 0; 0, 0, 1@}}
1382 @t{DESIGN(@{5; 8; 5@}) @result{} @{1, 0; 0, 1; 1, 0@}}
1383 @t{DESIGN(@{1, 5; 2, 8; 3, 5@})}
1384 @result{} @t{@{1, 0, 0, 1, 0; 0, 1, 0, 0, 1; 0, 0, 1, 1, 0@}}
1385 @t{DESIGN(@{5; 5; 5@})} @result{} (warning)
1389 @deffn {Matrix Function} DET (@var{M})
1390 Returns the determinant of square matrix @var{M}.
1393 @deffn {Matrix Function} EVAL (@var{M})
1395 Returns a column vector containing the eigenvalues of symmetric matrix
1396 @var{M}, sorted in ascending order.
1398 Use @code{CALL EIGEN} (@pxref{CALL EIGEN}) to compute eigenvalues and
1399 eigenvectors of a matrix.
1402 @deffn {Matrix Function} GINV (@var{M})
1403 Returns the @math{@var{k}@times{}@var{n}} matrix @var{A} that is the
1404 @dfn{generalized inverse} of @math{@var{n}@times{}@var{k}} matrix
1405 @var{M}, defined such that
1406 @math{@var{M}@times{}@var{A}@times{}@var{M}=@var{M}} and
1407 @math{@var{A}@times{}@var{M}@times{}@var{A}=@var{A}}.
1411 @deffn {Matrix Function} GSCH (@var{M})
1412 @var{M} must be a @math{@var{n}@times{}@var{m}} matrix, @math{@var{m}
1413 @geq{} @var{n}}, with rank @var{n}. Returns an
1414 @math{@var{n}@times{}@var{n}} orthonormal basis for @var{M}, obtained
1415 using the Gram-Schmidt process.
1418 @deffn {Matrix Function} INV (@var{M})
1419 Returns the @math{@var{n}@times{}@var{n}} matrix @var{A} that is the
1420 inverse of @math{@var{n}@times{}@var{n}} matrix @var{M}, defined such
1421 that @math{@var{M}@times{}@var{A} = @var{A}@times{}@var{M} = I}, where
1422 @var{I} is the identity matrix. @var{M} must not be singular, that
1423 is, @math{\det(@var{M}) @ne{} 0}.
1426 @deffn {Matrix Function} KRONEKER (@var{Ma}, @var{Mb})
1427 Returns the @math{@var{pm}@times{}@var{qn}} matrix @var{P} that is the
1428 @dfn{Kroneker product} of @math{@var{m}@times{}@var{n}} matrix
1429 @var{Ma} and @math{@var{p}@times{}@var{q}} matrix @var{Mb}. One may
1430 view @var{P} as the concatenation of multiple
1431 @math{@var{p}@times{}@var{q}} blocks, each of which is the scalar
1432 product of @var{Mb} by a different element of @var{Ma}. For example,
1433 when @code{A} is a @math{2@times{}2} matrix, @code{KRONEKER(A, B)} is
1434 equivalent to @code{@{A(1,1)*B, A(1,2)*B; A(2,1)*B, A(2,2)*B@}}.
1437 @deffn {Matrix Function} RANK (@var{M})
1438 Returns the rank of matrix @var{M}, a integer scalar whose value is
1439 the dimension of the vector space spanned by its columns or,
1440 equivalently, by its rows.
1443 @deffn {Matrix Function} SOLVE (@var{Ma}, @var{Mb})
1444 @var{Ma} must be an @math{@var{n}@times{}@var{n}} matrix, with
1445 @math{\det(@var{Ma}) @ne{} 0}, and @var{Mb} an
1446 @math{@var{n}@times{}@var{k}} matrix. Returns an
1447 @math{@var{n}@times{}@var{k}} matrix @var{X} such that @math{@var{Ma}
1448 @times{} @var{X} = @var{Mb}}.
1451 @deffn {Matrix Function} SVAL (@var{M})
1454 Given @math{@var{n}@times{}@var{k}} matrix @var{M}, returns a
1455 @math{\min(@var{n},@var{k})}-element column vector containing the
1456 singular values of @var{M} in descending order.
1458 Use @code{CALL SVD} (@pxref{CALL SVD}) to compute the full singular
1459 value decomposition of a matrix.
1462 @deffn {Matrix Function} SWEEP (@var{M}, @var{nk})
1463 Given @math{@var{r}@times{}@var{c}} matrix @var{M} and integer scalar
1464 @math{k = @var{nk}} such that @math{1 @leq{} k @leq{}
1465 \min(@var{r},@var{c})}, returns the @math{@var{r}@times{}@var{c}}
1466 sweep matrix @var{A}.
1468 If @math{@var{M}_{kk} @ne{} 0}, then:
1471 @math{@var{A}_{kk} = 1/@var{M}_{kk}},
1472 @math{@var{A}_{ik} = -@var{M}_{ik}/@var{M}_{kk} @r{for} i @ne{} k},
1473 @math{@var{A}_{kj} = @var{M}_{kj}/@var{M}_{kk} @r{for} j @ne{} k, @r{and}}
1474 @math{@var{A}_{ij} = @var{M}_{ij} - (@var{M}_{ik} * @var{M}_{kj}) / @var{M}_{kk} @r{for} i @ne{} k @r{and} j @ne{} k}.
1477 If @math{@var{M}_{kk} = 0}, then:
1480 @math{@var{A}_{ik} = @var{A}_{ki} = 0 @r{and}}
1481 @math{@var{A}_{ij} = @var{M}_{ij}, @r{for} i @ne{} k @r{and} j @ne{} k}.
1488 @deffn {Matrix Function} EOF (@var{file})
1489 Given a file handle or file name @var{file}, returns an integer scalar
1490 that indicates whether the last record in the file has been read.
1491 Determining this requires attempting reading past the current record,
1492 which means that @code{REREAD} on the next @code{READ} command
1493 following @code{EOF} on the same file will be ineffective.
1496 @node Matrix COMPUTE Command
1497 @subsection The @code{COMPUTE} Command
1500 @t{COMPUTE} @i{variable}[@t{(}@i{index}[@t{,}@i{index}]@t{)}]@t{=}@i{expression}@t{.}
1503 The @code{COMPUTE} command evaluates an expression and assigns the
1504 result to a variable or a submatrix of a variable. Assigning to a
1505 submatrix uses the same syntax as the index operator (@pxref{Matrix
1508 @node Matrix CALL command
1509 @subsection The @code{CALL} Command
1511 A matrix function returns a single result. The @code{CALL} command
1512 implements procedures, which take a similar syntactic form to
1513 functions but yield results by modifying their arguments rather than
1516 Output arguments to a @code{CALL} procedure must be a single variable
1519 The following procedures are implemented via @code{CALL} to allow them
1520 to return multiple results. For these procedures, the output
1521 arguments need not name existing variables; if they do, then their
1522 previous values are replaced:
1525 @item @t{CALL EIGEN(@var{M}, @var{evec}, @var{eval})}
1528 Computes the eigenvalues and eigenvector of symmetric
1529 @math{@var{n}@times{}@var{n}} matrix @var{M}. Assigns the
1530 eigenvectors of @var{M} to the columns of
1531 @math{@var{n}@times{}@var{n}} matrix @var{evec} and the eigenvalues in
1532 descending order to @var{n}-element column vector @var{eval}.
1534 Use the @code{EVAL} function (@pxref{EVAL}) to compute just the
1535 eigenvalues of a symmetric matrix.
1537 @item @t{CALL SVD(@var{M}, @var{U}, @var{S}, @var{V})}
1540 Computes the singular value decomposition of
1541 @math{@var{n}@times{}@var{k}} matrix @var{M}, assigning @var{S} a
1542 @math{@var{n}@times{}@var{k}} diagonal matrix and to @var{U} and
1543 @var{V} unitary @math{@var{k}@times{}@var{k}} matrices such that
1544 @math{@var{M} = @var{U}@times{}@var{S}@times{}@var{V}^T}. The main
1545 diagonal of @var{Q} contains the singular values of @var{M}.
1547 Use the @code{SVAL} function (@pxref{SVAL}) to compute just the
1548 singular values of a matrix.
1551 The final procedure is implemented via @code{CALL} to allow it to
1552 modify a matrix instead of returning a modified version. For this
1553 procedure, the output argument must name an existing variable.
1556 @item @t{CALL SETDIAG(@var{M}, @var{V})}
1557 @anchor{CALL SETDIAG}
1559 Replaces the main diagonal of @math{@var{n}@times{}@var{p}} matrix
1560 @var{M} by the contents of @var{k}-element vector @var{V}. If
1561 @math{@var{k} = 1}, so that @var{V} is a scalar, replaces all of the
1562 diagonal elements of @var{M} by @var{V}. If @math{@var{k} <
1563 \min(@var{n},@var{p})}, only the upper @var{k} diagonal elements are
1564 replaced; if @math{@var{k} > \min(@var{n},@var{p})}, then the
1565 extra elements of @var{V} are ignored.
1567 Use the @code{MDIAG} function (@pxref{MDIAG}) to construct a new
1568 matrix with a specified main diagonal.
1571 @node Matrix PRINT Command
1572 @subsection The @code{PRINT} Command
1575 @t{PRINT} [@i{expression}]
1576 [@t{/FORMAT}@t{=}@i{format}]
1577 [@t{/TITLE}@t{=}@i{title}]
1578 [@t{/SPACE}@t{=}@{@t{NEWPAGE} @math{|} @i{n}@}]
1579 [@{@t{/RLABELS}@t{=}@i{string}@dots{} @math{|} @t{/RNAMES}@t{=}@i{expression}@}]
1580 [@{@t{/CLABELS}@t{=}@i{string}@dots{} @math{|} @t{/CNAMES}@t{=}@i{expression}@}]@t{.}
1583 The @code{PRINT} command is commonly used to display a matrix. It
1584 evaluates the @i{expression}, if present, and outputs it either as
1585 text or a pivot table, depending on the setting of @code{MDISPLAY}
1586 (@pxref{SET MDISPLAY}).
1588 Any matrix expression is allowed as @var{expression}, but an
1589 expression with operators with lower precedence than exponentiation
1590 (@pxref{Matrix Operators}) must be parenthesized. (This avoids
1591 ambiguity between @t{/} as an operator and @t{/} to separate
1594 Use the @code{FORMAT} subcommand to specify a format, such as
1595 @code{F8.2}, for displaying the matrix elements. @code{FORMAT} is
1596 optional for numerical matrices. When it is omitted, @pspp{} chooses
1597 how to format entries automatically using @var{m}, the magnitude of
1598 the largest-magnitude element in the matrix to be displayed:
1602 If the matrix's elements are all integers, then, if possible, @pspp{}
1603 chooses the narrowest @code{F} format with width 12 or less that fits
1604 @var{m} plus a sign.
1607 Otherwise, if @math{@var{m} @geq{} 10^9} or @math{@var{m} @leq{}
1608 10^{-4}}, @pspp{} scales all of the numbers in the matrix by
1609 @math{10^x}, where @var{x} is the exponent used when @var{m} is
1610 displayed in scientific notation, and displays the scaled value in
1611 format @code{F13.10}. @pspp{} adds a note to the output to indicate
1615 Otherwise, @pspp{} displays the value, without scaling, in format
1619 The optional @code{TITLE} subcommand specifies a title for the output
1620 text or table, as a quoted string. When it is omitted, the syntax of
1621 the matrix expression is used as the title.
1623 Use the @code{SPACE} subcommand to request extra space above the
1624 matrix output. With a numerical argument, it adds the specified
1625 number of lines of blank space above the matrix. With @code{NEWPAGE}
1626 as an argument, it prints the matrix at the top of a new page. The
1627 @code{SPACE} subcommand has no effect when a matrix is output as a
1630 The @code{RLABELS} and @code{RNAMES} subcommands, which are mutually
1631 exclusive, can supply a label to accompany each row in the output.
1632 With @code{RLABELS}, specify the labels as comma-separated strings or
1633 other tokens. With @code{RNAMES}, specify a single expression that
1634 evaluates to a vector of strings. Either way, if there are more
1635 labels than rows, the extra labels are ignored, and if there are more
1636 rows than labels, the extra rows are unlabeled. For output to a pivot
1637 table with @code{RLABELS}, the labels can be any length; otherwise,
1638 the labels are truncated to 8 bytes.
1640 The @code{CLABELS} and @code{CNAMES} subcommands work for labeling
1641 columns as @code{RLABELS} and @code{RNAMES} do for labeling rows.
1643 @subsubheading Text Output
1645 When the @var{expression} is omitted, @code{PRINT} does not output a
1646 matrix. Instead, it outputs only the text specified on @code{TITLE},
1647 if any, preceded by any space specified on the @code{SPACE}
1648 subcommand, if any. Any other subcommands are ignored, and the
1649 command acts as if @code{MDISPLAY} is set to @code{TEXT} regardless of
1652 @node Matrix DO IF Command
1653 @subsection The @code{DO IF} Command
1656 @t{DO IF} @i{expression}@t{.}
1657 @dots{}@i{matrix commands}@dots{}
1658 [@t{ELSE IF} @i{expression}@t{.}
1659 @dots{}@i{matrix commands}@dots{}]@dots{}
1661 @dots{}@i{matrix commands}@dots{}]
1665 A @code{DO IF} command evaluates its expression argument. If the
1666 @code{DO IF} expression evaluates to true, then @pspp{} executes the
1667 associated commands. Otherwise, @pspp{} evaluates the expression on
1668 each @code{ELSE IF} clause (if any) in order, and executes the
1669 commands associated with the first one that yields a true value.
1670 Finally, if the @code{DO IF} and all the @code{ELSE IF} expressions
1671 all evaluate to false, @pspp{} executes the commands following the
1672 @code{ELSE} clause (if any).
1674 Each expression on @code{DO IF} and @code{ELSE IF} must evaluate to a
1675 scalar. Positive scalars are considered to be true, and scalars that
1676 are zero or negative are considered to be false.
1678 @node Matrix LOOP and BREAK Commands
1679 @subsection The @code{LOOP} and @code{BREAK} Commands
1682 @t{LOOP} [@i{var}@t{=}@i{first} @t{TO} @i{last} [@t{BY} @i{step}]] [@t{IF} @i{expression}]@t{.}
1683 @dots{}@i{matrix commands}@dots{}
1684 @t{END LOOP} [@t{IF} @i{expression}]@t{.}
1689 The @code{LOOP} command executes a nested group of matrix commands,
1690 called the loop's @dfn{body}, repeatedly. It has three optional
1691 clauses that control how many times the loop body executes.
1692 Regardless of these clauses, the global @code{MXLOOPS} setting, which
1693 defaults to 40, also limits the number of iterations of a loop. To
1694 iterate more times, raise the maximum with @code{SET MXLOOPS} outside
1695 of the @code{MATRIX} command (@pxref{SET MXLOOPS}).
1697 The optional index clause causes @var{var} to be assigned successive
1698 values on each trip through the loop: first @var{first}, then
1699 @math{@var{first} + @var{step}}, then @math{@var{first} + 2 @times{}
1700 @var{step}}, and so on. The loop ends when @math{@var{var} >
1701 @var{last}}, for positive @var{step}, or @math{@var{var} <
1702 @var{last}}, for negative @var{step}. If @var{step} is not specified,
1703 it defaults to 1. All the index clause expressions must evaluate to
1704 scalars, and non-integers are rounded toward zero. If @var{step}
1705 evaluates as zero (or rounds to zero), then the loop body never
1708 The optional @code{IF} on @code{LOOP} is evaluated before each
1709 iteration through the loop body. If its expression, which must
1710 evaluate to a scalar, is zero or negative, then the loop terminates
1711 without executing the loop body.
1713 The optional @code{IF} on @code{END LOOP} is evaluated after each
1714 iteration through the loop body. If its expression, which must
1715 evaluate to a scalar, is zero or negative, then the loop terminates.
1717 The @code{BREAK} command may be used inside a loop body, ordinarily
1718 within a @code{DO IF} command. If it is executed, then the loop
1719 terminates immediately, jumping to the command just following
1720 @code{END LOOP}. When multiple @code{LOOP} commands nest,
1721 @code{BREAK} terminates the innermost loop.
1723 @node Matrix READ Command
1724 @subsection The @code{READ} Command
1727 @t{READ} @i{variable}[@t{(}@i{index}[@t{,}@i{index}]@t{)}]
1728 [@t{/FILE}@t{=}@i{file}]
1729 @t{/FIELD}@t{=}@i{first} @t{TO} @i{last} [@t{BY} @i{width}]
1730 [@t{/SIZE}@t{=}@i{expression}]
1731 [@t{/MODE}@t{=}@{@t{RECTANGULAR} @math{|} @t{SYMMETRIC}@}]
1733 [@t{/FORMAT}@t{=}@i{format}]@t{.}
1736 @node Matrix WRITE Command
1737 @subsection The @code{WRITE} Command
1740 @t{WRITE} @i{expression}
1741 [@t{/OUTFILE}@t{=}@i{file}]
1742 @t{/FIELD}@t{=}@i{first} @t{TO} @i{last} [@t{BY} @i{width}]
1743 [@t{/MODE}@t{=}@{@t{RECTANGULAR} @math{|} @t{TRIANGULAR}@}]
1745 [@t{/FORMAT}@t{=}@i{format}]@t{.}
1748 @node Matrix GET Command
1749 @subsection The @code{GET} Command
1752 @t{GET} @i{variable}[@t{(}@i{index}[@t{,}@i{index}]@t{)}]
1753 [@t{/FILE}@t{=}@{@i{file} @math{|} @t{*}@}]
1754 [@t{/VARIABLES}@t{=}@i{variable}@dots{}]
1755 [@t{/NAMES}@t{=}@i{expression}]
1756 [@t{/MISSING}@t{=}@{@t{ACCEPT} @math{|} @t{OMIT} @math{|} @i{number}@}]
1757 [@t{/SYSMIS}@t{=}@{@t{OMIT} @math{|} @i{number}@}]@t{.}
1760 @node Matrix SAVE Command
1761 @subsection The @code{SAVE} Command
1764 @t{SAVE} @i{expression}
1765 [@t{/OUTFILE}@t{=}@{@i{file} @math{|} @t{*}@}]
1766 [@t{/VARIABLES}@t{=}@i{variable}@dots{}]
1767 [@t{/NAMES}@t{=}@i{expression}]
1768 [@t{/STRINGS}@t{=}@i{variable}@dots{}]@t{.}
1771 @t{MGET} [@t{/FILE}@t{=}@i{file}]
1772 [@t{/TYPE}@t{=}@{@t{COV} @math{|} @t{CORR} @math{|} @t{MEAN} @math{|} @t{STDDEV} @math{|} @t{N} @math{|} @t{COUNT}@}]@t{.}
1775 @node Matrix MSAVE Command
1776 @subsection The @code{MSAVE} Command
1779 @t{MSAVE} @i{expression}
1780 @t{/TYPE}@t{=}@{@t{COV} @math{|} @t{CORR} @math{|} @t{MEAN} @math{|} @t{STDDEV} @math{|} @t{N} @math{|} @t{COUNT}@}
1781 [@t{/OUTFILE}@t{=}@i{file}]
1782 [@t{/VARIABLES}@t{=}@i{variable}@dots{}]
1783 [@t{/SNAMES}@t{=}@i{variable}@dots{}]
1784 [@t{/SPLIT}@t{=}@i{expression}]
1785 [@t{/FNAMES}@t{=}@i{variable}@dots{}]
1786 [@t{/FACTOR}@t{=}@i{expression}]@t{.}
1789 @node Matrix DISPLAY Command
1790 @subsection The @code{DISPLAY} Command
1793 @t{DISPLAY} [@{@t{DICTIONARY} @math{|} @t{STATUS}@}]@t{.}
1796 @node Matrix RELEASE Command
1797 @subsection The @code{RELEASE} Command
1800 @t{RELEASE} @i{variable}@dots{}@t{.}