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

Aus VoWi
Zur Navigation springen Zur Suche springen

Regression (part 2)[Bearbeiten | Quelltext bearbeiten]

Continuation of exercise 4: Assume the linear regression model , with i.i.d. and , and . Test the null hypothesis (without lm()) at a significance level of 5%.

  • a) Compute the standard error of the regression .
  • b) Compute the standard error , of the slope .
  • c) Compute the value of the -statistc.
  • d) Compute the -distribution associated with .
  • e) Compute the -value.
  • f) Formulate a result.

Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 19:47:45 CET

5a)[Bearbeiten | Quelltext bearbeiten]

calc_sr <- function(x,y,b0,b1) {
  n <- length(x)
  result <- 0
  # Create the sum
  for (i in 1:n) {
    result <- result + (y[i] - (b0 + b1 * x[i]))^2
  }
  result <- sqrt(result /(n-2))
}
sr <- calc_sr(x, y, b0, b1)   # 8.762359

5b)[Bearbeiten | Quelltext bearbeiten]

n <- length(x)
seb <- sr/(sx * sqrt(n - 1))  # 0.08110709

5c)[Bearbeiten | Quelltext bearbeiten]

t <- (b1-0)/seb   # 2.864922

5d)[Bearbeiten | Quelltext bearbeiten]

alpha <- 0.05
q1 <- qt(1-alpha/2, df=n-2)   # 2.068658
I <- c(b1-q1*seb, b1+q1*seb)  # 0.0645827 0.4001483

5e)[Bearbeiten | Quelltext bearbeiten]

p <- pt(-t, df=n-2) * 2 # 0.0087558512

5f)[Bearbeiten | Quelltext bearbeiten]

The observed postive realation in the data is barely compatible with the null-hypothesis that there is no realation. If holds true we observed a case which occourse under of the cases.