simulate_lm | R Documentation |
lm
The function simulate
does not consider the
uncertainty in the estimation of the model parameters. This function will attempt
to do this.
simulate_lm(
object,
psim = 1,
nsim = 1,
resid.type = c("none", "resample", "normal", "wild"),
value = c("matrix", "data.frame"),
data = NULL,
...
)
object |
object of class |
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) |
Simulate responses from a linear model lm
These are the options that control the parameter simulation level
returns the fitted values
simulates a beta vector (mean response)
simulates a beta vector and adds resampled residuals (similar to observed data)
simulates a beta vector, considers uncertainty in the variance covariance matrix of beta and adds residuals (prediction)
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.
matrix or data.frame with responses
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.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.