Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

Trunc

Truncated Values for the GT-Expansion Method


Description

Given the minimum and maximum values in a response variable, and a positive multiplier, returns the truncated values for generally-truncated regression

Usage

Trunc(Range, mux = 2, location = 0, omits = TRUE)

Arguments

Range

Numeric, of length 2 containing the minimum and maximum in that order. Alternatively, if length(Range) > 2 then it is assumed that the untransformed data is passed in so that range is applied.

mux

Numeric, the multiplier. A positive integer.

location

Numeric, the location parameter, allows a shift to the right.

omits

Logical. The default is to return the truncated values (those being omitted). If FALSE then the multiples are returned.

Details

Generally-truncated regression can handle underdispersion with respect to some parent or base distribution such as the Poisson. Yee and Ma (2020) call this the GT-Expansion (GTE) method, which is a special case of the GT-location-scale (GT-LS) method. This is a utility function to help make life easier. It is assumed that the response is a count variable.

Value

A vector of values to be fed into the truncate argument of a VGAM family function such as gaitpoisson. If mux = 1 then the function will return a NULL rather than integer(0).

Author(s)

T. W. Yee

See Also

Examples

Trunc(c(1, 8), 2)

set.seed(1)  # The following example is based on the normal
mymean <- 20; m.truth <- 3  # approximation to the Poisson.
gdata <- data.frame(y1 = round(rnorm((nn <- 1000), mymean,
                                     sd = sqrt(mymean / m.truth))))
org1 <- with(gdata, range(y1))  # Original range of the raw data
m.max <- 5  # Try multipliers 1:m.max
logliks <- numeric(m.max)
names(logliks) <- as.character(1:m.max)
for (i in 1:m.max) {
  logliks[i] <- logLik(vglm(i * y1 ~ offset(rep(log(i), nn)),
    gaitpoisson(truncate = Trunc(org1, i)), data = gdata))
}
sort(logliks, decreasing = TRUE)  # Best to worst
## Not run:  par(mfrow = c(1, 2))
plot(with(gdata, table(y1)))  # Underdispersed wrt poisson
plot(logliks, col = "blue", type = "b", xlab = "Multiplier") 
## End(Not run)

VGAM

Vector Generalized Linear and Additive Models

v1.1-5
GPL-3
Authors
Thomas Yee [aut, cre], Cleve Moler [ctb] (author of several LINPACK routines)
Initial release
2021-01-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.