Trunc: Truncated Values for the GT-Expansion Method

View source: R/family.gait0.R

TruncR Documentation

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) of the untransformed data. Alternatively, if length(Range) > 2 then it is assumed that the entire 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 (2023) 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 gaitdpoisson. If mux = 1 then the function will return a NULL rather than integer(0).

Author(s)

T. W. Yee

See Also

gaitdpoisson, gaitdlog, gaitdzeta, range, setdiff, goffset.

Examples

Trunc(c(1, 8), 2)

## Not run: 
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)),
    gaitdpoisson(truncate = Trunc(org1, i)), data = gdata))
}
sort(logliks, decreasing = TRUE)  # Best to worst
 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 documentation built on Sept. 18, 2024, 9:09 a.m.