Empirische Softwaretechnik Prof. Dr. Walter F. Tichy Dr. Matthias Müller Sommersemester 2006 1
Einführung in das Statistikpaket 2
R?! nicht vergleichbar mit den üblichen Statistikprogrammen wie SAS oder SPSS interactive computing with data de-facto Standard an den Unis kostet nichts! 3
Entwickler von R Ross Ihaka & Robert Gentleman (University of Auckland, New Zealand) R: A Language for Data Analysis and Graphics Journal of Computational and Graphical Statistics 5 (1996) 299-314 R Development Core Team (ab 1997) 4
Eigenschaften von R interaktiv programmierbar (basiert auf Version 3 der Sprache S) erweiterbar (Schnittstelle zu Programmiersprachen wie C, C++, Fortran, Java, Perl) umfangreiche Graphikfunktionen 5
Wo gibt s R? R-Webseite http://www.r-project.org/ CRAN = Comprehensive R Archive Network http://cran.r-project.org/ Binärdateien für Windows, Linux, Mac Quellen Bibliotheken ( packages ) Dokumentation (Handbücher, FAQ s) 6
So sieht s dann aus... 7
Bücher über R Dalgaard: Introductory Statistics with R (Springer, 2002) Venables & Smith: An Introduction to R (Network Theory Ltd., 2002) letzteres gibt s auch als PDF im Internet: http://cran.r-project.org/doc/manuals/r-intro.pdf 8
Sprache S entwickelt von John Chambers & Richard Becker ACM Software System Award 1998 für Chambers http://www.acm.org/awards/ssaward.html for the S system, which has forever altered how people analyze, visualize, and manipulate data 9
Bücher über S Becker & Chambers (1984): S. An Interactive Environment for Data Analysis and Graphics ( the brown book ) Version 1 von S Becker & Chambers & Wilks (1988): The New S Language ( the blue book ) Version 2 von S 10
Bücher über S (Forts.) Chambers & Hastie (1992): Statistical Models in S ( ) Version 3 von S Chambers (1998): Programming with Data. A Guide to the S Language ( the green book ) Version 4 von S 11
Statistik mit R Verteilungsfunktionen Testen von Hypothesen parametrisch: t-test, Pearson,... nicht-parametrisch: Wilcoxon, Spearman,... Lineare Regression...und noch mehr! 12
Explorative Datenanalyse mit R Punktwolken ( scatter plots ) Balkendiagramme ( bar plots ) Boxplots Regressionskurven 13
Datentypen Zahlen und Zeichen Boolesche Werte (TRUE, FALSE, NA) kategorielle Daten ( factors ) Vektoren (auch Zeichenketten) Matrizen (und mehrdimensionale Felder) (inhomogene) Listen Datensätze/-tabellen ( data frames ) 14
Wertzuweisungen x <- 12 x [1] 12 y <- c(13,2,11,3,7,5) y [1] 13 2 11 3 7 5 y <- seq(0,0.9,0.2) y [1] 0.0 0.2 0.4 0.6 0.8 15
Zeichnen der Standard- Normalverteilung x <- seq(-4,4,0.05) v <- dnorm(x,mean=0,sd=1) plot(x,v,type="l") 16
Rechengenauigkeit pi [1] 3.141593 options("digits") $digits [1] 7 options(digits=4) pi [1] 3.142 17
Binomialverteilung für MVP Parameter n = 1.000.000 und p = 0,1267657 Beobachtung b = 1255 options(digits=20) y <- pbinom(1254,size=1000000, prob=0.0001267657) 1 y [1] 0 einfach zu unwahrscheinlich! 18
Hypothesen-Test zu MVP options(digits=20) prop.test(1255,1000000,0.0001267657) 1-sample proportions test with continuity correction data: 1255 out of 1e+06, null probability 0.0001267657 X-squared = 10033.83, df = 1, p-value = < 2.2e-16... 19
Schleifen?! Schleifen sind langsam also vermeiden! Befehle in R sind stattdessen vektor- und matrixorientiert Beispiel: x <- seq(0,0.8,0.2) x + 1 [1] 1.0 1.2 1.4 1.6 1.8 wird recycled! 20
Korrelationstest nach Pearson vt <- c(0,3,5,0,3,5) wa <- c(116,132,135,152,154,181) cor.test(vt,wa) Pearson's product-moment correlation data: vt and wa t = 1.052, df = 4, p-value = 0.3521... cor 0.4655445 21
Zeichnen von Punktwolken plot(vt,wa,xlab="vererbungstiefe", ylab="wartungsaufwand") 22
Lineare Regression vt <- c(0,3,5,0,3,5) wa <- c(116,132,135,152,154,181) lm(wa~vt) Sprechweise: wa depends on vt Call: lm(formula = wa ~ vt) Coefficients: (Intercept) vt 132.579 4.658 23
Zeichnen der Regressionsgerade plot(vt,wa,xlab="vererbungstiefe", ylab="wartungsaufwand") abline(lm(wa~vt)) Sprechweise: a and b line 24
Postscript-Ausgabe postscript(file="vt-wa-plot.ps") plot(vt,wa) dev.off() 25
Einlesen von Tabellen "inheritdata.txt" enthält die Experimentdaten: vt mz wa 0 15 116 3 18 132 5 19 135 0 13... scan(file="inheritdata.txt",skip=2) [1] 0 15 116 3 18 132 5 19 135... 26
Einlesen von Tabellen (Forts.) temp <- scan(file="inheritdata.txt",skip=2) Read 42 items tempmat <- matrix(temp,ncol=3,byrow=true) tempmat [,1] [,2] [,3] [1,] 0 15 116 [2,] 3 18 132 [3,] 5 19 135... 27
Einlesen von Tabellen (Forts.) vt <- tempmat[,1] mz <- tempmat[,2] wa <- tempmat[,3] mz [1] 15 18 19 13 16 17... 28
Abspeichern von Tabellen write(t(tempmat),file="mat.txt",ncolumns=3) muß erst transponiert werden es werden 3 Spalten 29
selbst ausprobieren! 30
ENDE 31