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

Aus VoWi
Zur Navigation springen Zur Suche springen

Processors - Part 2[Bearbeiten | Quelltext bearbeiten]

Use the ANOVA to test the null hypothesis that all data were sampled from the same distribution, on the 5% significance level

  • (a) Calculate the f-statistic and the p-value (without using anova()) (b) Double-check your statistics using anova()
  • (c) Formulate a result
  • (d) Would you say that the assumptions for the ANOVA are fulfilled?

Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 17:44:44 CET

# Statistics and Probability - HW #10
# Friday 
# Duedate: 14.12.2020

# Problem 3 - Processors - Part 2
load("temperatures.Rdata")
k <- length(temp)
ni <- c()
for (i in 1:k) {
  ni <- c(ni, length(temp[[i]]))
}
n <- sum(ni)

# 3a)
# Calculate the f-statistic and the p-value (without using anova())
Xi <- c()
tmp1 <- 0
for (i in 1:k) {
  Xi <- c(Xi, (1/ni[i]) * sum(temp[[i]]))
  tmp1 <- tmp1 + sum(temp[[i]])
}
X <- (1/n) * tmp1

tmp2 <- 0
tmp3 <- 0
for (i in 1:k) {
  tmp2 <- tmp2 + (ni[i] * (Xi[i] - X)^2)
  
  for (Xij in temp[[i]]) {
    tmp3 <- tmp3 + ((Xij - Xi[i])^2)
  }
}

F <- ((1/(k-1))*tmp2)/((1/(n-k))*tmp3)
result_3a <- pf(F, k-1, n-k)


# 3b)
# Double-check your statistics using anova()
x <- c()
gr <- c()
for (i in 1:k) {
  for (n in temp[[i]]) {
    x <- c(x, n)
    gr <- c(gr, length(temp[[i]]))
  }
}
gr
anova(aov(x~gr))
result_3b <- anova(aov(x~gr))$`Pr(>F)`[1]
result_3b

# 3c)
# Formulate a result

# Since the results from 3a and 3b differ a lot, I will asume that 3b is
# correct, and 3a is has a computation error.

# We do not reject the hypothesis as p < alpha

# 3d)
# Would you say that the assumptions for the ANOVA are fulfilled?

# Yes, the measures are independend and