########### # Blatt 3 # ########### #Aufgabe 2 library(MASS) data(crabs) attach(crabs) #a ?crabs head(crabs) summary(crabs) #a boxplot(crabs[4:8]) max(RW) points(2,max(RW), col = "magenta", pch = 19) #b mu_FL<-mean(FL) mu_RW<-mean(RW) mu_CL<-mean(CL) mu_CW<-mean(CW) mu_BD<-mean(BD) sd_FL<-sd(FL) sd_RW<-sd(RW) sd_CL<-sd(CL) sd_CW<-sd(CW) sd_BD<-sd(BD) hist(FL, freq = F) lines((min(FL)-1):(max(FL)+1),dnorm((min(FL)-1):(max(FL)+1), mean = mu_FL, sd = sd_FL), col = "red") legend(7,0.1,"Dichte der Normalverteilung", col = "red", pch = 20) hist(RW, freq = F) lines((min(RW)-1):(max(RW)+1),dnorm((min(RW)-1):(max(RW)+1), mean = mu_RW, sd = sd_RW), col = "red") legend(6,0.15,"Dichte der Normalverteilung", col = "red", pch = 20) hist(CL, freq = F, ylim = c(0, 0.06)) lines((min(CL)-1):(max(CL)+1),dnorm((min(CL)-1):(max(CL)+1), mean = mu_CL, sd = sd_CL), col = "red") legend(12,0.045,"Dichte der Normalverteilung", col = "red", pch = 20) hist(CW, freq = F, ylim = c(0,0.05)) lines((min(CW)-1):(max(CW)+1),dnorm((min(CW)-1):(max(CW)+1), mean = mu_CW, sd = sd_CW), col = "red") legend(15,0.04,"Dichte der Normalverteilung", col = "red", pch = 20) hist(BD, freq = F) lines((min(BD)-1):(max(BD)+1),dnorm((min(BD)-1):(max(BD)+1), mean = mu_BD, sd = sd_BD), col = "red") legend(6,0.1,"Dichte der Normalverteilung", col = "red", pch = 20) #d pairs(crabs[4:8], pch = 20) cor(crabs[4:8]) #Aufgabe 5 x<-matrix(ncol = 1000, nrow = 100) for(i in 1:100){ x[i,]<-rnorm(1000, mean = 2, sd = 5) } y<-matrix(ncol = 2, nrow = 100) for(i in 1:100){ y[i,1]<-mean(x[i,]) - qnorm(0.975) * (5/sqrt(1000)) y[i,2]<-mean(x[i,]) + qnorm(0.975) * (5/sqrt(1000)) } plot(0,0, type = "n", xlim = c(1,3), ylim = c(0,100)) for(i in 1:100){ lines(c(y[i,1],y[i,2]), c(i,i)) if(y[i,1] >= 2 || y[i,2] <= 2){lines(c(y[i,1],y[i,2]), c(i,i), col = "red")} } sum(y[,1] >= 2) + sum(y[,2] <= 2)