186
186
# Example 2. The use of the xij argument (simple case).
187
ymat = rdiric(n <- 1000, shape=rep(exp(2), len=4))
188
mydat = data.frame(x1=runif(n), x2=runif(n), x3=runif(n), x4=runif(n),
189
z1=runif(n), z2=runif(n), z3=runif(n), z4=runif(n))
190
mydat = transform(mydat, X=x1, Z=z1)
191
mydat = round(mydat, dig=2)
187
ymat = rdiric(n <- 1000, shape = rep(exp(2), len = 4))
188
mydat = data.frame(x1 = runif(n), x2 = runif(n), x3 = runif(n), x4 = runif(n),
189
z1 = runif(n), z2 = runif(n), z3 = runif(n), z4 = runif(n))
190
mydat = transform(mydat, X = x1, Z = z1)
191
mydat = round(mydat, dig = 2)
192
192
fit2 = vglm(ymat ~ X + Z,
193
dirichlet(parallel=TRUE), data=mydat, trace=TRUE,
193
dirichlet(parallel = TRUE), data = mydat, trace = TRUE,
194
194
xij = list(Z ~ z1 + z2 + z3 + z4,
195
195
X ~ x1 + x2 + x3 + x4),
196
196
form2 = ~ Z + z1 + z2 + z3 + z4 +
197
197
X + x1 + x2 + x3 + x4)
198
head(model.matrix(fit2, type="lm")) # LM model matrix
199
head(model.matrix(fit2, type="vlm")) # Big VLM model matrix
198
head(model.matrix(fit2, type = "lm")) # LM model matrix
199
head(model.matrix(fit2, type = "vlm")) # Big VLM model matrix
201
coef(fit2, matrix=TRUE)
202
max(abs(predict(fit2)-predict(fit2, new=mydat))) # Predicts correctly
201
coef(fit2, matrix = TRUE)
202
max(abs(predict(fit2)-predict(fit2, new = mydat))) # Predicts correctly
205
# plotvgam(fit2, se=TRUE, xlab="x1", which.term=1) # Bug!
206
# plotvgam(fit2, se=TRUE, xlab="z1", which.term=2) # Bug!
207
plotvgam(fit2, xlab="x1") # Correct
208
plotvgam(fit2, xlab="z1") # Correct
205
# plotvgam(fit2, se = TRUE, xlab = "x1", which.term = 1) # Bug!
206
# plotvgam(fit2, se = TRUE, xlab = "z1", which.term = 2) # Bug!
207
plotvgam(fit2, xlab = "x1") # Correct
208
plotvgam(fit2, xlab = "z1") # Correct
216
216
coalminers = transform(coalminers,
217
217
Age = (age - 42) / 5,
218
dum1 = round(runif(nrow(coalminers)), dig=2),
219
dum2 = round(runif(nrow(coalminers)), dig=2),
220
dum3 = round(runif(nrow(coalminers)), dig=2),
221
dumm = round(runif(nrow(coalminers)), dig=2))
222
BS = function(x, ..., df=3) bs(c(x,...), df=df)[1:length(x),,drop=FALSE]
223
NS = function(x, ..., df=3) ns(c(x,...), df=df)[1:length(x),,drop=FALSE]
218
dum1 = round(runif(nrow(coalminers)), dig = 2),
219
dum2 = round(runif(nrow(coalminers)), dig = 2),
220
dum3 = round(runif(nrow(coalminers)), dig = 2),
221
dumm = round(runif(nrow(coalminers)), dig = 2))
222
BS = function(x, ..., df = 3) bs(c(x,...), df = df)[1:length(x),,drop = FALSE]
223
NS = function(x, ..., df = 3) ns(c(x,...), df = df)[1:length(x),,drop = FALSE]
225
225
# Equivalently...
226
BS = function(x, ..., df=3) head(bs(c(x,...), df=df), length(x), drop=FALSE)
227
NS = function(x, ..., df=3) head(ns(c(x,...), df=df), length(x), drop=FALSE)
226
BS = function(x, ..., df = 3) head(bs(c(x,...), df = df), length(x), drop = FALSE)
227
NS = function(x, ..., df = 3) head(ns(c(x,...), df = df), length(x), drop = FALSE)
229
229
fit3 = vglm(cbind(nBnW,nBW,BnW,BW) ~ Age + NS(dum1,dum2),
230
fam = binom2.or(exchang=TRUE, zero=3),
230
fam = binom2.or(exchang = TRUE, zero = 3),
231
231
xij = list(NS(dum1,dum2) ~ NS(dum1,dum2) +
234
234
form2 = ~ NS(dum1,dum2) + NS(dum2,dum1) + fill(NS(dum1)) +
235
235
dum1 + dum2 + dum3 + Age + age + dumm,
236
data = coalminers, trace=TRUE)
237
head(model.matrix(fit3, type="lm")) # LM model matrix
238
head(model.matrix(fit3, type="vlm")) # Big VLM model matrix
236
data = coalminers, trace = TRUE)
237
head(model.matrix(fit3, type = "lm")) # LM model matrix
238
head(model.matrix(fit3, type = "vlm")) # Big VLM model matrix
240
coef(fit3, matrix=TRUE)
242
plotvgam(fit3, se=TRUE, lcol="red", scol="blue", xlab="dum1")
240
coef(fit3, matrix = TRUE)
241
\dontrun{ plotvgam(fit3, se = TRUE, lcol = "red", scol = "blue", xlab = "dum1") }
246
244
\keyword{regression}