TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Bura)/Übungen 2020W/HW11.6

Aus VoWi
Zur Navigation springen Zur Suche springen

Regression (part 3)[Bearbeiten | Quelltext bearbeiten]

Now perform the analysis from exercise 5 using the command lm().

  • a) Fit the data to the model using the command lm. Read the outcome of the test of the null hypothesis from the output of summary().
  • b) Again plot the data points and the regression line and discuss the plausibility of the model assumptions.
  • c) Which result in the exam would you predict for a students that achieved 140 points in the exercises? Mark the prediction in the plot.
  • d) What is the error that you have taken into account in your prediction? Add to your graphic two lines which are parallel to the regression line, but whose intercept is first raised and second lowered by one standard error of the regression.

Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 20:12:58 CET

This solution builds upon my solution of 11.5

1a)[Bearbeiten | Quelltext bearbeiten]

summary(lm(y~x))[["coefficients"]]   
#   Estimate  Std. Error  t value    Pr(>|t|)
#   (Intercept) 42.9352244 10.47420105 4.099141 0.000439672
#   x            0.2323655  0.08110709 2.864922 0.0087558

1b)[Bearbeiten | Quelltext bearbeiten]

abline(lm(y~x), col="coral1", lwd=1)

1c)[Bearbeiten | Quelltext bearbeiten]

b0 <- lm(y~x)$coefficients[1]
b1 <- lm(y~x)$coefficients[2]
prediction <- b0 + b1 * 140 # 75.5
points(140, prediction, pch=19, col="dodgerblue")

1d)[Bearbeiten | Quelltext bearbeiten]

sr      # 8.762359
abline(b0+sr, b1, col="gold", lwd=1)
abline(b0-sr, b1, col="gold", lwd=1)