Learn R Programming

propagate (version 1.3-0)

statVec: Transform an input vector into one with defined mean and standard deviation

Description

Transforms an input vector into one with defined \(\mu\) and \(\sigma\) by using a scaled-and-shifted Z-transformation.

Usage

statVec(x, mean, sd)

Value

A vector of the same length as x, with mean equal to mean and standard deviation equal to sd (of its non-missing values).

Arguments

x

the input vector to be transformed.

mean

the desired mean of the created vector.

sd

the desired standard deviation of the created vector.

Author

Andrej-Nikolai Spiess

Details

Calculates the vector \(V\) by a Z-transformation of the input vector \(X\) and subsequent scaling by sd and shifting by mean: $$V = \frac{X - \bar{X}}{s_X} \cdot \mathrm{sd} + \mathrm{mean}$$ Only location and scale are changed: the shape of the distribution of x (skewness, kurtosis) is preserved. The mean and standard deviation of x are computed from its finite values, so that missing and infinite values remain as they are; x needs at least two finite values that are not all equal. This can be used, e.g., to create Monte Carlo samples of an input quantity with exactly the stated estimate and standard uncertainty for propagate with type = "sim".

Examples

Run this code
## Create a vector of 10 values with mean = 5 and s.d. = 2.
x <- rnorm(10, 5, 2)
mean(x) ## => mean is not 5!
sd(x)   ## => s.d. is not 2!

z <- statVec(x, 5, 2)
mean(z) ## => mean is 5!
sd(z)   ## => s.d. is 2!

Run the code above in your browser using DataLab