# Diese 3 Funktionen nach R kopieren (cut-and-paste) sigma <- function(unten=1, oben=6) { x = unten:oben n = length(x) m = mean(x) sqrt((sum(x^2)/n - m^2)) } proben <- function(unten=1, oben = 6, k = 10, N = 50) { # default: wir werfen 10 Wuerfel 50 Mal alle <- NULL for(j in 1:N){ ergebnis = mean(sample(unten:oben, k, replace=T)) alle = c(alle, ergebnis) } alle } SE2 <- function(x, y) { # SE von x und y zusammen # fuer einen 2-sample t-test nx = length(x) ny = length(y) sx = sd(x) sy = sd(y) num = ((nx - 1) * sx^2) + ((ny - 1) * sy^2) den = nx + ny - 2 sqrt(num/den) * sqrt(1/nx + 1/ny) } ############################################# # # S2 mu = 3.5 SE = sigma()/sqrt(5) # S4 qnorm(0.025, mu, SE) qnorm(0.975, mu, SE) a = proben(1, 6, 5, 100) sum(a < 2 | a > 5) # Die Abbildung curve(dnorm(x, mu, SE), xlim = c(0, 7), ylab="Wahrscheinlichkeitsdichte", xlab = "Zahlen-Mittelwert", axes=F) axis(side=2) axis(side=1, at=1:6, labels=as.character(1:6)) x = seq(qnorm(0.025, mu, SE), qnorm(0.975, mu, SE), length=1000) y = dnorm(x, mu, SE) lines(x, y, type="h", col="turquoise") # S6 werte = c( 6, 5, 6, 9, 6, 5, 6, 8, 5, 6, 10, 9) # S8 SE = sd(werte)/sqrt(length(werte)) # S10 curve(dnorm(x, 0, 1), -4, 4) # 3 Freiheitsgrade curve(dt(x, 3), -4, 4, add=T, col="blue") # 10 Freiheitsgrade curve(dt(x, 10), -4, 4, add=T, col="red") # S 11 mu = 6 n = length(werte) SE = sd(werte)/sqrt(n) df = n - 1 mu + SE * qt(0.025, df) mu + SE * qt(0.975, df) # S14 x = c(20, 15, 19, 22, 17, 16, 23, 18, 20) y = c(18, 15, 17, 24, 15, 12, 14, 11, 13, 17, 18) # S15 mu = mean(x) - mean(y) # S16 SE = SE2(x, y) # S17 mu = mean(x) - mean(y) SE = SE2(x,y) df = length(x)+length(y)-2 mu + qt(0.025, df) * SE mu + qt(0.975, df) * SE # S19 t.test(x, y, var.equal=T) # S20 xlab = rep("winter", length(x)) ylab = rep("sommer", length(y)) jahreszeit = factor(c(xlab, ylab)) d = c(x, y) d.df = data.frame(dauer = d, J = jahreszeit) t.test(dauer ~ J, var.equal=T, data=d.df) # S21 mfdur = read.table(file.path(pfad, "mfdur.txt")) head(mfdur) # S23 with(mfdur, tapply(duration, Gender, shapiro.test)) # S24 var.test(duration ~ Gender, data = mfdur) # 25 wilcox.test(duration ~ Gender, data = mfdur) # 26 t.test(duration ~ Gender, data = mfdur) t.test(duration ~ Gender, var.equal=T, data = mfdur) # 27 tv = read.table(file.path(pfad, "tv.txt")) head(tv) with(tv, table(V)) # boxplot boxplot(d ~ V, data=tv) # PrŸfen, ob sie einer Normalverteilung folgen with(tv, tapply(d, V, shapiro.test)) # alles OK # PrŸfen, ob sich die Varianzen unterscheiden with(tv, var.test(d ~ V)) # Die Varianzen unterscheiden sich signifikant. Daher: t.test(d ~ V, data = tv)