opsr {OPSR} | R Documentation |
High-level formula interface to the workhorse opsr.fit
.
opsr(
formula,
data,
subset,
weights,
na.action,
start = NULL,
fixed = NULL,
method = "BFGS",
iterlim = 1000,
printLevel = 2,
nThreads = 1,
.get2step = FALSE,
.useR = FALSE,
.censorRho = TRUE,
...
)
formula |
an object of class |
data |
an optional data frame, list or environment (or object coercible by
|
subset |
an optional vector specifying a subset of observations to be used
in the fitting process. (See additional details in the 'Details' section of
the |
weights |
an optional vector of weights to be used in the fitting process.
Should be |
na.action |
a function which indicates what should happen when the data
contain |
start |
a numeric vector with the starting values (passed to |
fixed |
parameters to be treated as constants at their |
method |
maximzation method (passed to |
iterlim |
maximum number of iterations (passed to |
printLevel |
larger number prints more working information (passed to |
nThreads |
number of threads to be used. Do not pass higher number than
number of ordinal outcomes. See also |
.get2step |
if |
.useR |
if |
.censorRho |
if |
... |
further arguments passed to |
Models for opsr
are specified symbolically. A typical model has the form
ys | yo ~ terms_s | terms_o1 | terms_o2 | ...
. ys
is the ordered (numeric)
response vector (starting from 1, in integer-increasing fashion). For the terms
specification the rules of the regular formula interface apply (see also stats::lm).
The intercept in the terms_s
(selection process) is excluded automatically
(no need to specify -1
). If the user wants to specify the same process for
all continuous outcomes, two processes are enough (ys | yo ~ terms_s | terms_o
).
Note that the model is poorly identifiable if terms_s == terms_o
(same regressors
are used in selection and outcome processes).
An object of class "opsr" "maxLik" "maxim"
.
## simulated data
sim_dat <- opsr_simulate()
dat <- sim_dat$data # 1000 observations
sim_dat$sigma # cov matrix of errors
sim_dat$params # ground truth
## specify a model
model <- ys | yo ~ xs1 + xs2 | xo1 + xo2 | xo1 + xo2 | xo1 + xo2
model <- ys | yo ~ xs1 + xs2 | xo1 + xo2 # since we use the same specification...
## estimate
fit <- opsr(model, dat)
## inference
summary(fit)
## using update and model comparison
fit_updated <- update(fit, ~ . | 1) # only intercepts for the continuous outcomes
## null model
fit_null <- opsr_null_model(fit)
## likelihood ratio test
anova(fit_null, fit_updated, fit)
## predict
p1 <- predict(fit, group = 1, type = "response")
p2 <- predict(fit, group = 1, counterfact = 2, type = "response")
plot(p1, p2)
abline(a = 0, b = 1, col = "red")
## produce formatted tables
texreg::screenreg(fit, beside = TRUE, include.pseudoR2 = TRUE, include.R2 = TRUE)