# Example 1; proportional odds model
pneumo = transform(pneumo, let = log(exposure.time))
(fit = vglm(cbind(normal, mild, severe) ~ let, propodds, pneumo))
fit@y # Sample proportions
depvar(fit) # Better than using fit@y; dependent variable (response)
weights(fit, type = "prior") # Number of observations
coef(fit, matrix = TRUE) # p.179, in McCullagh and Nelder (1989)
constraints(fit) # Constraint matrices
summary(fit)
# Example 2; zero-inflated Poisson model
zdata = data.frame(x2 = runif(nn <- 2000))
zdata = transform(zdata, pstr0 = logit(-0.5 + 1*x2, inverse = TRUE),
lambda = loge( 0.5 + 2*x2, inverse = TRUE))
zdata = transform(zdata, y = rzipois(nn, lambda, pstr0 = pstr0))
with(zdata, table(y))
fit = vglm(y ~ x2, zipoisson, zdata, trace = TRUE)
coef(fit, matrix = TRUE) # These should agree with the above values
# Example 3; fit a two species GAM simultaneously
fit2 = vgam(cbind(agaaus, kniexc) ~ s(altitude, df = c(2, 3)),
binomialff(mv = TRUE), hunua)
coef(fit2, matrix = TRUE) # Not really interpretable
plot(fit2, se = TRUE, overlay = TRUE, lcol = 1:2, scol = 1:2)
ooo = with(hunua, order(altitude))
with(hunua, matplot(altitude[ooo], fitted(fit2)[ooo,], type = "l", lwd = 2,
xlab = "Altitude (m)", ylab = "Probability of presence", las = 1,
main = "Two plant species' response curves", ylim = c(0, 0.8)))
with(hunua, rug(altitude))
# Example 4; LMS quantile regression
fit = vgam(BMI ~ s(age, df = c(4, 2)), lms.bcn(zero = 1), dat = bmi.nz,
trace = TRUE)
head(predict(fit))
head(fitted(fit))
head(bmi.nz) # Person 1 is near the lower quartile among people his age
head(cdf(fit))
par(mfrow = c(1, 1), bty = "l", mar = c(5,4,4,3)+0.1, xpd = TRUE)
qtplot(fit, percentiles = c(5,50,90,99), main = "Quantiles", las = 1,
xlim = c(15, 90), ylab = "BMI", lwd = 2, lcol = 4) # Quantile plot
ygrid = seq(15, 43, len = 100) # BMI ranges
par(mfrow = c(1, 1), lwd = 2) # Density plot
aa = deplot(fit, x0 = 20, y = ygrid, xlab = "BMI", col = "black",
main = "Density functions at Age = 20 (black), 42 (red) and 55 (blue)")
aa
aa = deplot(fit, x0 = 42, y = ygrid, add = TRUE, llty = 2, col = "red")
aa = deplot(fit, x0 = 55, y = ygrid, add = TRUE, llty = 4, col = "blue",
Attach = TRUE)
aa@post$deplot # Contains density function values
# Example 5; GEV distribution for extremes
(fit = vglm(maxtemp ~ 1, egev, data = oxtemp, trace = TRUE))
head(fitted(fit))
coef(fit, matrix = TRUE)
Coef(fit)
vcov(fit)
vcov(fit, untransform = TRUE)
sqrt(diag(vcov(fit))) # Approximate standard errors
rlplot(fit)
Run the code above in your browser using DataLab