sim.lm: Simulate data from a simple linear model.

Description Usage Arguments Value Examples

Description

Generates one set of n independent pairs of observations using a simple linear model (y = a + b*x + disturbance) with intercept a, slope b, and (by default) normally distributed disturbances. The output is a matrix with x in the first column and y in the second column. The output matrix is sorted by the x values, with the lowest x value in the first row.

Usage

1
2
sim.lm(n, a, b, sigma.disturb = 1, mu.x = 8, sigma.x = 2,
  rdisturb = rnorm, rx = rnorm, het.coef = 0)

Arguments

n

The number of pairs of observations to simulate.

a

The intercept parameter of the linear regression model to be simulated.

b

The slope parameter of the linear regression model to be simulated.

sigma.disturb

The variance of the disturbances in the model y = a + b*x + disturbance.

mu.x

The expectation of the x values.

sigma.x

The variance of the x values.

rdisturb

A function for drawing the random disturbances. rnorm() is the default, which makes the disturbances normally distributed, but you can use any function for random number generation with first argument the sample size, second argument the expectation, and third argument the standard deviation.

rx

A function for drawing the random x values. rnorm() is the default, which makes x normally distributed, but you can use any function for random number generation with first argument the sample size, second argument the expectation, and third argument the standard deviation.

het.coef

A number introducing some heteroscedasticity (i.e. non-constant variance) to the disturbances. If het.coef = 0 (the default), then the disturbances have constant variance. If it is positive, then the standard deviation of the disturbances increases with x; if negative, then the standard deviation of the disturbances decreases with x.

Value

A matrix with n rows, x in the first column and y in the second column. The output matrix is sorted by the x values, with the lowest x value in the first row.

Examples

1
2
3
4
sim.lm(n = 11, a = 3, b = 1/2)
plot(sim.lm(1000, 3, 1/2))
plot(sim.lm(1000, 3, 1/2, rdisturb = rlaplace))
plot(sim.lm(1000, 3, 1/2, het.coef = .2))

mdedge/stfspack documentation built on May 9, 2019, 8:17 a.m.