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) } ############################################# sigma()/sqrt(5) qnorm(0.025, 3.5, sigma()/sqrt(5)) qnorm(0.975, 3.5, sigma()/sqrt(5)) a = proben(1, 6, 5, 100) sum(a < 2 | a > 5) werte = c( 6, 5, 6, 9, 6, 5, 6, 8, 5, 6, 10, 9) shut = sd(werte) SEhut = shut/sqrt(12) curve(dnorm(x, 0, 1), -4, 4) curve(dt(x, 3), -4, 4, add=T, col="blue") curve(dt(x, 10), -4, 4, add=T, col="red") mu = 6 n = length(werte) SEhut = sd(werte)/sqrt(n) # eingeschätzter SE frei = n - 1 # Freiheitsgrade mu + SEhut * qt(0.025, frei) # untere Grenze mu + SEhut * qt(0.975, frei) # obere Grenze mean(werte) mx = 200 sx = 20 nx = 20 my = 220 sy = 30 ny = 35 z = ((nx - 1) * sx^2) + ((ny - 1) * sy^2) nenn = nx + ny - 2 sqrt(z/nenn) * sqrt(1/nx + 1/ny) x = c(20, 15, 19, 22, 17, 16, 23, 18, 20) y = c(18, 15, 17, 24, 15, 12, 14, 11, 13, 17, 18) SEhut = SE2(x, y) d = mean(x) - mean(y) df = length(x) + length(y) - 2 d - qt(0.025, df) * SEhut d + qt(0.025, df) * SEhut t.test(x, y, var.equal=T) xlab = rep("winter", length(x)) ylab = rep("sommer", length(y)) d.df = data.frame(Dauer=c(x,y), Saison = factor(c(xlab, ylab))) t.test(Dauer ~ Saison, var.equal=T, data=d.df) mfdur = read.table(file.path(pfad, "mfdur.txt")) with(mfdur, tapply(duration, Gender, shapiro.test)) with(mfdur, tapply(duration, Gender, var)) var.test(duration ~ Gender, data = mfdur) wilcox.test(duration ~ Gender, data = mfdur) t.test(duration ~ Gender, data = mfdur) t.test(duration ~ Gender, var.equal=T, data = mfdur) tv = read.table(file.path(pfad, "tv.txt")) head(tv) with(tv, table(V)) # boxplot with(tv, 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 var.test(d ~ V, data=tv) # oder with(tv, var.test(d ~ V)) # Die Varianzen unterscheiden sich signifikant. Daher: t.test(d ~ V, data = tv)