Binary, ordinal and multinomial logit and probit models, conditional logit and simultaneous probit.
Usage
TDA_QRMODELS
tda_qreg(
formula,
data,
model = "logit",
nq = NULL,
waves = NULL,
min_waves = NULL,
intercept = NULL,
control = NULL,
nintegral = NULL,
tol_integral = NULL,
parameterization = NULL,
standardized = FALSE,
predictions = FALSE,
constraints = NULL,
start = NULL,
weights = NULL,
options = list(),
dir = tempfile("tda"),
...
)Arguments
- formula
a two-sided formula.
- data
a data frame.
- model
a name from
TDA_QRMODELSor a TDA model number.- nq
number of categories, for models 5 and 6. Filled in from the data if not given.
- waves, min_waves
the number of waves and, of those, the minimum with valid data required per case (
nw=/pmin=); only meaningful for models 7 and 8 (see the Panel models section).- intercept
whether to include an intercept. Defaults to whatever the formula itself says (
y ~ 0 + xory ~ x - 1already mean no intercept, the ordinary R way, and are honoured); set explicitly to override that.- control
convergence settings from
tda_control.- nintegral, tol_integral
for models needing numerical integration (6-8), the integration control and its accuracy (
qreg'snhp=/eps=).- parameterization
for models 6-8, how the between-wave correlation matrix is parameterised during estimation –
1(default) direct;2a logistic-style transform keeping each correlation in \([-1, 1]\) by construction;3a Cholesky-style factorisation. A numerical-stability choice for the optimiser, not something that changes what the fitted correlations mean;qreg'sopt=.- standardized
for a binary logit or probit model (
model = "logit"/"probit") fit to cross-sectional data (nowaves), also compute standardized coefficients –qreg'sres=1. A separate table, in$standardized: each coefficient in standard-deviation units (Coeff), its exponential (Exp(C)), the exponential of the coefficient times the predictor's standard deviation (Exp(C*SD)), and that standard deviation itself (Std.Dev.). Only works for these two, cross-sectional models (TDA silently skipsres=for any other), so requesting it for a different model errors here instead.- predictions
also write out each case's fitted probabilities –
qreg'sdf=/dtda=. A separate table, in$predictions: case and wave identifiers, the response, predictors, weight (if given), andPROB/PROB0,PROB1, ... (onePROBnper outcome category the model has). Unlikestandardized, model-agnostic: works for every model, each getting whicheverPROB*columns it actually computes.- constraints
for model 6 (
multivariate_probit) or 8 (simultaneous_probit), linear constraints on the model's parameters, in TDA'sbNnumbering –qreg'scon=, the same linear-constraint machinerytda_lsreg'sequality/inequalityuse, just addressed by number rather than by name.bNis the same numberingtda_estimates()'sIdxcolumn already shows, so a first run withoutconstraintstells you which number is which parameter. These two models introduce a correlation parameter for every pair of outcome categories (\(\binom{nq}{2}\) of them) on top of the regular regression coefficients, and are usually only identified with most of them fixed –examples/exam/qr6.cf's worked example fixes all ten (nq = 5) to zero,constraints = paste0("b", 9:18, " = 0")here, reproduced exactly.model's formula and variable list stay exactly the shape every other model already uses: a single response, one row per case.- start
optional starting values, in TDA's parameter order (the same order
bNinconstraintsrefers to, andtda_estimates()'sIdx) –qreg'sxp=. Often needed in practice for models 6/8: TDA's automatic starting-value generator is not always good enough for these two models' extra correlation parameters, and a fit that converges cleanly with good starting values can fail outright without them.- weights
optional case weights, a column name in
dataor a vector as long as the data – TDA'scwt = W;, a separate, standalone command (not a per-command option), the same conventiontda_ple/tda_ltbuse.- options
a named list of further TDA options, passed through: the output files.
- dir
working directory.
- ...
passed to
tda_run.
Value
An object of class tda_fit. For the multivariate and
simultaneous probits (models 6 and 8) it carries correlation,
the estimated correlation matrix among the latent equations, which
TDA computes only when asked for a parameter file. It additionally
carries categories, the (weighted) count and percentage of each
response category as qreg itself tabulates them before
estimating. Cases with missing values are dropped before the fit,
with a message (see ?tdaR).
Models
model takes a name from TDA_QRMODELS, matched partially, or a
TDA model number:
| 1 | logit | binary logit |
| 2 | probit | binary probit |
| 3 | ordinal_logit | needs three or more categories |
| 4 | ordinal_probit | needs three or more categories |
| 5 | multinomial_logit | needs nq |
| 6 | multivariate_probit | needs nq |
| 7 | conditional_logit | panel: needs waves (2+)
and cbind() terms – see
Panel models |
| 8 | simultaneous_probit | panel: needs waves (2+)
and cbind() terms – see
Panel models |
Panel models (waves)
Models 7 and 8 are TDA's panel models, taking each variable once per
wave in a horizontal layout. Write each variable's per-wave columns as
cbind(): cbind(y1, y2) ~ cbind(x1, x2) with
waves = 2. A term with a single column is a time-constant
predictor and is repeated across waves for you. Both models are fit
without an intercept option (TDA's design; model 8 estimates one
intercept per wave anyway, printed against Term = "W <k>",
with the between-wave correlations as Sigma rows).
Missing data follows TDA's unbalanced-panel rule: a case whose
response is missing in a wave simply has that wave dropped
from its likelihood contribution (min_waves – TDA's
pmin= – then sets how many valid waves a case needs to be
used at all), while a missing predictor value has no such
rule and drops the case, with a message.
conditional_logit is Chamberlain's fixed-effects logit; on
two-wave data it agrees with survival::clogit stratified by
case to full printed precision (pinned in the tests).
simultaneous_probit fits one binary probit per wave with
free cross-wave error correlations – for two waves, a bivariate
probit.
TDA's help text for this is incomplete: it names only model 5 as
needing nq, though models 5 and 6 both require it, and it
lists only the first five models, though eight are implemented – the
table above is the full set. The binary models agree with glm:
a binary logit is a binomial glm with a logit link, a binary probit
one with a probit link.
See also
Other regression:
TDA_FAMILIES,
tda_freg(),
tda_gdf(),
tda_l1reg(),
tda_lsreg(),
tda_mlrc_design(),
tda_mreg(),
tda_nlreg(),
tda_npreg(),
tda_zreg()
Examples
set.seed(23)
d <- data.frame(x = round(rnorm(200), 3))
d$y <- rbinom(200, 1, plogis(-0.5 + 1.4 * d$x))
qf <- tda_qreg(y ~ x, d, model = "logit")
coef(qf)
#> Intercept x
#> -0.6819166 1.7243012
coef(glm(y ~ x, d, family = binomial())) # matches: a binary logit is a
#> (Intercept) x
#> -0.6819166 1.7243012
# binomial glm with a logit link
head(predict(qf)) # fitted values, no newdata needed
#> [1] -0.3491264 -1.4319876 0.8923705 2.4097556 1.0372118 1.2268849