Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Eviews5 / EViews5 / Docs / EViews 5 Command Ref.pdf
Скачиваний:
47
Добавлен:
23.03.2015
Размер:
5.23 Mб
Скачать

34—Chapter 3. Matrix Language

Matrix Expressions

A matrix expression is an expression which combines matrix objects using mathematical operators or relations, functions, and parentheses. While we discuss matrix functions in great detail below, some examples will demonstrate the relevant issues.

Examples:

@inner(@convert(grp,s1))

mat1*vec1

@inverse(mat1+mat2)*vec1

mat1 > mat2

EViews uses the following rules to determine the order in which the expression will be evaluated:

You may nest any number of pairs of parentheses to clarify the order of operations in a matrix expression.

If you do not use parentheses, the operations are applied in the following order:

1.Unary negation operator and functions

2.Multiplication and division operators

3.Addition and subtraction operators

4.Comparison operators: “>=”, “>”, “<=”, “<”, “<>”

Examples:

@inverse(mat1+mat2)+@inverse(mat3+mat4)

vec1*@inverse(mat1+mat2)*@transpose(vec1)

In the first example, the matrices MAT1 and MAT2 will be added and then inverted. Similarly the matrices MAT3 and MAT4 are added and then inverted. Finally, the two inverses will be added together. In the second example, EViews first inverts MAT1+MAT2 and uses the result to calculate a quadratic form with VEC1.

Matrix Operators

EViews provides standard mathematical operators for matrix objects.

Negation (–)

The unary minus changes the sign of every element of a matrix object, yielding a matrix or vector of the same dimension. Example:

Matrix Expressions—35

matrix jneg = -jpos

Addition (+)

You can add two matrix objects of the same type and size. The result is a matrix object of the same type and size. Example:

matrix(3,4) a

matrix(3,4) b

matrix sum = a + b

You can add a square matrix and a sym of the same dimension. The upper triangle of the sym is taken to be equal to the lower triangle. Adding a scalar to a matrix object adds the scalar value to each element of the matrix or vector object.

Subtraction (–)

The rules for subtraction are the same as the rules for addition. Example:

matrix(3,4) a

matrix(3,4) b

matrix dif = a - b

Subtracting a scalar object from a matrix object subtracts the scalar value from every element of the matrix object.

Multiplication (*)

You can multiply two matrix objects if the number of columns of the first matrix is equal to the number of rows of the second matrix.

Example:

matrix(5,9) a

matrix(9,22) b

matrix prod = a * b

In this example, PROD will have 5 rows and 22 columns.

One or both of the matrix objects can be a sym. Note that the product of two sym objects is a matrix, not a sym. The @inner function will produce a sym by multiplying a matrix by its own transpose.

You can premultiply a matrix or a sym by a vector if the number of columns of the matrix is the same as the number of elements of the vector. The result is a vector whose dimension is equal to the number of rows of the matrix.

Example:

36—Chapter 3. Matrix Language

matrix(5,9) mat

vector(9) vec

vector res = mat * vec

In this example, RES will have 5 elements.

You can premultiply a rowvector by a matrix or a sym if the number of elements of the rowvector is the same as the number of rows of the matrix. The result is a rowvector whose dimension is equal to the number of columns of the matrix.

Example:

rowvector rres

matrix(5,9) mat

rowvector(5) row

rres = row * mat

In this example, RRES will have 9 elements.

You can multiply a matrix object by a scalar. Each element of the original matrix is multiplied by the scalar. The result is a matrix object of the same type and dimensions as the original matrix. The scalar can come before or after the matrix object. Examples:

matrix prod = 3.14159*orig

matrix xxx = d_mat*7

Division (/)

You can divide a matrix object by a scalar. Example:

matrix z = orig/3

Each element of the object ORIG will be divided by 3.

Relational Operators (=, >, >=, <, <=, <>)

Two matrix objects of the same type and size may be compared using the comparison operators (). The result is a scalar logical value. Every pair of corresponding elements is tested, and if any pair fails the test, the value 0 (FALSE) is returned; otherwise, the value 1 (TRUE) is returned.

For example, the commands:

if result <> value then

run crect

endif

Matrix Commands and Functions—37

It is possible for a vector to be not greater than, not less than, and not equal to a second vector. For example:

vector(2) v1 vector(2) v2 v1(1) = 1 v1(2) = 2 v2(1) = 2 v2(2) = 1

Since the first element of V1 is smaller than the first element of V2, V1 is not greater than V2. Since the second element of V1 is larger than the second element of V2, V1 is not less than V2. The two vectors are not equal.

Matrix Commands and Functions

EViews provides a number of commands and functions that allow you to work with the contents of your matrix objects. These commands and functions may be divided into roughly four distinct types:

1.Utility Commands and Functions

2.Matrix Algebra Functions

3.Descriptive Statistics Functions

4.Element Functions

The utility commands and functions provide support for creating, manipulating, and assigning values to your matrix objects. We have already seen the @convert function and the stom command, both of which convert data from series and groups into vectors and matrices.

The matrix algebra functions allow you to perform common matrix algebra manipulations and computations. Among other things, you can use these routines to compute eigenvalues, eigenvectors and determinants of matrices, to invert matrices, to solve linear systems of equations, and to perform singular value decompositions.

The descriptive statistics functions compute summary statistics for the data in the matrix object. You can compute statistics such as the mean, median, minimum, maximum, and variance, over all of the elements in your matrix.

The matrix element functions allow you create a new matrix containing the values of a function evaluated at each element of another matrix object. Most of the functions that are available in series expressions may be applied to matrix objects. You can compute the log-

38—Chapter 3. Matrix Language

arithm of every element of a matrix, or the cumulative normal distribution at every element of a vector.

A listing of the commands and functions is included in the matrix summary on page 44. Functions for computing descriptive statistics for data in matrices are discussed in “Descriptive Statistics” on page 577. Additional details on matrix element computations are provided in “Matrix Operators” on page 34.

Functions versus Commands

A function generally takes arguments, and always returns a result. Functions are easily identified by the initial “@” character in the function name.

There are two basic ways that you can use a function. First, you may assign the result to an EViews object. This object may then be used in other EViews expressions, providing you access to the result in subsequent calculations. For example:

matrix y = @transpose(x)

stores the transpose of matrix X in the matrix Y. Since Y is a standard EViews matrix, it may be used in all of the usual expressions.

Second, you may use a function as part of a matrix expression. Since the function result is used in-line, it will not be assigned to a named object, and will not be available for further use. For example, the command:

scalar z = vec1*@inverse(v1+v2)*@transpose(vec1)

uses the results of the @inverse and @transpose functions in forming the scalar expression assigned to Z. These function results will not be available for subsequent computations.

By contrast, a command takes object names and expressions as arguments, and operates on the named objects. Commands do not return a value.

Commands, which do not have a leading “@” character, must be issued alone on a line, rather than as part of a matrix expression. For example, to convert a series X to a vector V1, you would enter:

stom(x,v1)

Because the command does not return any values, it may not be used in a matrix expression.

Соседние файлы в папке Docs