The following code block shows how to run such a one-factor linear regression in R:
> set.seed(12345)> x<-1:100> a<-4> beta<-5> errorTerm<-rnorm(100)> y<-a+beta*x+errorTerm> lm(y~x)
The first line of set.seed(12345) guarantees that different users will get the same random numbers when the same seed() is applied, that is, 12345 in this case. The R function rnorm(n) is used to generate n random numbers from a standard normal distribution. Also, the two letters of the lm() function stand for linear model. The result is shown here:
Call: lm(formula = y ~ x)Coefficients: (Intercept) x 4.114 5.003
The estimated intercept is 4.11, while the estimated slope is 5.00. To get more information ...