TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Levajkovic)/Übungen 2023W/HW09.5
Zur Navigation springen
Zur Suche springen
- Simulation of test-power
Simulate the distribution of the -value in the two-sided two-sample -test: Let , be independent random variables with for all . For each , derive -values in 10000 simulations and plot them in a histogram of unit area. Comment on your three histograms.
Dieses Beispiel ist als solved markiert. Ist dies falsch oder ungenau? Aktualisiere den Lösungsstatus (Details: Vorlage:Beispiel)
Hilfreiche Tipps[Bearbeiten | Quelltext bearbeiten]
Fast identisches Beispiel: Übungen 2020W - HW 10.6
Lösungsvorschlag von Lessi[Bearbeiten | Quelltext bearbeiten]
--Lessi 2024-02-07T13:04:11Z
# Simulate the distribution of the p-value in the two-sided two-sample t-test: Let X1, . . . , X20,
# Y1, . . . , Y20 be independent random variables with Xi ∼ N(0, 1) and Yi ∼ N(d, 1) for all
# i = 1, 2, . . . , 20. For each d ∈ {0, 0.25, 0.5}, derive p-values in 10000 simulations (H0 : d = 0)
# and plot them in a histogram of unit area. Comment on your three histograms.
i <- 20
par(mfrow=c(3,1))
for (d in c(0, 0.25, 0.5)) {
results <- c()
for (m in 0:10000) {
sampleX <- rnorm(i, 0, 1)
sampleY <- rnorm(i, d, 1)
p <- t.test(sampleY, sampleX, var.equal = TRUE)$p.value
results[m] <- p
}
hist(results, main = paste("Histogram for d =", d),
xlab = "P-Value", col = "lightblue", border = "black", probability = TRUE)
}
par(mfrow=c(1,1))