Answer To: 1. In R copy the stackloss data into an object called Stack. For the 17th observation of Stack,...
Mohd answered on Nov 10 2021
-
-
-
11/10/2021
library(magrittr)
library(dplyr)
library(ggplot2)
library(rmarkdown)
library(skimr)
library(faraway)
library(ggeffects)
library(stargazer)
1. In R copy the stackloss data into an object called Stack. For the 17th observation of Stack, successively replace the Water.Temp value of 19 with the values 19, 20, 21, … 29 (degrees Celsius).
For each instance obtain the estimated regression coefficients (a four-vector) using least-squares and least-absolute values regression.
Then, for each coefficient, produce a plot of the coefficient estimate versus the value of Water.Temp that was used for the 17th observation.
Plot the least-squares and least-absolute values regression estimates on the same plot (use different colors).
Because there are four coefficients, you can use par(mfrow = c(2,2)) to make each one a separate subplot in a 2 × 2 plot matrix. Make sure that the subplots are properly labeled! When you are done,
write a few sentences to compare the sensitivity of least-squares versus least-absolute values regression to changes in this one observation.
Stack<-stackloss
mod_1<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_1)
plot(mod_1)
Stack[17,2]<-20
mod_2<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_2)
Stack[17,2]<-21
mod_3<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_3)
Stack[17,2]<-22
mod_4<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_4)
Stack[17,2]<-23
mod_5<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_6)
Stack[17,2]<-25
mod_7<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_7)
Stack[17,2]<-26
mod_8<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_8)
Stack[17,2]<-27
mod_9<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_9)
Stack[17,2]<-28
mod_10<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_10)
Stack[17,2]<-29
mod_11<-lm(stack.loss~Water.Temp,data=Stack)
#summary(mod_11)
stargazer(mod_1,mod_2,mod_3,mod_4,mod_5,type="text")
##
## ====================================================================================
## Dependent variable:
## ------------------------------------------------------
## stack.loss
## (1) (2) (3) (4) (5)
## ------------------------------------------------------------------------------------
## Water.Temp 2.817*** 2.815*** 2.786*** 2.729*** 2.647***
## (0.357) (0.370) (0.386) (0.405) (0.425)
##
## Constant -41.911*** -42.002*** -41.510*** -40.437*** -38.819***
## (7.606) (7.903) (8.273) (8.694) (9.137)
##
## ------------------------------------------------------------------------------------
## Observations 21 21 21 21 21
## R2 0.767 0.753 0.732 0.705 0.671
## Adjusted R2 0.754 0.740 0.718 0.689 0.654
## Residual Std. Error (df = 19) 5.043 5.187 5.400 5.670 5.982
## F Statistic (df = 1; 19) 62.373*** 57.922*** 51.967*** 45.360*** 38.821***
##...