0
simulation in R
hi, I run the following code in R but this error shows up for "while" part: Error in beta_1 * x: non-numeric argument to binary operator beta_0 <- 2 beta_0 beta_1 <- 1 beta_1 sig <- 4 n=100 x <- sample(x,100) x eps <- rnorm(n,mean=3,sd=sig) y <- beta_0 + beta_1*x +eps ols <- lm(y~x) ols beta_1 <- rep(0,m) beta_1 library(data.table) m <- 10000 while(i <= m){  eps_i <-  rnorm(n,mean=0, sd=sig)  y_i <- beta_0 + beta_1*x + eps  beta_1[i] <- lm(y~x)  i <- i+1 } hist(beta_1) https://code.sololearn.com/c1ZX4J6Qbu33/?ref=app
5 Answers
+ 1
Where did you initialize i?
+ 1
People are more likely to test your code if you LINK your code instead of pasting it into the task description.
0
I added i=1 before "while" but I still get the error
0
You are trying to use variables before you have defined them several times.
Have a look at the comments that I made:
https://code.sololearn.com/creFra0W09N7/?ref=app
0
That simulation returns an error