Learn R Programming

Disequilibrium (version 1.1)

GradientDE: Gradient of log likelihood with respect to all parameters

Description

Gradient of log likelihood with respect to all parameters

Usage

GradientDE(theta, Y, X, summed = TRUE, MaskRho = FALSE)

Arguments

theta

A vector of parameter values to obtain the gradient at. The order of parameters is coefficients of equation 1, coefficients of equation 2, log variance of equation 1, inverse hyperbolic tangent of the correlation of equations 1 and 2, and log variance of equation 2.

Y

A vector of observed responses.

X

A list of two elements. The first element is a \(N \times k_1\) design matrix for equation 1 and the second element is a \(N \times k_2\) design matrix for equation 2.

summed

A logical to determine if gradient values are summed over observations.

MaskRho

A logical or numeric to determine if the correlation is masked. A value of FALSE means the correlation is not fixed. A value between -1 and 1 will fix the correlation to that value.

Value

A \((k_1 + k_2 + 3)\) dimension vector of derivatives if summed = TRUE, else a \(N \times (k_1 + k_2 + 3)\) matrix of derivatives.

Examples

Run this code
# NOT RUN {
set.seed(1775)
library(MASS)
beta01 = c(1,1)
beta02 = c(-1,-1)
N = 10000
SigmaEps = diag(2)
SigmaX = diag(2)
MuX = c(0,0)
par0 = c(beta01, beta02, SigmaX[1, 1], SigmaX[1, 2], SigmaX[2, 2])

Xgen = mvrnorm(N,MuX,SigmaX)
X1 = cbind(1,Xgen[,1])
X2 = cbind(1,Xgen[,2])
X = list(X1 = X1,X2 = X2)
eps = mvrnorm(N,c(0,0),SigmaEps)
eps1 = eps[,1]
eps2 = eps[,2]
Y1 = X1 %*% beta01 + eps1
Y2 = X2 %*% beta02 + eps2
Y = pmin(Y1,Y2)

p1 = 2
p2 = 2
theta = c(beta01, beta02, log(SigmaX[1, 1]), atanh(SigmaX[1, 2]), log(SigmaX[2, 2]))

Gradient = GradientDE(theta, Y, X, summed = TRUE)
head(Gradient)

# }

Run the code above in your browser using DataLab