###Q1 code ###Plot the data plot(dat1$x, dat1$y) ###Fit the two regression models separately y1 <- dat1$y[1:777] y2 <- dat1$y[778:999] x1 <- dat1$x[1:777] x2 <- dat1$x[778:999] mod1 <- lm(y1~x1) mod2 <- lm(y2~x2) summary(mod1) summary(mod2) ###Fit a single joint regression model mod <- lm(y~t*x, data=dat1) summary(mod) ###Plot the fitted regression lines plot(dat1$x, dat1$y) segments(x0=0, x1=0.8, y0=mod1$coef[1], y1=mod1$coef[1]+mod1$coef[2]*0.8, col='red') segments(x0=0.8, x1=1, y0=mod2$coef[1]+mod2$coef[2]*0.8, y1=mod2$coef[1]+mod2$coef[2],col='red') ###Plot the residuals vs. fitted model values plot(residuals(mod),fitted(mod))