Learn R Programming

investr (version 1.4.0)

calibrate: Calibration for the simple linear regression model.

Description

The function calibrate computes the maximum likelihood estimate and a condfidence interval for the unknown predictor value that corresponds to an observed value of the response (or vector thereof) or specified value of the mean response. See the reference listed below for more details.

#' @rdname calibrate #' @export #' @method calibrate lm calibrate.lm <- function(object, ...) calibrate(formula(object), data = eval(object$call$data), ...)

Usage

calibrate(object, ...)
"calibrate"(object, y0, interval = c("inversion", "Wald", "none"), level = 0.95, mean.response = FALSE, adjust = c("none", "Bonferroni", "Scheffe"), k, ...)
"calibrate"(formula, data = NULL, ..., subset, na.action = na.fail)
"calibrate"(object, y0, interval = c("inversion", "Wald", "none"), level = 0.95, mean.response = FALSE, adjust = c("none", "Bonferroni", "Scheffe"), k, ...)

Arguments

object
An object that inherits from class "lm", a matrix, a list, or a data frame.
...
Additional optional arguments. At present, no optional arguments are used.
y0
The value of the observed response(s) or specified value of the mean response.
interval
The method to use for forming a confidence interval.
level
A numeric scalar between 0 and 1 giving the confidence level for the interval to be calculated.
mean.response
Logicial indicating whether confidence intervals should correspond to an observed response(s) (FALSE) or a specified value of the mean response (TRUE). Default is FALSE.
adjust
A logical value indicating if an adjustment should be made to the critical value used in calculating the confidence interval. This useful for when the calibration curve is to be used multiple, say k, times.
k
The number times the calibration curve is to be used for computing a confidence interval. Only needed when adjust = TRUE.
formula
A formula of the form y ~ x.
data
an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called.
subset
An optional vector specifying a subset of observations to be used in the fitting process.
na.action
a function which indicates what should happen when the data contain NAs.

Value

An object of class "invest" containing the following components:
  • estimate The estimate of x0.
  • lwr The lower confidence limit for x0.
  • upr The upper confidence limit for x0.
  • se An estimate of the standard error (Wald interval only).
  • interval The method used for calculating lower and upper (only used by print method).

References

Graybill, F. A., and Iyer, H. K. (1994) Regression analysis: Concepts and Applications. Duxbury Press.

Miller, R. G. (1981) Simultaneous Statistical Inference. Springer-Verlag.

Examples

Run this code
#
# Arsenic example (simple linear regression with replication)
#

# Inverting a prediction interval for an individual response
arsenic.lm <- lm(measured ~ actual, data = arsenic)
plotFit(arsenic.lm, interval = "prediction", shade = TRUE, 
        col.pred = "lightblue")
(cal <- calibrate(arsenic.lm, y0 = 3, interval = "inversion"))
abline(h = 3)
segments(cal$estimate, 3, cal$estimate, par()$usr[3])
arrows(cal$lower, 3, cal$lower, par()$usr[3])
arrows(cal$upper, 3, cal$upper, par()$usr[3])

#
# Crystal weight example (simple linear regression)
#

# Inverting a confidence interval for the mean response
crystal.lm <- lm(weight ~ time, data = crystal)
plotFit(crystal.lm, interval = "confidence", shade = TRUE,
        col.conf = "lightblue")
(cal <- calibrate(crystal.lm, y0 = 8, interval = "inversion", 
                  mean.response = TRUE))
abline(h = 8)
segments(cal$estimate, 8, cal$estimate, par()$usr[3])
arrows(cal$lower, 8, cal$lower, par()$usr[3])
arrows(cal$upper, 8, cal$upper, par()$usr[3])

# Wald interval and approximate standard error based on the delta method
calibrate(crystal.lm, y0 = 8, interval = "Wald", mean.response = TRUE)

Run the code above in your browser using DataLab