if (FALSE) # Fit a rank-1 RR-VGLM as a DRR-VGLM.
set.seed(1); n <- 1000; S <- 6 # S must be even
myrank <- 1
rdata <- data.frame(x1 = runif(n), x2 = runif(n),
x3 = runif(n), x4 = runif(n))
dval <- ncol(rdata) # Number of covariates
# Involves x1, x2, ... a rank-1 model:
ymatrix <- with(rdata,
matrix(rpois(n*S, exp(3 + x1 - 0.5*x2)), n, S))
H.C <- vector("list", dval) # Ordinary "rrvglm"
for (i in 1:dval) H.C[[i]] <- CM.free(myrank)
names(H.C) <- paste0("x", 1:dval)
H.A <- list(CM.free(S)) # rank-1
rfit1 <- rrvglm(ymatrix ~ x1 + x2 + x3 + x4,
poissonff, rdata, trace = TRUE)
class(rfit1)
dfit1 <- rrvglm(ymatrix ~ x1 + x2 + x3 + x4,
poissonff, rdata, trace = TRUE,
H.A = H.A, # drrvglm
H.C = H.C) # drrvglm
class(dfit1)
Coef(rfit1) # The RR-VGLM is the same as
Coef(dfit1) # the DRR-VGLM.
max(abs(predict(rfit1) - predict(dfit1))) # 0
abs(logLik(rfit1) - logLik(dfit1)) # 0
summary(rfit1)
summary(dfit1)
Run the code above in your browser using DataLab