a <- 2
b <- 3
sig_sq <- 1
x <- runif(40)
y <- a + b * x + rnorm(40, sd = sqrt(sig_sq))
(avg_x <- mean(x))
## [1] 0.4657908
write(avg_x, "avg_x.txt")
plot(x, y)
abline(a = a, b = b, col = "hotpink", lwd = 2)

my_fit <- lm(y ~ x)
summary(my_fit)
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.42438 -0.67534 0.06124 0.72514 2.53697
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.0440 0.3293 6.207 2.96e-07 ***
## x 2.9385 0.5979 4.914 1.73e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.111 on 38 degrees of freedom
## Multiple R-squared: 0.3886, Adjusted R-squared: 0.3725
## F-statistic: 24.15 on 1 and 38 DF, p-value: 1.734e-05