Trunc | R Documentation |
Given the minimum and maximum values in a response variable, and a positive multiplier, returns the truncated values for generally-truncated regression
Trunc(Range, mux = 2, location = 0, omits = TRUE)
Range |
Numeric, of length 2 containing the minimum and maximum
(in that order) of the untransformed data.
Alternatively, if |
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 |
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.
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)
.
T. W. Yee
gaitdpoisson
,
gaitdlog
,
gaitdzeta
,
range
,
setdiff
,
goffset
.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.