
Get Subject-Specific Parameters from TMB Model
Source:R/tmb-methods.R
get_subject_pars.beezdemand_tmb.RdGet Subject-Specific Parameters from TMB Model
Usage
# S3 method for class 'beezdemand_tmb'
get_subject_pars(object, expanded = NULL, at = NULL, ...)Arguments
- object
A
beezdemand_tmbobject.- expanded
Controls return shape for fits with within-id-varying design columns (factor-expanded random effects, within-id continuous covariates, or multi-block
pdBlockedspecs).NULL(default): auto-detect. When fit-time within-id variation causedNAin cachedsubject_pars$Q0, runs the expansion machinery: rows are expanded across within-id factor levels (one row per (subject, factor-level) cell), and within-id numeric covariates are conditioned at the subject's mean (no row expansion from numerics). When the cachedQ0has noNA, returns the wide one-row-per-subject shape unchanged.TRUE: always attempt expansion. On a fit with no within-id variation, silently returns the wide shape.FALSE: always return the wide shape. Emits a one-line warning on a fit with within-id variation (the returnedQ0,alpha,Pmax,OmaxareNA).
- at
Optional named numeric vector/list (e.g.
c(dose_c = 1)) giving the covariate value(s) at which to evaluate per-subjectQ0/alphafor continuous random-effect slope terms (TICKET-051). Defaults to each subject's mean of the covariate (which equals the reference 0 for a centered, balanced design). The per-subject slope deviations are always returned asq0_<term>/alpha_<term>columns regardless ofat. Ignored (with a warning) for fits without a continuous random slope.- ...
Additional arguments (currently unused).
Value
When the resolved expanded is FALSE: data
frame with columns id, b_i, c_i (if 2 RE),
Q0, alpha, Pmax, Omax. When the
resolved expanded is TRUE, the shape depends on the
kind of within-id variation: for fits with within-id factors, the
within-subject factor columns are added and rows are expanded to one
per (subject, factor-level) cell with per-cell Q0,
alpha, Pmax, Omax; for fits whose only within-id
variation is numeric, the numerics are conditioned at the subject's
mean and the return is one row per subject (no added factor columns)
with finite Q0 / alpha.
Per-block random-effect matrices
For factor-expanded or multi-block fits, the wide table's
b_i / c_i columns hold the first RE column from each
block (intercept slot for the M1 baseline block, for example) for
backward compatibility with downstream consumers. Power users who
need the full per-block RE structure can access
attr(subject_pars, "re_q0_mat") and
attr(subject_pars, "re_alpha_mat") as
n_subjects x re_dim matrices ordered by block.
Examples
# \donttest{
data(apt)
fit <- fit_demand_tmb(apt, equation = "exponential", verbose = 0)
#> equation='exponential': Dropped 14 zero-consumption observations (146 remaining).
head(get_subject_pars(fit))
#> id b_i c_i Q0 alpha Pmax Omax
#> 1 19 0.4347399 -0.6136355 10.058257 0.001637264 13.439089 44.13566
#> 2 30 -0.8308979 0.4420229 2.837025 0.004705279 16.579168 15.35759
#> 3 38 -0.3588356 0.1280378 4.548595 0.003437347 14.155026 21.02253
#> 4 60 0.3938846 0.1112281 9.655604 0.003380049 6.781236 21.37890
#> 5 68 0.4514144 -0.3174826 10.227378 0.002201589 9.829030 32.82253
#> 6 106 -0.1487057 0.4857013 5.612230 0.004915352 8.022711 14.70123
#> pmax_at_bound
#> 1 FALSE
#> 2 FALSE
#> 3 FALSE
#> 4 FALSE
#> 5 FALSE
#> 6 FALSE
# }