Code
source(file = file.path("Source", "functions.R"))Read in path and auxiliary functions
source(file = file.path("Source", "functions.R"))Load packages
source(file = file.path("Source", "rpackages.R"))noise <- list()
anz <- 25
set.seed(272024)#
for (i in 1:anz){
noise[[i]] <- 20-rtruncnorm(200, a=0,b=20, mean = 10, sd = 2)
}
df.noise<-as.data.frame(noise)
names(df.noise) <- c("V1","V2","V3","V4","V5","V6","V7","V8","V9","V10",
"V11","V12","V13","V14","V15","V16","V17","V18","V19",
"V20","V21","V22","V23","V24","V25")
group<- c(rep(0,100),rep(1,100))
data <- cbind(df.noise,group)
View(data)
candidate_models <- list(length=anz)
for(i in 1:anz){
candidate_models[[i]] <- formula(paste0(names(df.noise)[i],"~ group"))
}
# candidate_models[[5]]
summary_models <- list(length=anz)
for(i in 1:anz){
summary_models[[i]] <- summary(glm(candidate_models[[i]], data = data))
}
# summary_models[[9]]
# summary_models[[12]]
# library("broom")
tidy_model9 <- tidy(glm(candidate_models[[9]], data = data))
tidy_model9tidy_model12 <- tidy(glm(candidate_models[[12]], data = data))
tidy_model12## t-test ist äquivalent
# T-Test für Modell 9
test_9 <- t.test(candidate_models[[9]], var.equal = TRUE, alternative = "two.sided", data = data)
result_9 <- tibble(
Modell = "Modell 9",
t_Wert = round(test_9$statistic, 3),
df = round(test_9$parameter, 1),
p_Wert = round(test_9$p.value, 4),
Mittelwert_Gruppe1 = round(test_9$estimate[1], 2),
Mittelwert_Gruppe2 = round(test_9$estimate[2], 2)
)
# T-Test für Modell 12
test_12 <- t.test(candidate_models[[12]], var.equal = TRUE, alternative = "two.sided", data = data)
result_12 <- tibble(
Modell = "Modell 12",
t_Wert = round(test_12$statistic, 3),
df = round(test_12$parameter, 1),
p_Wert = round(test_12$p.value, 4),
Mittelwert_Gruppe1 = round(test_12$estimate[1], 2),
Mittelwert_Gruppe2 = round(test_12$estimate[2], 2)
)
# Ausgabe als separate Tabellen
kable(result_9, caption = "T-Test Ergebnis für Modell 9")| Modell | t_Wert | df | p_Wert | Mittelwert_Gruppe1 | Mittelwert_Gruppe2 |
|---|---|---|---|---|---|
| Modell 9 | 3.323 | 198 | 0.0011 | 10.49 | 9.6 |
kable(result_12, caption = "T-Test Ergebnis für Modell 12")| Modell | t_Wert | df | p_Wert | Mittelwert_Gruppe1 | Mittelwert_Gruppe2 |
|---|---|---|---|---|---|
| Modell 12 | 2.048 | 198 | 0.0419 | 10.12 | 9.55 |