rrvglm(formula, family, data = list(), weights = NULL, subset = NULL,
na.action = na.fail, etastart = NULL, mustart = NULL,
coefstart = NULL, control = rrvglm.control(...), offset = NULL,
method = "rrvglm.fit", model = FALSE, x.arg = TRUE, y.arg = TRUE,
contrasts = NULL, constraints = NULL, extra = NULL,
qr.arg = FALSE, smart = TRUE, ...)
vglm
.environment(formula)
,
typically the environment from which rrvglm
is called.vglm
.vglm
.rrvglm.control
for details.vglm
.rrvglm.fit
uses iteratively reweighted least squares (IRLS).x
and y
slots.
Note the model matrix is the LM model matrix; to get the VGLM
model matrixvglm
.vglm
.rrvglm.control
."rrvglm"
, which has the the same
slots as a "vglm"
object. The only difference is
that the some of the constraint matrices are estimates
rather than known. But "vglm"
objects are
described in vglm-class
.For identifiability it is common to enforce corner constraints on $A$: by default, the top $R$ by $R$ submatrix is fixed to be the order-$R$ identity matrix and the remainder of $A$ is estimated.
The underlying algorithm of RR-VGLMs is iteratively reweighted least squares (IRLS) with an optimizing algorithm applied within each IRLS iteration (e.g., alternating algorithm).
In theory, any vglm
and vgam
should work
for rrvglm
too.
The function that actually does the work is rrvglm.fit
;
it is vglm.fit
with some extra code.
Yee, T. W. (2004) A new technique for maximum-likelihood canonical Gaussian ordination. Ecological Monographs, 74, 685--701.
Anderson, J. A. (1984) Regression and ordered categorical variables. Journal of the Royal Statistical Society, Series B, Methodological, 46, 1--30.
Yee, T. W. (2013) Reduced-rank vector generalized linear models with two linear predictors. Computational Statistics and Data Analysis.
Documentation accompanying the
rrvglm.control
, lvplot.rrvglm
(same as biplot.rrvglm
), rrvglm-class
,
grc
,
cqo
,
vglmff-class
,
vglm
,
vglm-class
,
smartpred
,
rrvglm.fit
.
Special family functions include
negbinomial
zipoisson
and zinegbinomial
.
(see Yee (2012) and Coef.rrvglm
,
summary.rrvglm
,
etc.
Data include
crashi
.# Example 1: RR negative binomial (RR-NB) with Var(Y) = mu + delta1 * mu^delta2
nn <- 1000 # Number of observations
delta1 <- 3.0 # Specify this
delta2 <- 1.5 # Specify this; should be greater than unity
a21 <- 2 - delta2
mydata <- data.frame(x2 = runif(nn), x3 = runif(nn))
mydata <- transform(mydata, mu = exp(2 + 3 * x2 + 0 * x3))
mydata <- transform(mydata, y2 = rnbinom(nn, mu=mu, size=(1/delta1)*mu^a21))
plot(y2 ~ x2, data = mydata, pch = "+", col = 'blue', las = 1,
main = paste("Var(Y) = mu + ", delta1, " * mu^", delta2, sep = ""))
rrnb2 <- rrvglm(y2 ~ x2 + x3, negbinomial(zero = NULL), mydata, trace = TRUE)
a21.hat <- (Coef(rrnb2)@A)["log(size)", 1]
beta11.hat <- Coef(rrnb2)@B1["(Intercept)", "log(mu)"]
beta21.hat <- Coef(rrnb2)@B1["(Intercept)", "log(size)"]
(delta1.hat <- exp(a21.hat * beta11.hat - beta21.hat))
(delta2.hat <- 2 - a21.hat)
# exp(a21.hat * predict(rrnb2)[1,1] - predict(rrnb2)[1,2]) # delta1.hat
summary(rrnb2)
# Obtain a 95 percent confidence interval for delta2:
se.a21.hat <- sqrt(vcov(rrnb2)["I(latvar.mat)", "I(latvar.mat)"])
ci.a21 <- a21.hat + c(-1, 1) * 1.96 * se.a21.hat
(ci.delta2 <- 2 - rev(ci.a21)) # The 95 percent confidence interval
Confint.rrnb(rrnb2) # Quick way to get it
# Plot the abundances and fitted values against the latent variable
plot(y2 ~ latvar(rrnb2), data = mydata, col = "blue",
xlab = "Latent variable", las = 1)
ooo <- order(latvar(rrnb2))
lines(fitted(rrnb2)[ooo] ~ latvar(rrnb2)[ooo], col = "red")
# Example 2: stereotype model (reduced-rank multinomial logit model)
data(car.all)
index <- with(car.all, Country == "Germany" | Country == "USA" |
Country == "Japan" | Country == "Korea")
scar <- car.all[index, ] # standardized car data
fcols <- c(13,14,18:20,22:26,29:31,33,34,36) # These are factors
scar[,-fcols] = scale(scar[, -fcols]) # Standardize all numerical vars
ones <- matrix(1, 3, 1)
clist <- list("(Intercept)" = diag(3), Width = ones, Weight = ones,
Disp. = diag(3), Tank = diag(3), Price = diag(3),
Frt.Leg.Room = diag(3))
set.seed(111)
fit <- rrvglm(Country ~ Width + Weight + Disp. + Tank + Price + Frt.Leg.Room,
multinomial, data = scar, Rank = 2, trace = TRUE,
constraints = clist, noRRR = ~ 1 + Width + Weight,
Uncor = TRUE, Corner = FALSE, Bestof = 2)
fit@misc$deviance # A history of the fits
Coef(fit)
biplot(fit, chull = TRUE, scores = TRUE, clty = 2, Ccex = 2,
ccol = "blue", scol = "red", Ccol = "darkgreen", Clwd = 2,
main = "1=Germany, 2=Japan, 3=Korea, 4=USA")
Run the code above in your browser using DataLab