# # Statistik fuer Informatiker, SS 2018, JGU Mainz # # Plots der bivariaten (Standard-)Normaldichte f <- function(x, y) { # (dies ist die 2-dim. Standardnormaldichte) exp(-x^2/2 - y^2/2)/(2*pi) } # Plotten der Dichte: x.werte <- seq(from=-2.5,to=2.5,by=0.05) # x- und y.werte <- seq(from=-2.5,to=2.5,by=0.05) # y-Werte auf 2-dim Gitter nd <- outer(x.werte, y.werte, f) image(x.werte, y.werte, nd, xlab='x', ylab='y', main='2-dim. Standard-Normaldichte,') # fuege Konturlinien hinzu contour(x.werte, y.werte, nd, add=TRUE) # Alternative plots mit einem Zusatzpaket (aus CRAN): library(fields) image.plot(x.werte,y.werte,nd,col=terrain.colors(15), xlab='$x$',ylab='$y$') contour(x.werte,y.werte,nd, add=TRUE) # (alternativ auch:) library(lattice) filled.contour(x.werte, y.werte, nd, xlab='x', ylab='y', main='2-dim. Standard-Normaldichte,', color.palette=heat.colors) # ########################################### # # Perspektivische Plots der 2d- Normaldichte: persp(x.werte, y.werte, nd, xlab='x',ylab='y',zlab='Dichte',axes=TRUE,ticktype='detailed') # ggfs. auch Sichtwinkel variieren, siehe auch ?persp # (Kobreite" phi, "Azimuthwinkel" theta) persp(x.werte, y.werte, nd, phi=20, theta=-30, xlab='x',ylab='y',zlab='Dichte',axes=TRUE,ticktype='detailed') persp(x.werte, y.werte, nd, phi=30, theta=20, xlab='x',ylab='y',zlab='Dichte',axes=TRUE,ticktype='detailed') # "eingefaerbte" persp-Plots # # die "Hoehenwerte" der Facettenmittelpunkte: hfm <- (nd[-1,-1]+nd[-1,-length(y.werte)]+nd[-length(x.werte),-1]+nd[-length(x.werte),-length(y.werte)])/4 anz.farben <- 15 a <- cut(hfm, quantile(hfm, seq(0,1, length.out=anz.farben+1), include.lowest=TRUE)) farbw <- terrain.colors(anz.farben)[a] persp(x.werte,y.werte,nd,col=farbw, phi=30, theta=35,ticktype="detailed", xlab='x',ylab='y', zlab="f(x,y)")