Mathematical functions

Scientific functions

abs

Returns absolute value of argument.

arccos

Computes inverse cosine.

arcsin

Computes inverse sine.

atan

Computes inverse tangent.

atan2

Computes angle given a point \(x\),:math:y.

besselj

Computes Bessel function, first kind.

besselk

Computes the modified Bessel function of the second kind, \(K_n(x)\).

bessely

Computes Bessel function, second kind.

beta

Computes the complete Beta function, also called the Euler integral.

boxcox

Computes the Box-Cox function.

cos

Computes cosine.

cosh

Computes hyperbolic cosine.

curve

Computes a one-dimensional smoothing curve.

digamma

Computes the digamma function.

exp

Computes the exponential function of \(x\).

fmod

Computes the floating-point remainder of \(x/y\).

gamma

Computes gamma function value.

gammacplx

Computes gamma function for complex inputs.

gammaii

Compute the inverse incomplete gamma function.

ln

Computes the natural log of each element.

lnfact

Computes natural log of factorial function.

lngamma

Computes the natural log of the gamma function.

log

Computes the log (base 10) of each element.

mbesseli

Computes modified and exponentially scaled modified Bessels of the first kind of the nth order.

pi

Returns the constant, \(\pi\).

polygamma

Computes the polygamma function of order \(n\).

psi

Computes the psi (or digamma) function.

sin

Computes sine.

sinh

Computes the hyperbolic sine.

spline

Computes a two-dimensional interpolatory spline.

sqrt

Computes the square root of each element.

tan

Computes tangent.

tanh

Computes hyperbolic tangent.

tocart

Converts from polar to Cartesian coordinates.

topolar

Converts from Cartesian to polar coordinates.

trigamma

Computes trigamma function.

zeta

Computes the Rieman zeta function.

Differentiation and Integration

gradp, gradcplx

Computes first derivative of a function.

hessp, hesscplx

Computes second derivative of a function.

integrate1d

Integrates a user-defined function over a user-defined range, using adaptive quadrature.

intgrat2

Integrates a 2-dimensional function over an user-defined region.

intgrat3

Integrates a 3-dimensional function over an user-defined region.

intquad1

Integrates a 1-dimensional function.

intquad2

Integrates a 2-dimensional function over an user-defined rectangular region.

intquad3

Integrates a 3-dimensional function over an user-defined rectangular region.

intsimp

Integrates by Simpson’s method.

The following are differentiation functions with advanced options.

gradMTm

Computes numerical gradient with mask.

gradMTT

Computes numerical gradient using available threads.

gradMTTm

Computes numerical gradient with mask using available threads.

hessMTg

Computes numerical Hessian using gradient procedure.

hessMTgw

Computes numerical Hessian using gradient procedure with weights.

hessMTm

Computes numerical Hessian with mask.

hessMTmw

Computes numerical Hessian with mask and weights.

hessMTT

Computes numerical Hessian using available threads.

hessMTTg

Computes numerical Hessian using gradient procedure with available threads.

hessMTTgw

Computes numerical Hessian using gradient procedure with weights and using available threads.

hessMTTm

Computes numerical Hessian with mask and available threads.

hessMTw

Computes numerical Hessian with weights.

Linear Algebra

balance

Balances a matrix.

band

Extracts bands from a symmetric banded matrix.

bandchol

Computes the Cholesky decomposition of a positive definite banded matrix.

bandcholsol

Solves the system of equations \(Ax = b\) for \(x\), given the lower triangle of the Cholesky decomposition of a positive definite banded matrix \(A\).

bandltsol

Solves the system of equations \(Ax = b\) for \(x\), where \(A\) is a lower triangular banded matrix

bandrv

Creates a symmetric banded matrix, given its compact form.

bandsolpd

Solves the system of equations \(Ax = b\) for \(x\), where \(A\) is a positive definite banded matrix.

blockDiag

Creates a block-diagonal matrix from one or more input matrices

chol

Computes Cholesky decomposition, \(X=U'U\).

choldn

Performs Cholesky downdate on an upper triangular matrix.

cholsol

Solves a system of equations given the Cholesky factorization of a matrix.

cholup

Performs Cholesky update on an upper triangular matrix.

cond

Computes condition number of a matrix.

crout

Computes Crout decomposition, \(X = LU\) (real matrices only).

croutp

Computes Crout decomposition with row pivoting (real matrices only).

det

Computes determinant of square matrix.

detl

Computes determinant of decomposed matrix.

dot

Returns a scalar dot product of the columns of two matrices.

hess

Computes upper Hessenberg form of a matrix (real matrices only).

inv, invpd

Inverts a square or positive-definite matrices, respectively.

invswp

Computes a generalized sweep inverse.

lapeighb

Computes eigenvalues only of a real symmetric or complex Hermitian matrix selected by bounds.

lapeighi

Computes eigenvalues only of a real symmetric or complex Hermitian matrix selected by index.

lapeighvb

Computes eigenvalues and eigenvectors of a real symmetric or complex Hermitian matrix selected by bounds.

lapeighvi

Computes selected eigenvalues and eigenvectors of a real symmetric or complex Hermitian matrix.

lapgeig

Computes generalized eigenvalues for a pair of real or complex general matrices.

lapgeigh

Computes generalized eigenvalues for a pair of real symmetric or Hermitian matrices.

lapgeighv

Computes generalized eigenvalues and eigenvectors for a pair of real symmetric or Hermitian matrices.

lapgeigv

Computes generalized eigenvalues, left eigenvectors, and right eigenvectors for a pair of real or complex general matrices.

lapgschur

Computes the generalized Schur form of a pair of real or complex general matrices.

lapgsvdcst

Computes the generalized singular value decomposition of a pair of real or complex general matrices.

lapgsvds

Computes the generalized singular value decomposition of a pair of real or complex general matrices.

lapgsvdst

Computes the generalized singular value decomposition of a pair of real or complex general matrices.

ldl

Computes the \(L\) and \(D\) factors of the LDL factorization of a real symmetric matrix.

ldlp

Computes \(LDL\) decomposition with row pivoting of a symmetric matrix.

ldlsol

Computes Solves the system of equations \(LDLTx = b\) using a matrix factorized by ldlp.

lu

Computes \(LU\) decomposition with row pivoting (real and complex matrices).

lusol

Computes Solves the system of equations \(LUx = b\).

norm

Computes one of several specified matrix norms, or a vector p-norm.

null

Computes orthonormal basis for right null space.

null1

Computes orthonormal basis for right null space.

orth

Computes orthonormal basis for column space \(x\).

pinv

Generalized pseudo-inverse: Moore-Penrose.

pinvmt

Generalized pseudo-inverse: Moore-Penrose.

powerM

Computes the power \(n\) of a matrix \(A\), as the mathematical equivalent of the matrix product of \(n\) copies of \(A\).

qqr

\(QR\) decomposition: returns \(Q_1\) and \(R\).

qqre

\(QR\) decomposition: returns \(Q_1\), \(R\) and a permutation vector, \(E\).

qqrep

\(QR\) decomposition with pivot control: returns \(Q_1\), \(R\), and \(E\).

qr

\(QR\) decomposition: returns \(R\).

qre

\(QR\) decomposition: returns \(R\) and \(E\).

qrep

\(QR\) decomposition with pivot control: returns \(R\) and \(E\).

qrsol

Solves a system of equations \(R'x = b\) given an upper triangular matrix, typically the \(R\) matrix from a \(QR\) decomposition.

qrtsol

Solves a system of equations \(Rx = b\) given a lower triangular matrix, typically a transposed \(R\) matrix from a \(QR\) decomposition.

qtyr

\(QR\) decomposition: returns \(Q'Y\) and \(R\).

qtyre

\(QR\) decomposition: returns \(Q'Y\), \(R\) and \(E\).

qtyrep

\(QR\) decomposition with pivot control: returns \(Q'Y\), \(R\) and \(E\).

qyr

\(QR\) decomposition: returns \(QY\) and \(R\).

qyre

\(QR\) decomposition: returns \(QY\), \(R\) and \(E\).

qyrep

\(QR\) decomposition with pivot control: returns \(QY\), \(R\) and \(E\).

qz

Compute the complex \(QZ\), or generalized Schur, form of a pair of real or complex general matrices with an option to sort the eigenvalues.

rank

Computes rank of a matrix.

rref

Computes reduced row echelon form of a matrix.

schtoc

Reduces any 2x2 blocks on the diagonal of the real Schur form of a matrix returned from schur. The transformation matrix is also updated.

schur

Computes real or complex Schur decomposition of a matrix.

solpd

Solves a system of positive definite linear equations.

svd

Computes the singular values of a matrix.

svd1

Computes singular value decomposition, \(X = USV'\).

svd2

Computes the singular value decomposition \(X = USV'\) with compact \(U\).

svdcusv

Computes the singular value decomposition of a matrix so that: \(X = U S V'\) (compact \(U\)).

svds

Computes the singular values of a matrix.

svdusv

Computes the singular value decomposition of a matrix so that: \(X = U S V'\).

sylvester

Computes the solution to the Sylvester matrix equation, \(AX + XB = C\).

tracem

Computes the trace of a matrix.

Eigenvalues

eig

Computes eigenvalues of general matrix.

eigh

Computes eigenvalues of complex Hermitian or real symmetric matrix.

eighv

Computes eigenvalues and eigenvectors of complex Hermitian or real symmetric matrix.

eigv

Computes eigenvalues and eigenvectors of general matrix.

Polynomial Operations

polychar

Computes characteristic polynomial of a square matrix.

polyeval

Evaluates polynomial with given coefficients.

polyint

Calculates Nth order polynomial interpolation given known point pairs.

polymake

Computes polynomial coefficients from roots.

polymat

Returns sequence powers of a matrix.

polymult

Multiplies two polynomials together.

polyroot

Computes roots of polynomial from coefficients.

See also recserrc, recsercp, and conv.

Fourier Transforms

dfft

Computes discrete 1-D FFT.

dffti

Computes inverse discrete 1-D FFT.

fft

Computes 1- or 2-D FFT.

ffti

Computes inverse 1- or 2-D FFT.

fftm

Computes multi-dimensional FFT.

fftmi

Computes inverse multi-dimensional FFT.

fftn

Computes 1- or 2-D FFT using prime factor algorithm.

rfft

Computes real 1- or 2-D FFT.

rffti

Computes inverse real 1- or 2-D FFT.

rfftip

Computes inverse real 1- or 2-D FFT from packed format FFT.

rfftn

Computes real 1- or 2-D FFT using prime factor algorithm.

rfftnp

Computes real 1- or 2-D FFT using prime factor algorithm, returns packed format FFT.

rfftp

Computes real 1- or 2-D FFT, returns packed format FFT.

Fuzzy Conditional Functions

dotfeq, dotfge, dotfgt, dotfle, dotflt, dotfne

Fuzzy .==, .>=, .>, .<=, .<, .!=

dotfeqmt, dotfgemt, dotfgtmt, dotflemt, dotfltmt, dotfnemt

Fuzzy .==, .>=, .>, .<=, .<, .!=

feq, fge, fgt, fle, flt, fne

Fuzzy ==, >=, >, <=, <, !=

feqmt, fgemt, fgtmt, flemt, fltmt, fnemt

Fuzzy ==, >=, >, <=, <, !=

The mt commands use an fcmptol argument to control the tolerance used for comparison. The non-mt commands use the global variable _fcmptol to control the tolerance used for comparison. By default, this is 1e-15. The default can be changed by editing the file fcompare.dec.

Statistical Functions

acf

Computes sample autocorrelations.

astd

Computes the standard deviation of the elements across one dimension of an N-dimensional array.

astds

Computes the ‘sample’ standard deviation of the elements across one dimension of an N-dimensional array.

chiBarSquare

Computes probability of chi-bar-square statistic.

clusterSE

Computes the White cluster-robust standard errors.

combinate

Computes combinations of \(n\) things taken \(k\) at a time.

combinated

Writes combinations of \(n\) things taken \(k\) at a time to a GAUSS data set.

ConScore

Computes constrained score statistic and its probability.

conv

Computes convolution of two vectors.

corrm, corrvc, corrx

Computes an unbiased estimate of a correlation matrix from a moment matrix, variance-covariance matrix or general matrix.

crossprd

Computes cross product.

design

Creates a design matrix of 0’s and 1’s.

dstatmt

Computes descriptive statistics of a data set or matrix.

dwstat

Computes the Durbin-Watson statistic.

dot

Computes a scalar dot product of the columns of two matrices.

gdaDStat

Computes descriptive statistics on multiple Nx1 variables in a GDA.

gdaDStatMat

Computes descriptive statistics on a selection of columns in a variable in a GDA.

glm

Computes generalized linear regression of a matrix.

gmmFit

Computes generalized method of moments estimates from user specified moment function.

gmmFitIV

Estimate instrumental variables model using the generalized method of moments.

loess

Computes coefficients of locally weighted regression.

loessmt

Computes coefficients of locally weighted regression.

meanc

Computes mean value of each column of a matrix.

median

Computes medians of the columns of a matrix.

moment

Computes moment matrix (\(x'x\)) with special handling of missing values.

momentd

Computes moment matrix from a data set.

movingave

Computes moving average of a series.

movingaveExpwgt

Computes exponentially weighted moving average of a series.

movingaveWgt

Computes weighted moving average of a series.

numCombinations

Computes number of combinations of \(n\) things taken \(k\) at a time.

ols

Computes least squares regression of data set or matrix.

olsmt

Computes least squares regression of data set or matrix.

olsqr

Computes OLS coefficients using \(QR\) decomposition.

olsqr2

Computes OLS coefficients, residuals, and predicted values using \(QR\) decomposition.

olsqrmt

Computes OLS coefficients using \(QR\) decomposition.

pacf

Computes sample partial autocorrelations.

princomp

Computes principal components of a data matrix.

quantile

Computes quantiles from data in a matrix, given specified probabilities.

quantiled

Computes quantiles from data in a data set, given specified probabilities.

quantileFit

Perform linear quantile regression.

quantileFitLoc

Perform local linear or quadratic quantile regression.

robustSE

Computes the Huber-White heteroscedastic robust standard errors. The procedure uses the “sandwich” variance-covariance estimator with a small sample correction of \((n)/(n-1)\).

stdc

Computes standard deviation of the columns of a matrix.

toeplitz

Computes Toeplitz matrix from column vector.

varmall

Computes the log-likelihood of a Vector ARMA model.

varmares

Computes the residuals of a Vector ARMA model.

vcm, vcx

Computes an unbiased estimate of a variance-covariance matrix from a matrix \(x\) or a moment matrix, \(x'x\).

Series and Sequence Functions

recserar

Computes autoregressive recursive series.

recsercp

Computes recursive series involving products.

recserrc

Computes recursive series involving division.

recserVAR

Computes a vector autoregressive recursive.

seqa, seqm

Creates an additive or multiplicative sequence, respectively.

seqaDT

Creates a sequence of dates in DT scalar format.

seqaPosix

Creates a sequence of dates in posix date format, returned as a dataframe date variable.

Precision Control

base10

Converts number to x.xxx and a power of 10.

ceil

Rounds up towards \(+\infty\).

fix

Rounds towards 0.

floor

Rounds down towards \(-\infty\).

machEpsilon

Returns the smallest number such that \(1 + eps > 1\).

round

Rounds to the nearest integer.

trunc

Converts numbers to integers by truncating the fractional portion.