# Stochastik IV, Übungsblatt 2 # Aufgabe 4 # Einlesen der Daten und Einbinden in Suchpfad data.crabs <- read.table("D:/Univ Augsburg/Lehre/SS07/VO_MultiVar/Datensaetze/crabs.txt", header = TRUE, sep = "\t", quote = "") attach(data.crabs) # Histogramme und überlagerte Kerndichteschätzer und Normalverteilungen par(mfrow = c(3,2)) # Frontal Lobe Size (FL) hist(FL, freq = FALSE, col ="grey", xlab = "FL (frontal lobe size, mm)") curve(dnorm(x, mean(FL), sd(FL)), add = TRUE, col = "red", lwd = 3) lines(density(FL), lwd = 3) # Rear Width (RW) hist(RW, freq = FALSE, col ="grey", xlab = "RW (rear width, mm)") curve(dnorm(x, mean(RW), sd(RW)), add = TRUE, col = "red", lwd = 3) lines(density(RW), lwd = 3) # Carapace Length (CL) hist(CL, freq = FALSE, col ="grey", xlab = "CL (carapace length, mm)", ylim = c(0.00, 0.06)) curve(dnorm(x, mean(CL), sd(CL)), add = TRUE, col = "red", lwd = 3) lines(density(CL), lwd = 3) # Carapace Width (CW) hist(CW, freq = FALSE, col ="grey", xlab = "CW (carapace width, mm)", ylim = c(0.00, 0.06)) curve(dnorm(x, mean(CW), sd(CW)), add = TRUE, col = "red", lwd = 3) lines(density(CW), lwd = 3) # Body Depth (BD) hist(BD, freq = FALSE, col ="grey", xlab = "BD (body depth, mm)") curve(dnorm(x, mean(BD), sd(BD)), add = TRUE, col = "red", lwd = 3) lines(density(BD), lwd = 3) frame() legend(c(0,1), c(0.3,1), c("Histogram", "Kernel Density Estimate", "Normal Distribution"), fill = c("grey", "black", "red")) windows() # QQ-Plots par(mfrow = c(3,2)) # Frontal Lobe Size (FL) plot(qnorm(ppoints(FL), mean(FL), sd(FL)), sort(FL), xlab = "Theoretical Quantiles of Normal Distribution", ylab = "Sample Quantiles of FL", main ="QQ-Plot [FL]") abline(0,1, col = "red", lwd = 2) lines(c(quantile(FL, 0.25), quantile(FL, 0.75)), c(qnorm(0.25, mean(FL), sd(FL)), qnorm(0.75, mean(FL), sd(FL))), lty = 2, col = "blue", lwd = 2) # Rear Width (RW) plot(qnorm(ppoints(RW), mean(RW), sd(RW)), sort(RW), xlab = "Theoretical Quantiles of Normal Distribution", ylab = "Sample Quantiles of RW", main ="QQ-Plot [RW]") abline(0,1, col = "red", lwd = 2) lines(c(quantile(RW, 0.25), quantile(RW, 0.75)), c(qnorm(0.25, mean(RW), sd(RW)), qnorm(0.75, mean(RW), sd(RW))), lty = 2, col = "blue", lwd = 2) # Carapace Length (CL) plot(qnorm(ppoints(CL), mean(CL), sd(CL)), sort(CL), xlab = "Theoretical Quantiles of Normal Distribution", ylab = "Sample Quantiles of CL", main ="QQ-Plot [CL]") abline(0,1, col = "red", lwd = 2) lines(c(quantile(CL, 0.25), quantile(CL, 0.75)), c(qnorm(0.25, mean(CL), sd(CL)), qnorm(0.75, mean(CL), sd(CL))), lty = 2, col = "blue", lwd = 2) # Carapace Width (CW) plot(qnorm(ppoints(CW), mean(CW), sd(CW)), sort(CW), xlab = "Theoretical Quantiles of Normal Distribution", ylab = "Sample Quantiles of CW", main ="QQ-Plot [CW]") abline(0,1, col = "red", lwd = 2) lines(c(quantile(CW, 0.25), quantile(CW, 0.75)), c(qnorm(0.25, mean(CW), sd(CW)), qnorm(0.75, mean(CW), sd(CW))), lty = 2, col = "blue", lwd = 2) # Body Depth (BD) plot(qnorm(ppoints(BD), mean(BD), sd(BD)), sort(BD), xlab = "Theoretical Quantiles of Normal Distribution", ylab = "Sample Quantiles of BD", main ="QQ-Plot [BD]") abline(0,1, col = "red", lwd = 2) lines(c(quantile(BD, 0.25), quantile(BD, 0.75)), c(qnorm(0.25, mean(BD), sd(BD)), qnorm(0.75, mean(BD), sd(BD))), lty = 2, col = "blue", lwd = 2) frame() legend(c(0,1), c(0.3,1), c("Graph of QQ-Plot", "Line y = x", "Line Segment 1. and 3. quartiles"), fill = c("black", "red", "blue")) # Varianz-Kovarianz Matrix cov(data.crabs[, 4:8])