Learn R Programming

mosaic (version 0.8-18)

deltaMethod: Delta method on data frames

Description

An expansion of the capabilities of deltaMethod from the car package.

Usage

## S3 method for class 'data.frame':
deltaMethod(object, g, uncertainties,
  estimates = measurements, func = g, constants = c(),
  measurements = NULL, vcov., ...)

Arguments

object
a data frame containing measured quantities
g
a quoted string that is describes the function of the parameter estimates to be evaluated; see deltaMethod for details.
uncertainties
a data frame with the same dimension as object or numeric vector of length ncol(object) containing the uncertainties on each measured value in object or a matrix providing a variance-covariance matrix for the
vcov.
a covariance matrix or a list of covariance matrices. Only one of vcov. and uncertainties may be defined.
func
a quoted string used to annotate output. The default of func = g is usually appropriate.
constants
This argument is a named vector whose elements are constants that are used in the f argument. This is needed only when the function is called from within another function to comply to R scoping rules.
estimates
a vector of column names or column numbers used to specify a subset of object containing the measured/estimated quantities.
measurements
an alternative name for estimates
...
additional arguments passed through to deltaMethod in the car package.

See Also

deltaMethod in the car package.

Examples

Run this code
C_p <- 4.182 / 60 # / 60 because measureing m in L/min
exprforQ <- "(T.cold.out - T.cold.in) * C_p * m.cold"
deltaMethod( HeatX[, c("T.cold.in","T.cold.out","m.cold")], exprforQ, c(1,1,.5) )
# This is just wordier in this example, but would allow the uncertainties to vary
# from row to row.

HeatX3 <- transform(HeatX,
                    u.cold.in=1, u.cold.out=1, u.hot.in=1, u.hot.out=1,
                    u.m.cold=0.5, u.m.hot=0.5)
deltaMethod( HeatX3[, c("T.cold.in","T.cold.out","m.cold")], exprforQ,
             HeatX3[, c("u.cold.in", "u.cold.out", "u.m.cold")])
# Rather than specifying two data frames, we can use subsetting instead
deltaMethod( HeatX3,  exprforQ,
   estimates=c("T.cold.in","T.cold.out","m.cold"),
   uncertainties=c("u.cold.in", "u.cold.out", "u.m.cold"))
# Can also specify vcov. as a matrix or list of matrices:
deltaMethod(HeatX[, c("T.cold.in","T.cold.out","m.cold")], exprforQ,
  vcov. = diag(c(1,1,.5)^2) )
deltaMethod(HeatX[, c("T.cold.in","T.cold.out","m.cold")], exprforQ,
  vcov. = list( diag(c(1,1,.5)^2), diag(c(1,2,.8)^2) ) )

Run the code above in your browser using DataLab