View source: R/confidence_intervals.R
confint.chandwich | R Documentation |
confint
method for objects of class "chandwich"
.
Computes confidence intervals for one or more model parameters based
on an object returned from adjust_loglik
.
## S3 method for class 'chandwich'
confint(
object,
parm,
level = 0.95,
type = c("vertical", "cholesky", "spectral", "none"),
profile = TRUE,
...
)
object |
An object of class |
parm |
A vector specifying the (unfixed) parameters for which confidence intervals are required. If missing, all parameters are included. Can be either a numeric vector,
specifying indices of the components of the full parameter
vector, or a character vector of parameter names, which must be a subset
of those supplied in
|
level |
The confidence level required. A numeric scalar in (0, 1). |
type |
A character scalar. The argument |
profile |
A logical scalar. If |
... |
Further arguments to be passed to |
For details see the documentation for the function
conf_intervals
, on which confint.chandwich
is based.
A matrix with columns giving lower and upper confidence limits for each parameter. These will be labelled as (1 - level)/2 and 1 - (1 - level)/2 in % (by default 2.5% and 97.5%). The row names are the names of the model parameters, if these are available.
The underlying function conf_intervals
. If you would
like to plot the profile loglikelihood function for a parameter then call
conf_intervals
directly and then use the associated plot
method. Note that in conf_intervals()
a parameter choice is
specified using an argument called which_pars
, not parm
.
conf_region
for a confidence region for
pairs of parameters.
compare_models
for an adjusted likelihood ratio test
of two models.
adjust_loglik
to adjust a user-supplied
loglikelihood function.
# -------------------------- GEV model, owtemps data -----------------------
# ------------ following Section 5.2 of Chandler and Bate (2007) -----------
gev_loglik <- function(pars, data) {
o_pars <- pars[c(1, 3, 5)] + pars[c(2, 4, 6)]
w_pars <- pars[c(1, 3, 5)] - pars[c(2, 4, 6)]
if (isTRUE(o_pars[2] <= 0 | w_pars[2] <= 0)) return(-Inf)
o_data <- data[, "Oxford"]
w_data <- data[, "Worthing"]
check <- 1 + o_pars[3] * (o_data - o_pars[1]) / o_pars[2]
if (isTRUE(any(check <= 0))) return(-Inf)
check <- 1 + w_pars[3] * (w_data - w_pars[1]) / w_pars[2]
if (isTRUE(any(check <= 0))) return(-Inf)
o_loglik <- log_gev(o_data, o_pars[1], o_pars[2], o_pars[3])
w_loglik <- log_gev(w_data, w_pars[1], w_pars[2], w_pars[3])
return(o_loglik + w_loglik)
}
# Initial estimates (method of moments for the Gumbel case)
sigma <- as.numeric(sqrt(6 * diag(var(owtemps))) / pi)
mu <- as.numeric(colMeans(owtemps) - 0.57722 * sigma)
init <- c(mean(mu), -diff(mu) / 2, mean(sigma), -diff(sigma) / 2, 0, 0)
# Log-likelihood adjustment of the full model
par_names <- c("mu[0]", "mu[1]", "sigma[0]", "sigma[1]", "xi[0]", "xi[1]")
large <- adjust_loglik(gev_loglik, data = owtemps, init = init,
par_names = par_names)
confint(large)
confint(large, profile = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.