Re: [R] How to simulate heteroscedasticity (correlation)

From: Patrizio Frederic <frederic.patrizio_at_gmail.com>
Date: Wed, 23 Jul 2008 12:22:33 +0200

> Now I also want to generate two correlated variables where the error
> variance vary over the variable-correlation.
> And I want to plot this for showing heteroscedasticity.
>
> Like shown here:
> http://upload.wikimedia.org/wikipedia/de/1/1b/Heteroske2.png
>
> Is that possible with R?
>

of course it is. And it' very simple

seed(123456)
x = rnorm(500,1,1)
b0 = 1 # intercept chosen at your choice b1 = 1 # coef chosen at your choice
h = function(x) 1+.4*x # h performs heteroscedasticity function (here I used a linear one)
eps = rnorm(500,0,h(x))
y = b0 + b1*x + eps
plot(x,y)
abline(lsfit(x,y))
abline(b0,b1,col=2)

regards

PF

ps notice that in heteroscedasticity case the random vector (X,Y) is not a bivariate normal but it is:

Y|X=x ~ normal(b0+b1 x; h(x))

ie every conditional Y is normal

+-------------------------------------------------
| Patrizio Frederic
| Research associate in Statistics,
| Department of Economics,
| University of Modena and Reggio Emilia,
| Via Berengario 51,
| 41100 Modena, Italy
|
| tel:  +39 059 205 6727

| fax: +39 059 205 6947
| mail: patrizio.frederic_at_unimore.it
+-------------------------------------------------

______________________________________________
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. Received on Wed 23 Jul 2008 - 10:30:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Jul 2008 - 11:32:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive