Skip to content

Simulate heteroscedastic data

Source: man/simulate_hetero.Rd ยท Help: ?simulate_hetero

Utilities to generate data with non-constant variance patterns. simulate_hetero simulates a linear regression model with heteroscedastic errors using a user-supplied variance function. The helper functions prefixed by sigma_ implement common variance patterns and can be passed to sigma_func. simulate_arch1 creates a simple ARCH(1) time series.

Usage

simulate_hetero(n, beta0, beta1, sigma_func, seed = NULL)

simulate_arch1(n, mu = 0, alpha0 = 0.5, alpha1 = 0.3, seed = NULL)

sigma_linear(x)

sigma_exponential(x)

sigma_group(x)

sigma_piecewise(x)

sigma_poly(x, a = 0.5, b = 0.1, c = 0.02)

sigma_sin(x, A = 1, B = 0.5, omega = 2 * pi/10, phi = 0)

sigma_multiplicative(x, mu_func, p = 1)

sigma_spatial(coords, gamma0 = 0.5, gamma1 = 0.1)

sigma_logistic(x, L = 2, k = 1, x0 = 5)

sigma_inverse(x, a = 1, b = 1)

sigma_power(x, a = 0.5, p = 0.5)

sigma_step(x, thr = 5, low = 0.5, high = 2)

sigma_u_shape(x, a = 0.1, b = 0.05, center = 5)

sigma_exp_decay(x, a = 2, b = 0.2)

sigma_gaussian_peak(x, base = 0.5, height = 1, mu = 5, sd = 1)

sigma_piecewise_linear(x, thr = 5, slope1 = 0.1, slope2 = 0.3)

Arguments

n
Number of observations for simulate_hetero, or the length of the series for simulate_arch1.
beta0
Intercept of the regression.
beta1
Slope of the regression.
sigma_func
Function returning the standard deviation for each x.
seed
Optional integer seed for reproducibility.
mu
Mean of the ARCH(1) process for simulate_arch1, and the peak location for sigma_gaussian_peak.
alpha0
Constant term in the ARCH variance equation.
alpha1
ARCH coefficient (must be in [0,1)).
x
Numeric vector used by the sigma_* functions.
coords
Matrix or data frame with columns x and y for sigma_spatial.
mu_func
Function returning mean values for sigma_multiplicative.
p
Exponent for sigma_multiplicative or sigma_power.
a, b, c, A, B, omega, phi, L, k, x0, thr, low, high, center, base, height, sd, slope1, slope2, gamma0, gamma1
Additional numeric parameters controlling the shape of the variance patterns.

Value

For simulate_hetero a data frame with columns x and y. For simulate_arch1 a data frame with columns time, y and sigma. The sigma_* helpers return numeric vectors of standard deviations.

Naming

The simulation functions form one family and are named in snake_case on purpose: simulate_hetero(), simulate_arch1(), simulate_size() and simulate_power(), and the sigma_*() variance functions. The rest of the package uses camelCase. The family keeps these names after 1.0.0.

Examples

set.seed(1)
hetero <- simulate_hetero(200, 1, 2, sigma_linear)
head(hetero)

# Other variance patterns
simulate_hetero(100, 0, 1, sigma_logistic)
simulate_arch1(50)