simulate_lm: Simulate responses from a linear model 'lm'

View source: R/simulate_lm.R

simulate_lmR Documentation

Simulate responses from a linear model lm

Description

The function simulate does not consider the uncertainty in the estimation of the model parameters. This function will attempt to do this.

Usage

simulate_lm(
  object,
  psim = 1,
  nsim = 1,
  resid.type = c("none", "resample", "normal", "wild"),
  value = c("matrix", "data.frame"),
  data = NULL,
  ...
)

Arguments

object

object of class lm

psim

parameter simulation level (an integer, 0, 1, 2, 3 or 4).

nsim

number of simulations to perform

resid.type

type of residual to include (none, resample, normal or wild)

value

either ‘matrix’ or ‘data.frame’

data

the data argument might be needed when using this function inside user defined functions. At least it is expected to be safer.

...

additional arguments (none used at the moment)

Details

Simulate responses from a linear model lm

These are the options that control the parameter simulation level

psim = 0

returns the fitted values

psim = 1

simulates a beta vector (mean response)

psim = 2

simulates a beta vector and adds resampled residuals (similar to observed data)

psim = 3

simulates a beta vector, considers uncertainty in the variance covariance matrix of beta and adds residuals (prediction)

psim = 4

only adds residuals according to resid.type (similar to simulate.lm)

The residual type (resid.type) controls how the residuals are generated. They are either resampled, simulated from a normal distribution or ‘wild’ where the Rademacher distribution is used (https://en.wikipedia.org/wiki/Rademacher_distribution). Resampled and normal both assume iid, but ‘normal’ makes the stronger assumption of normality. When psim = 2 and resid.type = none, simulate is used instead. ‘wild’ does not assume constant variance, but it assumes symmetry.

Value

matrix or data.frame with responses

References

See “Inference Based on the Wild Bootstrap” James G. MacKinnon https://www.math.kth.se/matstat/gru/sf2930/papers/wild.bootstrap.pdf “Bootstrap in Nonstationary Autoregression” Zuzana Praskova https://dml.cz/bitstream/handle/10338.dmlcz/135473/Kybernetika_38-2002-4_1.pdf “Jackknife, Bootstrap and other Resampling Methods in Regression Analysis” C. F. J. Wu. The Annals of Statistics. 1986. Vol 14. 1261-1295.

Examples


require(ggplot2)
data(Orange)
fit <- lm(circumference ~ age, data = Orange)
sims <- simulate_lm(fit, nsim = 100, value = "data.frame")

ggplot(data = sims) + 
  geom_line(aes(x = age, y = sim.y, group = ii), 
            color = "gray", alpha = 0.5) + 
  geom_point(aes(x = age, y = circumference)) 




nlraa documentation built on May 29, 2024, 2:01 a.m.