nGradientDE: Negative gradient of log likelihood with respect to all...

Description Usage Arguments Value Examples

View source: R/Disequilibrium.R

Description

Negative gradient of log likelihood with respect to all parameters

Usage

1
nGradientDE(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 x k[1] design matrix for equation 1 and the second element is a N x 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 x (k[1] + k[2] + 3) matrix of derivatives.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 = nGradientDE(theta, Y, X, summed = TRUE)
head(Gradient)

Disequilibrium documentation built on July 2, 2020, 3:27 a.m.