statistics - How to generate observations from a linear model in R -


i have been trying verify ols estimators consistent under usual assumptions.

could please tell me how generate observations linear model afterwards can run regression on data , verify desirable properties of ols?

thank in advance,

not clear if want??

# sample data: x1 , x2 uncorrelated df <- data.frame(x1=sample(1:100,100),x2=sample(1:100,100)) # y = 1 +2.5*x1 - 3.2*x2 + n(0,5) df$y <- with(df,1 + 2.5*x1 -3.2*x2 + rnorm(100,0,5))  fit  <- lm(y~x1+x2, data=df) summary(fit) #... # residuals: #     min      1q  median      3q     max  # -9.8951 -2.6056 -0.4384  3.6082  9.5044  # coefficients: #             estimate std. error  t value pr(>|t|)     # (intercept)    1.954      1.263    1.548    0.125     # x1             2.516      0.016  157.257   <2e-16 *** # x2            -3.237      0.016 -202.306   <2e-16 *** # --- # signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1  # residual standard error: 4.611 on 97 degrees of freedom # multiple r-squared:  0.9986,  adjusted r-squared:  0.9986  # f-statistic: 3.48e+04 on 2 , 97 df,  p-value: < 2.2e-16 

note se ~ 4.6 agrees "true" se = 5. note (intercept) estimated poorly because se(y|x) = 5.

par(mfrow=c(2,2)) plot(fit) 

note q-q plot confirms normality.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -