Trunc: Truncated Values for the GT-Expansion Method

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/family.gait.R

Description

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

Usage

1
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

gaitpoisson, gaitlog, gaitzeta, range. setdiff.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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 documentation built on Jan. 16, 2021, 5:21 p.m.