I came up with a strange result when doing my homework in R, can anyone explain to me what's going on?
The instruction told me to set seed 1 to keep consistency.
At first, I set seed(1) twice
set.seed(1)
x <- rnorm(100, mean = 0, sd = 1)
set.seed(1)
epsilon <- rnorm(100, mean = 0, sd = 0.25)
y <- 0.5 * x + epsilon -1
plot(x,y,main = "Scatter plot between X and Y", xlab = "X", ylab = "Y")
I get scatter plot like this: The plot with two set seed
After I only use one set seed the code is:
set.seed(1)
x <- rnorm(100, mean = 0, sd = 1)
epsilon <- rnorm(100, mean = 0, sd = 0.25)
y <- 0.5 * x + epsilon -1
plot(x,y,main = "Scatter plot between X and Y", xlab = "X", ylab = "Y")
The plot became reasonable: The plot with one set seed
Can anyone explain to me why two results are different by adding an extra "set.seed(1)"?