# t-distributed errors with 3 degrees of freedom
ols_with_error(rt, df = 3)
# A linear regression with t-distributed error, using error_scale to make
# errors large
population(
x1 = predictor(rnorm, mean = 4, sd = 10),
x2 = predictor(runif, min = 0, max = 10),
y = response(0.7 + 2.2 * x1 - 0.2 * x2,
family = ols_with_error(rt, df = 4),
error_scale = 2.5)
)
# Cauchy-distributed errors
ols_with_error(rcauchy, scale = 3)
# A contaminated error distribution, where
# 95% of observations are Gaussian and 5% are Cauchy
rcontaminated <- function(n) {
contaminant <- rbinom(n, 1, prob = 0.05)
return(ifelse(contaminant == 1,
rcauchy(n, scale = 20),
rnorm(n, sd = 1)))
}
ols_with_error(rcontaminated)
Run the code above in your browser using DataLab