first r-03: r packages - university of...

36
Descriptive 1 / 36 First R-03: R packages Paul E. Johnson 1 2 1 Department of Political Science 2 Center for Research Methods and Data Analysis, University of Kansas 2015

Upload: others

Post on 17-Jan-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 1 / 36

First R-03: R packages

Paul E. Johnson1 2

1Department of Political Science

2Center for Research Methods and Data Analysis, University of Kansas

2015

Page 2: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 2 / 36

An Engine with a lot of Packages

Ross Ihaka and Robert Gentleman created the original R programin the mid 1990s

a computational engine that could tolerate the addition offeatures in the form of “packages”

New Zealand junk car story

User commands followed the style of the S language (BellLabs) but internal logic different

R framework “bolts together” computational routines writtenin Fortran, C, C++, Objective C, Java, etc.

Page 3: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 3 / 36

Start R, what packages are loaded?

Run “sessionInfo()”.

> s e s s i o n I n f o ( )

R v e r s i o n 3 . 1 . 2 (2014−10−31)P la t fo rm : x86 64−pc− l inux−gnu (64 −bit )

l o c a l e :[ 1 ] LC CTYPE=en US.UTF−8 LC NUMERIC=C

LC TIME=en US.UTF−8 LC COLLATE=en US.UTF−8LC MONETARY=en US.UTF−8

[ 6 ] LC MESSAGES=en US.UTF−8 LC PAPER=en US.UTF−8LC NAME=C LC ADDRESS=CLC TELEPHONE=C

[ 1 1 ] LC MEASUREMENT=en US.UTF−8 LC IDENTIFICATION=C

at tached base packages :[ 1 ] s t a t s g r a p h i c s g rDev i c e s u t i l s d a t a s e t s base

l oaded v i a a namespace ( and not a t t a ched ) :

Page 4: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 4 / 36

Start R, what packages are loaded? ...

[ 1 ] t o o l s 3 . 1 . 2

Page 5: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 5 / 36

The importance of packages

R’s core functionality, the part that users think is R itself, isdrawn from the packages “graphics” and “stats”.

When you run into trouble, it is important to tell others whichpackages are loaded. (Hence my advice “always show themsessionInfo()”).

Page 6: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 6 / 36

List the packages your System Already Has

Lets check my Laptop on 2015-08-12:

> l i b r a r y ( )

Packages i n l i b r a r y '/home/ pau l j ohn /R/x86 64−pc− l inux−gnu− l ibrary /3 . 1 ' :

ab ind Combine Mu l t i d imen s i o n a l A r r ay sa c c e l e r ome t r y Func t i on s f o r P r o c e s s i n g Minute−to−Minute

Acce l e r ome t e r Dataacepack ace ( ) and avas ( ) f o r s e l e c t i n g r e g r e s s i o n

t r a n s f o rma t i o n sacp Au t o r e g r e s s i v e C ond i t i o n a l Po i s sonAc t i g r aphy Ac t i g r aphy Data An a l y s i sADGofTest Anderson−Darl ing GoF t e s tAER App l i ed Economet r i c s w i th Rakima I n t e r p o l a t i o n o f i r r e g u l a r l y spaced dataape Ana l y s e s o f Ph y l o g e n e t i c s and Evo l u t i o nap lpack Another P lo t PACKage : s t em . l e a f , bagp lo t ,

f a c e s , spin3R , plotsummary , p l o t h u l l s , and somes l i d e r f u n c t i o n s

arm Data An a l y s i s Us ing Reg r e s s i o n andMu l t i l e v e l / H i e r a r c h i c a l Models

a s s e r t t h a t Easy p re and pos t a s s e r t i o n s .bayesm Bayes i an I n f e r e n c e f o r

Market ing /Micro−Econometr icsbbmle Too l s f o r g e n e r a l maximum l i k e l i h o o d e s t ima t i o n

Page 7: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 7 / 36

List the packages your System Already Has ...

bdsmat r i x Rou t i n e s f o r Block Diagona l Symmetric ma t r i c e sbeeswarm The Bee Swarm Plot , an A l t e r n a t i v e to

S t r i p c h a r tb e t a r e g Beta Reg r e s s i o nBH Boost C++ Header F i l e sb i t o p s B i tw i s e Ope ra t i on sbootES Boot s t r ap E f f e c t S i z e sB rad l e yTe r r y2 Bradley−Terry Modelsbrew Templat ing Framework f o r Report Gene r a t i onbrglm Bia s r e d u c t i o n i n b inomia l− r e sponse g e n e r a l i z e d

l i n e a r mode l s .c a r Companion to App l i ed Reg r e s s i o nc a r e t C l a s s i f i c a t i o n and Reg r e s s i o n T r a i n i n gcaToo l s Too l s : moving window s t a t i s t i c s , GIF , Base64 ,

ROC AUC, e t c .cem Coarsened Exact Matchingchron Ch r o n o l o g i c a l Ob j e c t s which can Handle Dates

and Timescoda Output An a l y s i s and D i a g n o s t i c s f o r MCMCco i n Cond i t i o n a l I n f e r e n c e Procedu re s i n a

Permutat ion Test Frameworkc o l o r s p a c e Co lo r Space Man ipu l a t i oncombinat c omb i n a t o r i c s u t i l i t i e sc ompo s i t i o n s Compos i t i ona l Data An a l y s i scopu l a Mu l t i v a r i a t e Dependence wi th Copu lasc o r p co r E f f i c i e n t E s t ima t i on o f Cova r i ance and

( P a r t i a l ) C o r r e l a t i o n

Page 8: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 8 / 36

List the packages your System Already Has ...

cor rgram P lo t a Cor re log ramcrayon Co lo r ed Termina l Outputc u r l A Modern and F l e x i b l e Web C l i e n t f o r RDataCombine Too l s f o r E a s i l y Combining and C l e an i ng Data

Se t sd a t a . t a b l e Ex t en s i on o f da t a . f r ameDBI R Database I n t e r f a c eDEoptimR D i f f e r e n t i a l E v o l u t i o n Opt im i z a t i on i n Pure Rd e v t o o l s Too l s to Make Deve l op ing R Packages E a s i e rDiagrammeR Crea te Diagrams and F l owcha r t s Us ing Rd ichromat Co lo r Schemes f o r Dichromatsd i g e s t Crea te C r yp t og r aph i c Hash D i g e s t s o f R Ob j ec t sd i s t i l l e r y Method Func t i on s f o r Con f i d ence I n t e r v a l s and

to D i s t i l l I n f o rma t i o n from an ObjectD i s t r i b u t i o n U t i l s D i s t r i b u t i o n U t i l i t i e sd o P a r a l l e l Foreach p a r a l l e l adapto r f o r the p a r a l l e l

packaged p l y r A Grammar o f Data Man ipu l a t i ondynsim Dynamic S imu l a t i o n s o f A u t o r e g r e s s i v e

R e l a t i o n s h i p se1071 Misc Func t i on s o f the Department o f S t a t i s t i c s ,

P r o b a b i l i t y Theory Group ( Former l y : E1071 ) , TUWien

e a r t h Mu l t i v a r i a t e Adapt i ve Reg r e s s i o n S p l i n e se f f e c t s E f f e c t D i s p l a y s f o r L inea r , G e n e r a l i z e d L inea r ,

and Other Modelse f f s i z e E f f i c i e n t E f f e c t S i z e Computation

Page 9: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 9 / 36

List the packages your System Already Has ...

e l l i p s e Func t i on s f o r drawing e l l i p s e s and e l l i p s e− l i k ec o n f i d e n c e r e g i o n s

emdbook Support Func t i on s and Data f o r ”E c o l o g i c a lModels and Data ”

emu la to r Bayes i an emu la t i on o f computer programsene rgy E− s t a t i s t i c s ( ene rgy s t a t i s t i c s )e s t i m a b i l i t y E s t i m a b i l i t y Too l s f o r L i n e a r Modelse v a l u a t e Pa r s i ng and Eva l u a t i o n Too l s t ha t P rov i d e More

D e t a i l s than the De f au l tevd Func t i on s f o r ext reme va l u e d i s t r i b u t i o n sevdbayes Bayes i an An a l y s i s i n Extreme Value Theoryexpm Matr i x e x p o n e n t i a lexpsmooth Data Se t s from ”Fo r e c a s t i n g wi th Exponen t i a l

Smoothing ”extRemes Extreme Value An a l y s i sez Easy a n a l y s i s and v i s u a l i z a t i o n o f f a c t o r i a l

e x p e r im en t s .f a s t ICA FastICA A lgo r i t hms to per fo rm ICA and

P r o j e c t i o n Pu r s u i tf B a s i c s Rmet r i c s − Markets and Bas i c S t a t i s t i c sfda Fun c t i o n a l Data An a l y s i sfGarch Rmet r i c s − Au t o r e g r e s s i v e Co nd i t i o n a l

H e t e r o s k e d a s t i c Mode l l i ngf i e l d s Too l s f o r S p a t i a l Dataf l e xm i x F l e x i b l e Mixtu re Model ingfma Data s e t s from ”Fo r e c a s t i n g : methods and

a p p l i c a t i o n s ” by Makr idak i s , Whee lwr ight &

Page 10: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 10 / 36

List the packages your System Already Has ...

Hyndman (1998)f o r e a c h Foreach l o o p i n g c o n s t r u c t f o r Rf o r e c a s t F o r e c a s t i n g Func t i on s f o r Time S e r i e s and

L i n e a r Modelsf o r e i g n Read Data Sto red by Minitab , S , SAS , SPSS ,

Stata , Sys ta t , Weka , dBase , . . .formatR Format R Code Au t oma t i c a l l yFormula Extended Model Formulasfpp Data f o r ”F o r e c a s t i n g : p r i n c i p l e s and p r a c t i c e ”f r a c d i f f F r a c t i o n a l l y d i f f e r e n c e d ARIMA aka

ARFIMA(p , d , q ) modelsgam Gen e r a l i z e d Add i t i v e ModelsGAMBoost G e n e r a l i z e d l i n e a r and a d d i t i v e models by

l i k e l i h o o d based boo s t i n ggamlss G e n e r a l i s e d Add i t i v e Models f o r Loca t i on Sca l e

and Shapegaml s s . add Ext ra Add i t i v e Terms f o r GAMLSS Modelsg am l s s . c e n s F i t t i n g an I n t e r v a l Response Va r i a b l e Us ing

g am l s s . f am i l y D i s t r i b u t i o n sg am l s s . d a t a GAMLSS Datag am l s s . d i s t D i s t r i b u t i o n s to be Used f o r GAMLSS Mode l l i ngg am l s s . n l F i t t i n g non l i n e a r p a r ame t r i c GAMLSS modelsg am l s s . t r Gene r a t i ng and f i t t i n g t r un c a t e d

( g am l s s . f am i l y ) d i s t r i b u t i o n sgamm4 Gen e r a l i z e d a d d i t i v e mixed models u s i n g mgcv

and lme4gbm Gen e r a l i z e d Boosted Reg r e s s i o n Models

Page 11: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 11 / 36

List the packages your System Already Has ...

g c l u s C l u s t e r i n g Graph i c sgcmr Gaus s i an Copula Marg ina l R e g r e s s i o ngdata Va r i ou s R Programming Too l s f o r Data

Man ipu l a t i onG e n e r a l i z e dHyp e r b o l i c The G en e r a l i z e d Hyp e r bo l i c D i s t r i b u t i o nGenOrd S imu l a t i o n o f O rd i n a l and D i s c r e t e V a r i a b l e s

w i th Given C o r r e l a t i o n Matr i x and Marg ina lD i s t r i b u t i o n s

geoR An a l y s i s o f G e o s t a t i s t i c a l DataGGa l l y Ex t en s i on to g g p l o t 2 .ggp l o t 2 An Imp l ementa t i on o f the Grammar o f G raph i c sggthemes Ext ra Themes , S c a l e s and Geoms f o r `ggp lo t2 `

g i t 2 r P r o v i d e s Access to G i t R e p o s i t o r i e sg lmnet Lasso and E las t i c−Net Regu l a r i z e d G en e r a l i z e d

L i n e a r Modelsgmodels Va r i ou s R Programming Too l s f o r Model F i t t i n ggmp Mu l t i p l e P r e c i s i o n A r i t hme t i cg p l o t s Va r i ou s R Programming Too l s f o r P l o t t i n g Datag r i dBa s e I n t e g r a t i o n o f base and g r i d g r a p h i c sg r i d E x t r a M i s c e l l a n e o u s Func t i on s f o r ”Gr id ” Graph i c sg s l wrapper f o r the Gnu S c i e n t i f i c L i b r a r yg s s Gene ra l Smoothing S p l i n e sgsub fn U t i l i t i e s f o r s t r i n g s and f u n c t i o n a rgument s .g t a b l e Arrange g robs i n t a b l e s .g t o o l s Va r i ou s R Programming Too l shaven Import SPSS , Sta ta and SAS F i l e sheavy Package f o r r obu s t e s t ima t i o n u s i n g

Page 12: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 12 / 36

List the packages your System Already Has ...

heavy− ta i l ed d i s t r i b u t i o n sh f l i g h t s F l i g h t s t ha t depa r t ed Houston i n 2011HH S t a t i s t i c a l A n a l y s i s and Data D i s p l a y :

He i b e r g e r and Ho l l andh i g h r Syntax H i g h l i g h t i n g f o r R Source CodeHis tData Data s e t s from the h i s t o r y o f s t a t i s t i c s and

data v i s u a l i z a t i o nHmisc H a r r e l l M i s c e l l a n e o u sh tm l t o o l s Too l s f o r HTMLhtmlw idge t s HTML Widgets f o r Rht tpuv HTTP and WebSocket s e r v e r l i b r a r yh t t r Too l s f o r Working wi th URLs and HTTPi g r aph Network An a l y s i s and V i s u a l i z a t i o ni r l b a Fas t p a r t i a l SVD by im p l i c i t l y− r e s t a r t e d

Lanczos b i d i a g o n a l i z a t i o ni smev An I n t r o d u c t i o n to S t a t i s t i c a l Model ing o f

Extreme Va luesi t e r a t o r s I t e r a t o r c o n s t r u c t f o r RJM Jo i n t Model ing o f L o n g i t u d i n a l and S u r v i v a l

Dataj s o n l i t e A Robust , High Per formance JSON Pa r s e r and

Gene ra to r f o r Rk n i t r A General−Purpose Package f o r Dynamic Report

Gene r a t i on i n Rks Ke rne l Smoothingl a b e l i n g Ax i s L ab e l i n gLahman Sean Lahman ' s Ba s e b a l l Database

Page 13: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 13 / 36

List the packages your System Already Has ...

l a t t i c e E x t r a Ext ra G r a ph i c a l U t i l i t i e s Based on L a t t i c el a vaan Laten t V a r i a b l e A n a l y s i sl a v a a n . s u r v e y Complex s u r v e y S t r u c t u r a l Equat ion Model ing

(SEM)l a z y e v a l Lazy (Non−Standard ) Ev a l u a t i o nl e a p s r e g r e s s i o n s ub s e t s e l e c t i o nlme4 L i n e a r Mixed−Effects Models u s i n g ' Eigen ' and

S4Lmoments L−moments and q u a n t i l e m i x t u r e slm t e s t Te s t i ng L i n e a r Reg r e s s i o n Modelsl p S o l v e I n t e r f a c e to ' Lp s o l v e ' v . 5 . 5 to So l v e

L i n e a r / I n t e g e r Programsl smeans Least−Squares Meansmagic c r e a t e and i n v e s t i g a t e magic s qua r e smag r i t t r A Forward−Pipe Operato r f o r Rman ipu l a t e I n t e r a c t i v e P l o t s f o r RStudiomaps Draw Geog r aph i c a l Mapsmarkdown 'Markdown ' Render ing f o r RMatching Mu l t i v a r i a t e and P r op en s i t y Score Matching wi th

Ba lance Opt im i z a t i onMatchIt MatchIt : Nonparametr i c P r e p r o c e s s i n g f o r

Pa ramet r i c Casua l I n f e r e n c ema t r i x c a l c C o l l e c t i o n o f f u n c t i o n s f o r mat r i x c a l c u l a t i o n sMatr ixMode l s Mode l l i ng wi th Spar se And Dense Mat r i c e smaxLik Maximum L i k e l i h o o d Es t ima t i onMCMCglmm MCMC Gen e r a l i s e d L i n e a r Mixed Modelsmed i a t i on Causa l Med ia t ion An a l y s i s

Page 14: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 14 / 36

List the packages your System Already Has ...

memisc Too l s f o r Management o f Survey Data , Graph ic s ,Programming , S t a t i s t i c s , and S imu l a t i o n

memoise Memoise f u n c t i o n smhurdle Mu l t i p l e h u r d l e Tob i t modelsmi M i s s i ng Data Imputa t i on and Model Check ingmice Mu l t i v a r i a t e Imputa t i on by Chained Equat i on smicrobenchmark Accurate Timing Func t i on smime Map F i l enames to MIME Typesminqa De r i v a t i v e− f r e e o p t im i z a t i o n a l g o r i t hm s by

qu ad r a t i c app rox imat i onmisc3d M i s c e l l a n e o u s 3D P l o t smi scToo l s M i s c e l l a n e o u s Too l s and U t i l i t i e sm i t o o l s Too l s f o r mu l t i p l e impu ta t i on o f m i s s i n g datam log i t mu l t i n om i a l l o g i t modelMM The m u l t i p l i c a t i v e mu l t i n om i a l d i s t r i b u t i o nmnormt The Mu l t i v a r i a t e Normal and t D i s t r i b u t i o n smode l t oo l s Too l s and C l a s s e s f o r S t a t i s t i c a l ModelsMplusAutomation Automating Mplus Model E s t ima t i on and

I n t e r p r e t a t i o nmultcomp S imu l taneous I n f e r e n c e i n Gene ra l Pa ramet r i c

ModelsmultcompView V i s u a l i z a t i o n s o f Pa i r ed Compar i sonsmu l t i c o o l Pe rmuta t i ons o f Mu l t i s e t s i n Cool−Lex Ordermunse l l Munse l l c o l o u r systemMVB Mut i v a r i a t e B e r n o u l l i l o g− l i n e a r modelmvnormtest Norma l i t y t e s t f o r m u l t i v a r i a t e v a r i a b l e smvProbit Mu l t i v a r i a t e P r ob i t Models

Page 15: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 15 / 36

List the packages your System Already Has ...

mvtnorm Mu l t i v a r i a t e Normal and t D i s t r i b u t i o n snetwork C l a s s e s f o r R e l a t i o n a l Datan l o p t r R i n t e r f a c e to NLoptNMF Algo r i t hms and Framework f o r Nonnegat ive Matr i x

F a c t o r i z a t i o n (NMF)numDeriv Accurate Numer i ca l D e r i v a t i v e sOarray Ar r ay s w i th a r b i t r a r y o f f s e t sop enx l s x Read , Wri te and Ed i t XLSX F i l e soptmatch Func t i on s f o r op t ima l matchingo r d i n a l R e g r e s s i o n Models f o r O rd i n a l Dataorthopo lynom Co l l e c t i o n o f f u n c t i o n s f o r o r t hogona l and

o r thono rma l p o l y nom i a l sp a r t i t i o n s Add i t i v e p a r t i t i o n s o f i n t e g e r spa r t y A Labo ra to r y f o r R e c u r s i v e P a r t y t i o n i n gpawacc Ph y s i c a l a c t i v i t y w i th a c c e l e r ome t e r spbivnorm Vec t o r i z e d B i v a r i a t e Normal CDFpb k r t e s t Pa ramet r i c b oo t s t r a p and Kenward−Roger−based

methods f o r mixed model compar i sonpequod Moderated Reg r e s s i o n PackagePhyActBedRest Marks p e r i o d s o f s l e e p i n Ac t i g r aph

a c c e l e r ome t e r dataP h y s i c a l A c t i v i t y P roce s s Ph y s i c a l A c t i v i t y Acce l e r ome t e r Datapkgmaker Package deve lopment u t i l i t i e splm L i n e a r Models f o r Pane l Dataplotmo P lo t a Model ' s Response and R e s i d u a l sp l o t r i x Va r i ou s P l o t t i n g Func t i on sp l y r Too l s f o r S p l i t t i n g , App l y i ng and Combining

Page 16: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 16 / 36

List the packages your System Already Has ...

Datapng Read and w r i t e PNG imagesPoisNor S imu l taneous g e n e r a t i o n o f m u l t i v a r i a t e data

wi th Po i s son and normal ma r g i n a l sp o l s p l i n e Po l ynomia l S p l i n e Rou t i n e spolynom A c o l l e c t i o n o f f u n c t i o n s to implement a c l a s s

f o r u n i v a r i a t e po l ynom i a l man i pu l a t i o n sp o r t a b l e P a r a l l e l S e e d s Al low r e p l i c a t i o n o f s im u l a t i o n s on p a r a l l e l

and s e r i a l compute r s .p o r t a b l e P a r a l l e l S t r e am s

Al low r e p l i c a t i o n o f s im u l a t i o n s on p a r a l l e land s e r i a l compute r s .

p r o f i l eMod e l Too l s f o r p r o f i l i n g i n f e r e n c e f u n c t i o n s f o rv a r i o u s model c l a s s e s

p ro to Pro to type object−based programmingPSAboot Boo t s t r app i ng f o r P r op en s i t y Score An a l y s i sPSAgraphics P r op en s i t y Score An a l y s i s G raph i c sp s c l P o l i t i c a l S c i e n c e Computat iona l Labora to ry ,

S t an f o rd U n i v e r s i t yp s p l i n e Pena l i z e d Smoothing S p l i n e spsy Va r i ou s p r o c edu r e s used i n psychometrypsych Procedu re s f o r P s y c ho l o g i c a l , Psychometr i c , and

P e r s o n a l i t y Resea rchpwr Bas i c Func t i on s f o r Power An a l y s i sqdapRegex Regu l a r E xp r e s s i o n Removal , E x t r a c t i o n , and

Replacement Too l squadprog Func t i on s to s o l v e Quadra t i c Programming

Page 17: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 17 / 36

List the packages your System Already Has ...

Prob l ems .quantmod Quan t i t a t i v e F i n a n c i a l Mode l l i ng Frameworkquant reg Quan t i l e R eg r e s s i o nR2OpenBUGS Running OpenBUGS from RR6 C l a s s e s w i th Re f e r en c e Semant ic sRandomFie lds S imu l a t i o n and An a l y s i s o f Random F i e l d sRandomF i e l d sUt i l s U t i l i t i e s f o r the S imu l a t i o n and An a l y s i s o f

Random F i e l d srandomForest Breiman and Cu t l e r ' s random f o r e s t s f o r

c l a s s i f i c a t i o n and r e g r e s s i o nRcmdr R CommanderRcmdrMisc R Commander M i s c e l l a n e o u s Func t i on sRColorBrewer Co lo rBrewer P a l e t t e sRcpp Seamles s R and C++ I n t e g r a t i o nRcppArmad i l l o 'Rcpp ' I n t e g r a t i o n f o r the ' Armad i l l o '

Templated L i n e a r A lgeb ra L i b r a r yRcppEigen 'Rcpp ' I n t e g r a t i o n f o r the ' Eigen ' Templated

L i n e a r A lgeb ra L i b r a r yRCurl Gene ra l Network (HTTP/FTP/ . . . ) C l i e n t I n t e r f a c e

f o r RreadODS Read ODS f i l e s and put s them i n t o data f ramesr e a d x l Read Exce l F i l e sr e g i s t r y I n f r a s t r u c t u r e f o r R Package R e g i s t r i e sr e l a impo R e l a t i v e impor tance o f r e g r e s s o r s i n l i n e a r

modelsr e l imp R e l a t i v e Con t r i b u t i o n o f E f f e c t s i n a

Reg r e s s i o n Model

Page 18: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 18 / 36

List the packages your System Already Has ...

r e shape F l e x i b l y r e shape d a t a .r e shape2 F l e x i b l y Reshape Data : A Reboot o f the Reshape

Package .r g l 3D V i s u a l i z a t i o n Us ing OpenGLr i o A Swiss−Army Kn i f e f o r Data I /OrJava Low−Level R to Java I n t e r f a c eRJSONIO S e r i a l i z e R o b j e c t s to JSON, J a v aS c r i p t Object

Nota t i onr l e c u y e r R i n t e r f a c e to RNG with mu l t i p l e s t r eamsRmal scha in s Cont inuous Opt im i z a t i on u s i n g Memetic

A lgo r i t hms wi th Loca l Search Cha ins(MA−LS−Chains) i n R

rmarkdown Dynamic Documents f o r RR.methodsS3 S3 Methods S im p l i f i e dRmpfr R MPFR − Mu l t i p l e P r e c i s i o n F loat ing−Po int

R e l i a b l erms Reg r e s s i o n Model ing S t r a t e g i e sr n g t o o l s U t i l i t y f u n c t i o n s f o r work ing wi th Random

Number Gene r a t o r sr obu s t b a s e Bas i c Robust S t a t i s t i c sr o c k c h a l k Reg r e s s i o n E s t ima t i on and P r e s e n t a t i o nRODBC ODBC Database AccessR.oo R Object−Oriented Programming wi th or w i thout

Re f e r e n c e sroxygen2 In−Source Documentat ion f o r Rrqpd Reg r e s s i o n Quan t i l e s f o r Pane l DataRso lnp Gene ra l Non− l inear Op t im i z a t i on

Page 19: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 19 / 36

List the packages your System Already Has ...

RSQLite SQLite I n t e r f a c e f o r Rr s t r eam Streams o f Random Numbersr s t u d i o Too l s and U t i l i t i e s f o r RStudior s t u d i o a p i S a f e l y Access the RStudio APIruga r ch Un i v a r i a t e GARCH modelsRUnit R Uni t Test FrameworkR . u t i l s Va r i ou s Programming U t i l i t i e sr v S imulat ion−based random v a r i a b l e o b j e c t sr v e r s i o n s Query 'R ' Ver s i on s , I n c l u d i n g ' r− r e l e a s e ' and

' r−o l d r e l 'sandwich Robust Cova r i ance Matr i x E s t ima t o r ss c a l e s S ca l e Func t i on s f o r V i s u a l i z a t i o ns c a t t e r p l o t 3 d 3D Sc a t t e r P l o tSDMTools Sp e c i e s D i s t r i b u t i o n Mode l l i ng Too l s : Too l s f o r

p r o c e s s i n g data a s s o c i a t e d wi th s p e c i e sd i s t r i b u t i o n mode l l i n g e x e r c i s e s

SEEDMC SEarch f o r E f f i c i e n t Des igns u s i n g Monte Ca r l oS imu l a t i o n

sem S t r u c t u r a l Equat ion Modelss e r i a t i o n I n f r a s t r u c t u r e f o r S e r i a t i o ns f sm i s c U t i l i t i e s from Seminar f u e r S t a t i s t i k ETH

Zur i chs h i n y Web App l i c a t i o n Framework f o r RSkewHyperbo l i c The Skew Hype r bo l i c Student t−D i s t r i b u t i o ns lam Spar se L i gh twe i gh t A r r ay s and Mat r i c e ssna Too l s f o r S o c i a l Network An a l y s i ssnow Simple Network o f Work s ta t i on s

Page 20: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 20 / 36

List the packages your System Already Has ...

s n ow f a l l E a s i e r c l u s t e r computing ( based on snow ) .snowFT Fau l t To l e r an t S imple Network o f Work s ta t i on sSoDA Func t i on s and Examples f o r ”So f tware f o r Data

An a l y s i s ”sp C l a s s e s and Methods f o r S p a t i a l Dataspam SPArse Matr i xSparseM Spar se L i n e a r A lgeb raSpa t i a l E x t r eme s Mode l l i ng S p a t i a l Extremesspd Semi Pa ramet r i c D i s t r i b u t i o ns p l a n c s S p a t i a l and Space−Time Po in t Pa t t e rn An a l y s i ss t a b l e d i s t S t ab l e D i s t r i b u t i o n Func t i on sstatmod S t a t i s t i c a l Model ingstatnet .common Common R S c r i p t s and U t i l i t i e s Used by the

S t a t n e t P r o j e c t So f twares t r i n g i Cha ra c t e r S t r i n g P r o c e s s i n g F a c i l i t i e ss t r i n g r Simple , C on s i s t e n t Wrappers f o r Common S t r i n g

Ope ra t i on ss t r u c change Test ing , Mon i to r ing , and Dat ing S t r u c t u r a l

Changess u r v e y a n a l y s i s o f complex s u r v e y samplest a b l e s Formula−dr iven t a b l e g e n e r a t i o nt c l t k 2 Tcl /Tk Add i t i o n sTeachingDemos Demons t ra t i ons f o r t e a c h i n g and l e a r n i n gtenso rA Advanced t e n s o r s a r i t hm e t i c w i th named i n d i c e st e s t t h a t Un i t Te s t i ng f o r Rt e x r e g Conve r s i on o f R Reg r e s s i o n Output to LaTeX or

HTML Tab le s

Page 21: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 21 / 36

List the packages your System Already Has ...

TH.data TH ' s Data Ar ch i v et imeDate Rmet r i c s − Ch r o n o l o g i c a l and Ca l enda r Ob j e c t st im e S e r i e s Rmet r i c s − F i n a n c i a l Time S e r i e s Ob j e c t streemap Treemap V i s u a l i z a t i o nTriMatch P r op en s i t y Score Matching o f Non−Binary

Treatmentstruncnorm Truncated normal d i s t r i b u t i o nt r u n c r e g Truncated Gaus s i an Reg r e s s i o n Modelst r u s t Trus t Region Opt im i z a t i ont s e r i e s Time S e r i e s A n a l y s i s and Computat iona l F inanceTSP T r a v e l i n g S a l e s p e r s o n Problem (TSP)TTR Techn i c a l Trad ing Ru l e sucminf Genera l−purpose un con s t r a i n e d non− l i nea r

o p t im i z a t i o nUsingR Data Sets , e t c . f o r the Text ”Us ing R f o r

I n t r o d u c t o r y S t a t i s t i c s ” , Second Ed i t i o nvcd V i s u a l i z i n g C a t e g o r i c a l DataVGAM Vector G e n e r a l i z e d L i n e a r and Add i t i v e ModelsVGAMdata Data Suppo r t i ng the 'VGAM' PackageVIM V i s u a l i z a t i o n and Imputa t i on o f M i s s i ng Va luesWhatI f WhatI f : So f tware f o r E v a l u a t i n g Coun t e r f a c t u a l swh i s k e r {{mustache }} f o r R , l o g i c l e s s t emp l a t i n gx l s x Read , w r i t e , fo rmat Exce l 2007 and Exce l

97/2000/XP/2003 f i l e sx l s x j a r s Package r e q u i r e d POI j a r s f o r the x l s x packageXML Tools f o r Pa r s i ng and Gene r a t i ng XML With in R

and S−Plus

Page 22: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 22 / 36

List the packages your System Already Has ...

xml2 Parse XMLx t a b l e Export t a b l e s to LaTeX or HTMLx t s eX t e n s i b l e Time S e r i e syaml Methods to conv e r t R data to YAML and backZ e l i g Everyone ' s S t a t i s t i c a l So f twarezoo S3 I n f r a s t r u c t u r e f o r Regu l a r and I r r e g u l a r

Time S e r i e s (Z ' s Ordered Obs e r v a t i o n s )

Packages i n l i b r a r y '/ u s r / l i b /R/ l i b r a r y ' :

base The R Base Packageboot Boot s t r ap Func t i on s ( O r i g i n a l l y by Angelo Canty

f o r S)c l a s s Func t i on s f o r C l a s s i f i c a t i o nc l u s t e r ”F i nd i ng Groups i n Data ” : C l u s t e r A n a l y s i s

Extended Rousseeuw e t a l .c o d e t o o l s Code An a l y s i s Too l s f o r Rcomp i l e r The R Compi l e r Packaged a t a s e t s The R Data s e t s Packagef o r e i g n Read Data Sto red by Minitab , S , SAS , SPSS ,

Stata , Sys ta t , Weka , dBase , . . .g r a p h i c s The R Graph i c s Packageg rDev i c e s The R Graph i c s Dev i c e s and Support f o r Co l ou r s

and Fontsg r i d The Gr id G raph i c s PackageKernSmooth Func t i on s f o r Ke rne l Smoothing Suppo r t i ng Wand

& Jones (1995)

Page 23: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 23 / 36

List the packages your System Already Has ...

l a t t i c e T r e l l i s G raph i c s f o r RMASS Support Func t i on s and Data s e t s f o r Venab l e s and

R i p l e y ' s MASSMatr i x Spa r se and Dense Matr i x C l a s s e s and Methodsmethods Formal Methods and C l a s s e smgcv Mixed GAM Computation Veh i c l e w i th GCV/AIC/REML

Smoothness E s t ima t i onnlme L i n e a r and Non l i n e a r Mixed E f f e c t s Modelsnnet Feed−Forward Neura l Networks and Mu l t i nom ia l

Log−Linear Modelsp a r a l l e l Support f o r P a r a l l e l computat ion i n Rr p a r t R e c u r s i v e P a r t i t i o n i n g and Reg r e s s i o n Treess p a t i a l Func t i on s f o r K r i g i n g and Po in t Pa t t e rn

An a l y s i ss p l i n e s Reg r e s s i o n S p l i n e Func t i on s and C l a s s e ss t a t s The R S t a t s Packages t a t s 4 S t a t i s t i c a l Func t i on s u s i n g S4 C l a s s e ss u r v i v a l S u r v i v a l A n a l y s i st c l t k Tcl /Tk I n t e r f a c et o o l s Too l s f o r Package Developmentu t i l s The R U t i l s Package

Warning message :I n l i b r a r y ( ) :

l i b r a r i e s '/ u s r / l o c a l / l i b /R/ s i t e− l i b r a r y ' , '/ u s r / l i b /R/ s i t e− l i b r a r y ' c on t a i nno packages

>

Page 24: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 24 / 36

List the packages your System Already Has ...

Page 25: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 25 / 36

To load a package, run library() with a package name

Make all of the functions, data sets, and vignettes in the“lme4” package available to my current session

> l i b r a r y ( lme4 )

Page 26: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 26 / 36

How to install new packages

Browse a CRAN server’s list of packages .Number of packagesin CRAN is growing exponentially, now exceeds 6,500.

Sometimes difficult to know which packages are worthwhile.Buyer Beware!

Inside R, check for the giant list of packages on CRAN

> g i a n t L i s t <− a v a i l a b l e . p a c k a g e s ( )> row.names ( g i a n t L i s t )

Run install.packages(). I suggest the argument “dependencies= TRUE”, which can abbreviate as:

> i n s t a l l . p a c k a g e s ( ”ca r ” , dep = TRUE)

Page 27: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 27 / 36

How to install new packages ...

That will pop up a menu-chooser for web servers. If yoursystem hangs, it means it is failing to talk to your graphicalinterface. Avoid that by running

> i n s t a l l . p a c k a g e s ( ”ca r ” , dep = TRUE, r epo s = ”ht tp : //rweb . c rmda .ku . edu / c ran ”)

If you want more than one package, concatenate

> i n s t a l l . p a c k a g e s ( c ( ”lme4 ” , ”ca r ”) , dep = TRUE, r epo s = ”ht tp : // rweb . c rmda .ku . edu / c ran ”)

All good KU students install the package “rockchalk” and lookat its beautiful vignettes.

Page 28: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 28 / 36

:: and :::

All non-private functions in all loaded packages can beaccessed by name. There is, however, sometimes confusionthat several packages offer functions of same name. Thedisambiguator is “::”

Use the function with syntax package::function().

Since R-2.15, every function has to have a package namespace.So if you are afraid you are not getting the real plot function,let R know:

g r a p h i c s : : p l o t ( whatever , whateve r )

I don’t generally write out the full package::function name.But I’m trying to remember to do it more often because the RCore Team is recommending that more and more often (manymore examples in help written that way).

Page 29: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 29 / 36

:: and ::: ...

Ever need 3 colons? Some functions are “private”, but notexactly hidden. You can’t access them by name. But you canget them by syntax package:::function().

Page 30: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 30 / 36

Staying up to date

Please remember that the package world is always changing.

Keep up to date,

> upda t e . package s ( ask = FALSE , c h e c kBu i l t = TRUE)

Avoid the repo-chooser with

> upda t e . package s ( ask = FALSE , c h e c kBu i l t = TRUE, r epo s= ”ht tp : // rweb . c rmda .ku . edu / c ran ”)

Page 31: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 31 / 36

Other repositories exist as well

After CRAN, Bioconductor is the most notable packagerepository

At KU, we host a development server for not-yet-on-CRANpackages. http://rweb.crmda.ku.edu/kran

Page 32: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 32 / 36

System administration questions

When you run this

> i n s t a l l . p a c k a g e s ( c ( ”lme4 ”) , dep = TRUE)

The result will depend on your operating system and your useraccount.

If you are logged in as an administrator, or if you ran R asadministrator, then the packages will be installed into thesystem-wide R folder structure.

If you are logged in as a limited user, then R will not havepermission to update the whole system, it will ask if you wantto install in your own user account.

You can ask R where it looks for packages during a session.Run

Page 33: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 33 / 36

System administration questions ...

> . l i b P a t h s ( )

(the period at the beginning is required).

On my Linux system, I see:

> . l i b P a t h s ( )

[ 1 ] ”/home/ pau l j ohn /R/x86 64−pc− l inux−gnu− l ibrary /3 . 1 ” ”/ u s r / l o c a l / l i b /R/s i t e− l i b r a r y ” ”/ u s r / l i b /R/ s i t e− l i b r a r y ”

[ 4 ] ”/ u s r / l i b /R/ l i b r a r y ”

Page 34: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 34 / 36

Interact with packages

Packages installed are linked to the help.start() page

Same: list all packages that are installed now in R:

> l i b r a r y ( )

Read about a package, get a list of all functions & features

> he l p ( package = ”s t a t s ”)

Synonym: The “old way” I used to teach still works, butmaybe not for long

> l i b r a r y ( h e l p = ”s t a t s ”)

Page 35: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 35 / 36

Don’t forget about help

Make a package’s functions immediately accessible.

> l i b r a r y ( lme4 )

Run> help(package = ”lme4”)

See helps

> ? lmer> ? g lmer

Page 36: First R-03: R packages - University of Kansascrmda.dept.ku.edu/resources/presentations/StatsCamp2015/R/first-R-03.pdfDescriptive 1/36 First R-03: R packages Paul E. Johnson1 2 1Department

Descriptive 36 / 36

Package Namespaces: Using non-attached packages

Without running library(), functions are still accessible with anamespace prefix

> lme4 : : g lmer ( )

That’s generally irrelevant to elementary R usage, but isbecoming more noticeable in examples and help pages.

The “namespace” idea is increasingly popular in computerprogramming, part of an widespread emphasis on“disambiguation”