170 likes | 294 Views
Introduction to R project. Marek Majdan. R project. Statistical computing environment and software Absolutely free Updated by statisticians Very powerfull Basically unlimited capability. R project - principle. Editor. R Engine. SCRIPT. Graphical Output. Numerical output.
E N D
Introduction to R project Marek Majdan Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
R project • Statistical computing environment and software • Absolutely free • Updated by statisticians • Very powerfull • Basically unlimited capability Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
R project - principle Editor R Engine SCRIPT Graphical Output Numerical output Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Script example library (RODBC) library(foreign) library(Hmisc) library(Design) library(graphics) barb <- sqlFetch(odbcConnectExcel("d:/barb_data_new.xls"), sqtable = "data", na.strings = "NA", as.is = T) summary(barb) describe(barb) describe(barb$barb_group) ##normality tests shapiro.test(barb$AGE_CORRECTED) Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Packages • Base package • Contributed packages - specific functions written for specific purposes - not included in the base package - can be installed any time Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
R EDITOR NUMERICAL OUTPUT GRAPHICAL OUTPUT Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Installing R Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Installing R Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Installing Packages 1. 3. 2. Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Writing scripts • Every package contains ‘functions’ for performing various operations with data • Every function has a specific form and arguments needed • Every function has a specific output • An algorithm of functions to perform a specific sequence of actions is a script Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Example I. • Function: library • To load a specific package • Form: library (name of package) library (Epicalc) library (Hmisc) Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Example II. • Function: plot • To plot a graph • Simple form: plot(x) • Complex form with a number of additional arguments: plot(x <- sort(rnorm(47)), type = "s", main = "plot(x, type = \"s\")") points(x, cex = .5, col = "dark red") Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Important notes • Case sensitivity Plot ≠ plot ≠ PLOT • Avoid using punctuation and spaces in names of databases or variables (e.g. use ‘age_category’ instead ‘Age category’) Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
Importing data to R from Excel • Package: RODBC • Function: X=sqlFetch(odbcConnectExcel(“Y"),sqtable = “Z", na.strings = "NA", as.is = T) X=name of database in R after importing Y=path to excel file on disk Z=name of excel sheet Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
R commander • Graphical user interface (GUI) • Makes basic statistical computations simple but puts certain restrictions on R • Installing R commander: install package ‘Rcmdr’ using the standard package installing procedure • Function: library(Rcmdr) to start R commander Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com
R commander Training in essential biostatistics for Public Health Professionals in BiH, Marek Majdan, PhD; marekmajdan@gmail.com