Please include all code from
R that was used to calculate everything.
set.seed(1)
library(ggplot2)
epsilon=rnorm(100,0,6)
x=c(1:100)
y=1+2*x + epsilon
data=data.frame(x,y)
fit1=lm(y~x,data=data)
fit1
fit1$coefficients
ggplot(data , aes(x = x, y = y)) + geom_point(size = 0.8) +
stat_smooth(method = 'lm', formula = y ~ x)
summary(fit1)
# t statistic to check b1=2
#from summary we found, standard error of b1 = 0.02001
se=0.02001
b1=2
n=100
t=(as.numeric(fit1$coefficients[2])-2)/se
p_value =1-pt(abs(t),n-1)
# value comes out to be 0.403835 => We fail to reject null
hypothesis that b1=2 and conclude that b1=2
#-------------------------
b00=c()
b11=c()
for(i in 1:100){
set.seed(i)
x1=c(1:100)
e=rnorm(100,0,6)
y1=1+2*x1 + e
data1=data.frame(x1,y1)
fit2=lm(y1~x1,data=data1)
b00=c(b00,as.numeric(fit2$coefficients[1]))
b11=c(b11,as.numeric(fit2$coefficients[2]))
}
cor(b00,b11)
#correlation comes out to be -0.892052
Please include all code from R that was used to calculate everything. Problem 2 (0.5 x...