200 likes | 286 Views
Introduction to. Alejandro Buren & Paul Regular. BIOL 7220 September 2012. What to expect from this workshop. Intro to R Data summaries Create plots Run General linear models Easily extensible to glm, gam, glmm, gamm BUT you have to know what you’re doing.
E N D
Introductionto Alejandro Buren & Paul Regular BIOL 7220 September 2012
What to expect from this workshop • Intro to R • Data summaries • Create plots • Run General linear models • Easily extensible to glm, gam, glmm, gamm • BUT you have to know what you’re doing
What NOT to expect from this workshop • A course in statistics • A showcase of R’s capabilities
What is R? • Environment and language for • Statistics • Graphics • Etc. • Open source
Why use R? • It’s FREE! • Flexible • One stop shop • Large up-front cost, but BIG payoff • Growing number of users • Expansive!
Download & Install • Program • R & Tinn-R installed? • Packages • Required to use statistical and graphical packages not included in the base package • Install once • Load each new session
Vectors • R has symbolic vectors which can be assigned values • The traditional way to do this in R is the ’<-’ operator • Possible vector names flexible • Vector names cannot start with a digit • Names are case-sensitive • Some common names are already used by R • c, q, t, C, D, F, I, T,
Functions • MANY built in functions • log() • exp() • sin() • sqrt() • mean() • max() • Etc.
Data Types • Vectors (Numeric, Character, Logical) • Matrix • All columns in a matrix must have same mode • Array • N-dimensional matrix • Dataframe • Columns in a data frame can have different modes. Similar to SAS and SPSS datasets • Lists • Collection of objects, can be different modes and dimensions • Factor
Data Management • Import & Export • Useful functions • subset • na.omit • cbind, rbind • sort • summaryBy • Operate over dataframe • Random numbers
Good Practice • Set up a working directory • Comment on each line of code • Avoid attach function • Define parameters in first lines of code • Use standard format • use.dots, OrCapitals, avoid spaces anywhere • Clean up
Statistics & Graphics • Working example • Look at data • Graph data • Run one regression and one ANOVA
HELP! • Useful websites • Official site (http://www.r-project.org/) • Manuals found on this site (http://cran.r-project.org/manuals.html) • R search site (http://finzi.psych.upenn.edu/search.html) • Quick-R (http://www.statmethods.net/index.html) • R graphics gallery (http://addictedtor.free.fr/graphiques/) • Books • The R Book • Etc. • List serve • ?function
Useful Packages...for us • Statistical • VEGAN • lme4 • gam • nnet • Rcmdr • Graphical • lattice • Rcmdr • gplots • Data management • RODBC • doBy • reshape
Possibilities... • Customized graphics... • Complex statistics...
GENERAL LINEAR MODELS ε ~ Normal R: lm() ANOVA Multiple Linear Regression t-test Simple Linear Regression ANCOVA
GENERALIZED LINEAR MODELS Linear combination of parameters R: glm() Multinomial Binomial Poisson GENERAL LINEAR MODELS ε ~ Normal R: lm() ANOVA Multiple Linear Regression t-test Simple Linear Regression ANCOVA Exponential Gamma Negative Binomial Inverse Gaussian
GENERALIZED ADDITIVE MODELS R: gam() GENERALIZED LINEAR MODELS Linear combination of parameters R: glm() Non-linear effect of covariates Multinomial Binomial Poisson GENERAL LINEAR MODELS ε ~ Normal R: lm() ANOVA Multiple Linear Regression t-test Simple Linear Regression ANCOVA Exponential Gamma Negative Binomial Inverse Gaussian
Fixed effects model Random effects model