earg = list(lambda=1)
golf("p", earg=earg, short=FALSE)
golf("p", earg=earg, tag=TRUE)
p = seq(0.02, 0.98, len=201)
y = golf(p, earg=earg)
y. = golf(p, earg=earg, deriv=1)
max(abs(golf(y, earg=earg, inv=TRUE) - p)) # Should be 0
par(mfrow=c(2,1), las=1)
plot(p, y, type="l", col="blue", main="golf()")
abline(h=0, v=0.5, col="red", lty="dashed")
plot(p, y., type="l", col="blue",
main="(Reciprocal of) first GOLF derivative")
# Another example
gdata = data.frame(x2 = sort(runif(nn <- 1000)))
gdata = transform(gdata, x3 = runif(nn))
gdata = transform(gdata, mymu = exp( 3 + 1 * x2 - 2 * x3))
lambda = 4
gdata = transform(gdata, y1 = rgamma(nn, shape=lambda, scale=mymu/lambda))
cutpoints = c(-Inf, 10, 20, Inf)
gdata = transform(gdata, cuty = Cut(y1, breaks=cutpoints))
par(mfrow=c(1,1), las=1)
with(gdata, plot(x2, x3, col=cuty, pch=as.character(cuty)))
with(gdata, table(cuty) / sum(table(cuty)))
fit = vglm(cuty ~ x2 + x3, fam = cumulative(link="golf",
reverse=TRUE, parallel=TRUE, intercept.apply=TRUE,
mv=TRUE, earg=list(cutpoint=cutpoints[2:3], lambda=lambda)),
gdata, trace=TRUE)
head(fit@y)
head(fitted(fit))
head(predict(fit))
coef(fit)
coef(fit, matrix=TRUE)
constraints(fit)
fit@misc$earg
Run the code above in your browser using DataLab