# Stochastik fuer Lehramt II, SS 2008 ########### # Blatt 5 # ########### #aufgabe 1 #a library(MASS) attach(crabs) # In der Reihenfolge im Datensatz: 50 mal BM, dann 50 mal BF, etc. combi<-c(rep("BM",50), rep("BF",50), rep("OM",50), rep("OF",50)) par(mfrow = c(1,5)) # Grafikfenster: 1x5 boxplot(FL ~ combi) # Werte in entsprechender Reihenfolge gepaart boxplot(RW ~ combi) boxplot(CL ~ combi) boxplot(CW ~ combi) boxplot(BD ~ combi) # Keine Ausreisser # Blaue kleiner als Orangene # In Blau: Female kleiner als Male; in Orange: Female groesser als Male # Streuungen ungefaehr gleich #b # i. arithm. Mittel der Mittelwerte der anderen Krebse sieht verschieden aus # wie Mittelwert der OM Krebse (siehe ii, die mu_CL und mu_RW Werte) # ii. mu_CL<-mean(CL[combi != "OM"]) # 31.578 mu_RW<-mean(RW[combi != "OM"]) # 12.89733 # Annahmebereich untere Grenze # Nach Herrn Unwin Folien in mu_0 lb_CL<-mu_CL - qnorm(0.995) * sqrt(50/50) # 29.00217 lb_RW<-mu_RW - qnorm(0.995) * sqrt(6.8/50) # 11.94741 #Annahmebereich obere Grenze # Nach Herrn Unwin Folien in mu_0 ub_CL<-mu_CL + qnorm(0.995) * sqrt(50/50) # 34.15383 ub_RW<-mu_RW + qnorm(0.995) * sqrt(6.8/50) # 13.84725 # Annahmebereiche sind jetzt [lb_CL,ub_CL] und [lb_RW,ub_RW] #Erwartungswert von orangen maennlichen Krebsen mu_CL_OM<-mean(CL[combi == "OM"]) # 33.688 mu_RW_OM<-mean(RW[combi == "OM"]) # 12.262 (vgl. oben) #Test (lb_CL <= mu_CL_OM) && (ub_CL >= mu_CL_OM) # H_0 nicht abgelehnt (lb_RW <= mu_RW_OM) && (ub_RW >= mu_RW_OM) # H_0 nicht abgelehnt # siehe auch Werte oben #aufgabe 2 iq<-c(84,88,89,92,94,96,97,99,99,101,102,102,103,106,109,111,111,113, 115,116,117,120,122,126,132) mean(iq) # 105.76 #aufgabe 5 #Simulation von 1000 Stichproben verschiedener Groessen n aus einer #Standardnormalverteilung #n=10, alpha=0.05, H_0: mu=0 y1<-matrix(ncol = 2, nrow = 1000) # Ablehnungsbereich nach KI aus Herrn Unwin Folien; H_0 ablehnen, # falls 0 nicht in KI(x_quer) for(i in 1:1000){ mu<-mean(rnorm(10)) y1[i,1]<-mu - qnorm(0.975) * (1/sqrt(10)) # untere Grenze des KI y1[i,2]<-mu + qnorm(0.975) * (1/sqrt(10)) # obere Grenze des KI } # H_0 gilt (liegt den Daten zugrunde), aber H_0 ablehnen; wie oft: (sum(y1[,1] > 0) + sum(y1[,2] < 0))/1000 # z.B. 0.058 #n=100, alpha=0.05, H_0:mu=0 y2<-matrix(ncol = 2, nrow = 1000) for(i in 1:1000){ mu<-mean(rnorm(100)) y2[i,1]<-mu - qnorm(0.975) * (1/sqrt(100)) y2[i,2]<-mu + qnorm(0.975) * (1/sqrt(100)) } (sum(y2[,1] > 0) + sum(y2[,2] < 0))/1000 # z.B. 0.041 #n=1000, alpha=0.05, H_0:mu=0 y3<-matrix(ncol = 2, nrow = 1000) for(i in 1:1000){ mu<-mean(rnorm(1000)) y3[i,1]<-mu - qnorm(0.975) * (1/sqrt(1000)) y3[i,2]<-mu + qnorm(0.975) * (1/sqrt(1000)) } (sum(y3[,1] > 0) + sum(y3[,2] < 0))/1000 # z.B. 0.051 # Grafische Darstellung par(mfrow = c(3,1)) # Grafikfenster 3x1 plot(0,0, type = "n", xlim = c(-2,2), ylim = c(0,1000)) for(i in 1:1000){ lines(c(y1[i,1],y1[i,2]), c(i,i)) if(y1[i,1] > 0 || y1[i,2] < 0){lines(c(y1[i,1],y1[i,2]), c(i,i), col = "red")} } # KIs, die 0 nicht enthalten, d.h. H_0 ablehnen, sind rot (Fehler 1. Art) plot(0,0, type = "n", xlim = c(-2,2), ylim = c(0,1000)) for(i in 1:1000){ lines(c(y2[i,1],y2[i,2]), c(i,i)) if(y2[i,1] >= 0 || y2[i,2] <= 0){lines(c(y2[i,1],y2[i,2]), c(i,i), col = "red")} } # KIs, die 0 nicht enthalten, d.h. H_0 ablehnen, sind rot (Fehler 1. Art) plot(0,0, type = "n", xlim = c(-2,2), ylim = c(0,1000)) for(i in 1:1000){ lines(c(y3[i,1],y3[i,2]), c(i,i)) if(y3[i,1] >= 0 || y3[i,2] <= 0){lines(c(y3[i,1],y3[i,2]), c(i,i), col = "red")} } # KIs, die 0 nicht enthalten, d.h. H_0 ablehnen, sind rot (Fehler 1. Art) # Fazit: #Ergebnis nicht von Stichprobengroesse abhaengig!! (Fehler 1.Art ca. 0.05) #Aber Intervallgroesse nimmt mit Stichprobengroesse ab! (Bild wird bzgl. x-Achse #schmaller) #"Repraesentatitivitaet" spielt hier keine Rolle; d.h. mit wachsendem n werden # Fehler 1. Art nicht besser