Predict a frozen-margin pair association
Source:R/associate-pairs.R
predict.drm_pair_association.RdWith no newdata or type, this method preserves the historical
fitted()-style output of the two frozen margins. type = "link" returns
the association linear predictor and type = "eta" returns its bounded
latent-normal association transform; type = "response" is a compatibility
alias for "eta". The beta Bernoulli x ordinary-NB2 route also admits
new-data prediction from its fixed-effect association formula.
Arguments
- object
A
drm_pair_associationobject.- newdata
Optional data frame for beta Bernoulli x ordinary-NB2 association prediction. Its terms, factor levels, contrasts, and columns must match the fitted association formula.
- type
Prediction scale:
"link"forX_A %*% alphaor"eta"for0.999999 * tanh(X_A %*% alpha)."response"is an alias for"eta". Omittypetogether withnewdatato retain the historical frozen-margin fitted output.- se.fit
Logical; return pointwise standard errors on the requested scale. Eta-scale standard errors use the delta method.
- interval
"none"or"confidence". Confidence limits are pointwise link-scale Wald limits transformed monotonically to eta whentype = "eta".- level
Confidence level in
(0, 1).- ...
Must be empty.
Value
With omitted type and newdata, the frozen marginal fitted values.
Without uncertainty, a numeric association prediction on the requested
scale. With interval = "confidence", a matrix with fit, lwr, and
upr columns. With se.fit = TRUE, a list containing fit and se.fit;
fit is the three-column matrix when an interval is requested.
Examples
if (FALSE) { # \dontrun{
set.seed(20260801)
n <- 160
dat <- data.frame(
x1 = seq(-1.2, 1.2, length.out = n),
x2 = rep(c(-0.5, 0.5), length.out = n)
)
z_binary <- rnorm(n)
eta <- 0.999999 * tanh(-0.1 + 0.4 * dat$x1 - 0.2 * dat$x2)
z_count <- eta * z_binary + sqrt(1 - eta^2) * rnorm(n)
dat$binary <- as.integer(
z_binary > qnorm(plogis(-0.2 + 0.3 * dat$x1), lower.tail = FALSE)
)
dat$count <- qnbinom(
pnorm(z_count), mu = exp(0.5 + 0.2 * dat$x2), size = 4
)
binary_fit <- drmTMB(bf(mu = binary ~ x1), binomial(), dat)
count_fit <- drmTMB(
bf(mu = count ~ x2, sigma = ~ 1), nbinom2(), dat
)
assoc <- associate_pairs(
binary_fit, count_fit,
kernel = latent_normal(), association = ~ x1 + x2
)
new_dat <- data.frame(x1 = c(-1, 0, 1), x2 = 0)
eta_prediction <- predict(
assoc,
newdata = new_dat,
type = "eta",
se.fit = TRUE,
interval = "confidence"
)
eta_prediction$fit
eta_prediction$se.fit
} # }