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

Aus VoWi
Zur Navigation springen Zur Suche springen

Processors - Part 3[Bearbeiten | Quelltext bearbeiten]

Perform pairwise t-tests (α = 5%) and correct the p-values according to Bonferroni

  • (a) How many pairs are to be tested?
  • (b) Give all p-values. Which null-hypotheses are to be rejected prior Bonferroni correction?
  • (c) Which null-hypotheses are to be rejected after Bonferroni correction?

Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 17:47:36 CET

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


# Problem 4 - Processors - Part 3
# Perform pairwise t-tests (α = 5%) and correct the p-values according to 
# Bonferron.
load("temperatures.Rdata")
alpha <- 5


# Problem 4a)
# How many pairs are to be tested?
k <- length(temp)
m <- (k*(k-1))/2
result_4a <- m
result_4a

# Problem 4b)
# Give all p-values. Which null-hypotheses are to be rejected prior 
# Bonferroni correction?
draw_ttest <- function(data, alpha) {
  colnames <- c()
  rownames <- c('p-value','color') 
  pvalues <- c()
  colors <- c()
  len <- length(data)
  
  for (i in 1:(len-1)) {
    for (j in (i+1):len){
      colnames <- c(colnames, sprintf("%d/%d", i, j))
      p <- t.test(data[[i]], data[[j]])$p.value
      pvalues <- c(pvalues, p)
      if (p < alpha) {
        colors <- c(colors, 'red')
      } else {
        colors<-c(colors, 'green')
      }
    }
  }
  
  tmp = matrix(NA, length(rownames), length(colnames))
  rownames(tmp) = rownames
  colnames(tmp) = colnames
  tmp[1,] <- pvalues
  tmp[2,] <- colors
  print(length(colors))
  return (tmp);
}
result_4b <- draw_ttest(temp, alpha)
result_4b

# Problem 4c)
# Which null-hypotheses are to be rejected after Bonferroni correction?
alpha_star <- alpha/m
result_4c <- draw_ttest(temp, alpha_star)
result_4c