Fits a parametric distribution to a (standardized) input vector using misc::fit_param_dist, and generates random draws from the fitted distribution. Useful for simulating residuals or innovations whose distribution is estimated from data rather than assumed.

rfitdistr(x, n = length(x), p = 1)

Arguments

x

a numeric vector used to fit the distribution (the vector is centered and scaled internally before fitting)

n

number of observations to simulate per column/path (default length(x))

p

number of columns/paths to simulate; if p <= 1, a vector of length n is returned, otherwise a matrix of dimension n x p is returned (default 1)

Value

If p <= 1, a numeric vector of length n containing simulated values. If p > 1, a numeric matrix with n rows and p columns containing simulated values.

Author

T. Moudiki

Examples


x <- rnorm(100)
res <- rfitdistr(x, n = 10, p = 5)