Question about Regression

63 Views Asked by At

I am solving a problem but I am having a hard time understanding the terminology. I have not been exposed to much statistics/probability before so please bear with me. I am considering a regression model $Y_i = f(x_i)+\epsilon_i$ for $i=1,2,\dots n$. We are given that $x_i$ are independently and identically distributed in [0,1] and that $\epsilon_i$ are independently and identically distributed normal random variables with standard deviation $\sigma$. We are of course given $\sigma$.

So the first thing I want to do is generate some random samples $\{(x_j,Y_j)\}$, but I am unsure how to do this. I feel like I am not understanding how to generate my $x_i$ and $\epsilon_i$, but once knowing this it should become simple I believe.

I know this may be simple, but any help is much appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

Here is an example in R language

set.seed(123)

# define the sample size n
n = 100
# sampling n uniform [0,1] realizations 
x = runif(n)
# sampling n normal realizations with sigma = 1 
epsilon = rnorm(100)
# assume that f(x) = 1 + x
y = 1 + x + epsilon

# plot the results with the regression line
plot(x, y, pch = 20, col = "blue")
abline( lm(y~x), col = "red" )

enter image description here