#Zufallszahlengenerator für Exponentialverteilung schreiben rexp2<-function(n,lambda=1) { return(-1/lambda*log(runif(n))) } hist(rexp2(100),freq=F,main="Histogramm simulierte Werte Exp-Verteilung",xlab="x-Werte") plot(dexp,0,7,add=T,col="blue",lwd=2) legend(x = 1.3, y = 0.6, legend = c("Histogramm", "Exp(1)-Dichte"), lty = c(1, 1), col = c("black", "blue"), lwd = c(2, 2)) x<-rexp2(100) #Kolmogorov-Smirnow-Test auf Gammaverteilung mit Parametern 1, 1 ks.test(x, "pgamma", 1, 1) ks.test(x, "pexp", 1, 1) #Plotten der empirischen Verteilungsfunktion und der Verteilungsfunktion der Gamma(1,1)-Verteilung plot(ecdf(x)) plot(function(x) pgamma(x,1,1),0,10,add=T) #Shapiro-Wilk-Test auf Normalverteilung shapiro.test(rexp2(100)) rbeta22 <- function(n) { x<-rep(0,n) for (i in 1:n) { y<-runif(2) while (6*y[1]*(1-y[1]) < 3/2*y[2]) { y<-runif(2) } x[i]<-y[1] } return(x) } hist(rbeta22(1000),freq=F,main="Histogramm der simulierten Beta(2,2)-Zufallszahlen",xlab="x-Werte") plot(function(x) 6*x*(1-x),0,1,add=T) #Geometrische Verteilung simulieren (Beispiel nicht mehr geschafft in der Vorlesung) rgeo <- function(n,p) { u<-runif(n) return(floor(log(u)/log(1-p))+1) } x<-rgeo(100000,0.25) plot(ecdf(x)) plot(function(x) pgeom(x-1,0.25),0,20,add=T)