regfac.expand.2par {RegressionFactory} | R Documentation |
Expander Function for Two-Parameter Base Distributions
Description
This function produces the full, high-dimensional gradient and Hessian from the base-distribution derivatives for linear transformations of the arguments of a two-parameter base distribution.
Usage
regfac.expand.2par(coeff, X, Z=matrix(1.0, nrow=nrow(X), ncol=1)
, y, fbase2, fgh=2, block.diag=FALSE, ...)
Arguments
coeff |
Vector of coefficients in the regression model. The first |
X |
Matrix of covariates corresponding to the first parameter of the base distribution |
Z |
Matrix of covariates corresponding to the second parameter of the base distribution |
y |
Vector of response variables. Note that |
fbase2 |
Base distribution function |
fgh |
Integer with possible values 0,1,2. If |
block.diag |
If |
... |
Other arguments to be passed to |
Value
A list with elements f,g,h
corresponding to the function, gradient vector, and Hessian matrix of the function fbase2(X%*%beta, Z%*%gamma, y, ...)
, where beta=coeff[1:ncol(X)]
and gamma=coeff[ncol(X)+1:ncol(Z)]
. (Derivatives are evaluated relative to coeff
.) In other words, the base function fbase2(u, v, y, ...)
is projected onto the high-dimensional space of c(beta, gamma)
through the linear transformations of its first argument (u <- X%*%beta
) and its second argument (v <- Z%*%gamma
).
Author(s)
Alireza S. Mahani, Mansour T.A. Sharabiani
References
Mahani, Alireza S. and Sharabiani, Mansour T.A. (2013) Metropolis-Hastings Sampling Using Multivariate Gaussian Tangents https://arxiv.org/pdf/1308.0657v1.pdf
See Also
Examples
## Not run:
library(dglm)
library(sns)
# defining log-likelihood function
loglike.linreg <- function(coeff, X, y) {
regfac.expand.2par(coeff = coeff, X = X, Z = X, y = y
, fbase2 = fbase2.gaussian.identity.log, fgh = 2, block.diag = T)
}
# simulating data according to generative model
N <- 1000 # number of observations
K <- 5 # number of covariates
X <- matrix(runif(N*K, min=-0.5, max=+0.5), ncol=K)
beta <- runif(K, min=-0.5, max=+0.5)
gamma <- runif(K, min=-0.5, max=+0.5)
mean.vec <- X%*%beta
sd.vec <- exp(X%*%gamma)
y <- rnorm(N, mean.vec, sd.vec)
# estimation using dglm
est.dglm <- dglm(y~X-1, dformula = ~X-1, family = "gaussian", dlink = "log")
beta.dglm <- est.dglm$coefficients
gamma.dglm <- est.dglm$dispersion.fit$coefficients
# estimation using RegressionFactory
coeff.tmp <- rep(0, 2*K)
for (n in 1:10) {
coeff.tmp <- sns(coeff.tmp, fghEval=loglike.linreg
, X=X, y=y, rnd = F)
}
beta.regfac.vd <- coeff.tmp[1:K]
gamma.regfac.vd <- coeff.tmp[K+1:K]
# comparing dglm and RegressionFactory results
# neither beta's nor gamma's will match exactly
cbind(beta.dglm, beta.regfac.vd)
cbind(gamma.dglm, gamma.regfac.vd)
## End(Not run)