Description Usage Arguments Value Author(s) References See Also Examples
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.
1 2 |
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 |
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
).
Alireza S. Mahani, Mansour T.A. Sharabiani
Mahani, Alireza S. and Sharabiani, Mansour T.A. (2013) Metropolis-Hastings Sampling Using Multivariate Gaussian Tangents https://arxiv.org/pdf/1308.0657v1.pdf
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 28 29 30 31 32 33 34 35 36 37 38 39 40 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.