Description Usage Arguments Value Examples
Use Taylor linearization (i.e. the Delta Method) to obtain the variance of a function or the variance-covariance matrix of a vector-valued function
1 | get_tsl_variance(f, values, vcov_matrix)
|
f |
An expression or list of expressions created using the 'expression()' function, e.g. 'expression(x/y)' or 'list(expression(sin(x + y)), expression(cos(x + y)))'. |
values |
A named list of values where first derivatives are to be evaluated, e.g. 'list(y = 10, x = 5)'. The names must match variables in the expression(s). |
vcov_matrix |
A variance-covariance matrix for the variables in the expression must be provided. |
A variance-covariance matrix for the expressions evaluated at the specified points. If only one expression is provided, the result is a single numeric value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Sample values of y and x
var_cov_pop <- matrix(c(5,4,4,5), byrow = TRUE, nrow = 2)
sampled_obs <- MASS::mvrnorm(n = 100, mu = c(120, 100), Sigma = var_cov_pop)
y <- sampled_obs[,1]
x <- sampled_obs[,2]
# Estimate ratio of y to x
ratio <- mean(y)/mean(x)
# Estimate sampling covariance of X and Y
x_y_vcov_estimate <- cov(sampled_obs) / (nrow(sampled_obs) - 1)
# Estimate sampling covariance of ratio
get_tsl_variance(list('ratio' = expression(y/x),
'product' = expression(x/y)),
values = list('y' = mean(y),
'x' = mean(x)),
vcov_matrix = x_y_vcov_estimate)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.