simulCoef | R Documentation |
cirls
object.Simulates coefficients for a fitted cirls
object. confint
and vcov
compute confidence intervals and the Variance-Covariance matrix for coefficients from a fitted cirls
object. These methods supersede the default methods for cirls
objects.
simulCoef(object, nsim = 1, seed = NULL, complete = TRUE,
constrained = TRUE)
## S3 method for class 'cirls'
confint(object, parm, level = 0.95, nsim = 1000,
complete = TRUE, ...)
## S3 method for class 'cirls'
vcov(object, complete = TRUE, nsim = 1000, trunc = TRUE,
...)
object |
A fitted |
nsim |
The number of simulations to perform. |
seed |
Either NULL or an integer that will be used in a call to |
complete |
If FALSE, doesn't return inference for undetermined coefficients in case of an over-determined model. |
constrained |
A logical switch indicating Whether to simulate from the constrained (the default) or unconstrained coefficients distribution. |
parm |
A specification of which parameters to compute the confidence intervals for. Either a vector of numbers or a vector of names. If missing, all parameters are considered. |
level |
The confidence level required. |
... |
Further arguments passed to or from other methods. For |
trunc |
If set to |
confint
and vcov
are custom methods for cirls objects to supersede the default methods used for glm objects. Internally, they both call simulCoef
to generate coefficient vectors from a Truncated Multivariate Normal Distribution using the TruncatedNormal::rtmvnorm()
function. This distribution accounts for truncation by constraints, ensuring all coefficients are feasible with respect to the constraint matrix. simulCoef
typically doesn't need to be used directly for confidence intervals and variance-covariance matrices, but it can be used to check other summaries of the coefficients distribution.
These methods only work when Cmat
is of full row rank, i.e. if there are less constraints than variables in object
.
For simulCoef
, a matrix with nsim
rows containing simulated coefficients.
For confint
, a two-column matrix with columns giving lower and upper confidence limits for each parameter.
For vcov
, a matrix of the estimated covariances between the parameter estimates of the model.
By default, the Variance-Covariance matrix generated by vcov
is different than the one returned by summary(obj)$cov.scaled
. The former accounts for the reduction in degrees of freedom resulting from the constraints, while the latter is the unconstrained GLM Variance-Covariance. Note that the unconstrained one can be obtained from vcov
by setting constrained = FALSE
.
Geweke, J.F., 1996. Bayesian Inference for Linear Models Subject to Linear Inequality Constraints, in: Lee, J.C., Johnson, W.O., Zellner, A. (Eds.), Modelling and Prediction Honoring Seymour Geisser. Springer, New York, NY, pp. 248–263. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/978-1-4612-2414-3_15")}
Botev, Z.I., 2017, The normal law under linear restrictions: simulation and estimation via minimax tilting, Journal of the Royal Statistical Society, Series B, 79 (1), pp. 1–24.
rtmvnorm for the underlying routine to simulate from a TMVN. checkCmat()
to check if the contraint matrix can be reduced.
####################################################
# Isotonic regression
#----- Perform isotonic regression
# Generate data
set.seed(222)
p1 <- 5; p2 <- 3
x1 <- matrix(rnorm(100 * p1), 100, p1)
x2 <- matrix(rnorm(100 * p2), 100, p2)
b1 <- runif(p1) |> sort()
b2 <- runif(p2)
y <- x1 %*% b1 + x2 %*% b2 + rnorm(100, sd = 2)
# Fit model
Ciso <- diff(diag(p1))
resiso <- glm(y ~ x1 + x2, method = cirls.fit, Cmat = list(x1 = Ciso))
#----- Extract uncertainty
# Extract variance covariance
vcov(resiso)
# Extract confidence intervals
confint(resiso)
# We can extract the usual unconstrained matrix
vcov(resiso, constrained = FALSE)
all.equal(vcov(resiso, constrained = FALSE), summary(resiso)$cov.scaled)
# Simulate from the distribution of coefficients
sims <- simulCoef(resiso, nsim = 10)
# Check that all simulated coefficient vectors are feasible
apply(resiso$Cmat %*% t(sims) >= resiso$lb, 2, all)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.