[R] Simulate residuals with different properties for a linear model (regression)
Juliet Hannah
juliet.hannah at gmail.com
Tue Jul 21 01:56:24 CEST 2009
Here are a couple of examples.
# residuals not normal
n <- 100;
x = seq(n)
y = 10 + 10 *x + 20 * rchisq(n,df=2)
non_normal_lm = lm(y~x)
#non-constant variance
n <- 100;
x = seq(n)
y = 100 + 3 * x + rnorm(n,0,3) * x;
het_var_lm = lm(y~x)
#For each of these try:
plot(non_normal_lm)
plot(het_var_lm)
#or specify which one you want
plot(non_normal_lm,which=1)
Best,
Juliet
On Mon, Jul 20, 2009 at 2:16 PM, Friedericksen
Hope<friedericksen.hope at gmail.com> wrote:
> Hey guys,
>
> for educational purposes I wonder if it is possible to simulate
> different data sets (or specifically residuals) for a linear regression.
> I would like to show my students residuals with different means,
> variances and distributions (normal, but also not normal) in the plots
> created with the plot command for a lm-object. In addition it would be
> nice to simulate although influencal values (high cooks distance and
> leverage)
>
> lm.results <- lm(y~x,data)
> plot(lm.results)
>
> Is there an easy way to do this? Or can this be done at all (and if yes,
> any hints?:-)
>
> Thanks and Greetings!
> Friedericksen
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list