Skip to content

Random data

4 messages · mentor_, Sarah Goslee, Dimitris Rizopoulos +1 more

#
That's not a 45-degree angle: the x and y scales are quite different. But
you can use corgen from the ecodist package to create correlated x and
y variables, and then adjust the scale as needed.

Sarah
On Wed, Nov 25, 2009 at 9:42 AM, mentor_ <mentor_ at gmx.net> wrote:

  
    
#
one way is:

x <- sort(rnorm(100))
y <- rnorm(100, mean = x, sd = 0.3)

plot(x, y)
abline(a = 0, b = 1)


I hope it helps.

Best,
Dimitris
mentor_ wrote:

  
    
#
One option, first, generate the range of "x" data that you want, then add normally distributed noise to each x, these will be your "y" data. 

n <- 20
x <- sample(20:50, n)
y <- rnorm(n, mean = x, sd = 3)
plot(y ~ x)


Erik