rnorm(10) # draw 10 random values from a Standard Normal distribution [1] -2.9017454 1.6591803 -0.3806936 0.2842570 -2.1319494 -1.1003835
[7] 1.5540280 -1.5755473 -0.5630551 0.4359361
Mainstream in academia for data science, increasingly used in business. Job market advantage!
Free & open-source: wherever you go, R will be with you at no costs (unlike MPLUS, MATLAB, SPSS, etc.)
Real programming language: difficult at the beginning, but: 1) gives you lots of flexibility; 2) has transfer on other programming languages (e.g., Python).
Vast community support thanks to a large and active community (also, chatGPT, Lucrez-IA, etc., know it pretty well!).
Huge ecosystem, >20,000 packages on CRAN, more from other sources (e.g., GitHub), to do amazing stuff with statistical data analysis, machine learning, data visualization, developing webapps [shiny], writing reports and even entire books [bookdown, rmarkdown]), can integrate with quarto, github.
Facilitates reproducible research by sharing code and workflows.
Executing fundamental operations and using basic functions;
Working with essential data types and structures;
Gaining some proficiency in managing and manipulating data with vectors and dataframes;
Understanding some fundamental concepts of programming.
Core statistical inference methods;
(Generalized) linear (mixed-effects) modeling;
Data visualization using ggplot2;
Power analysis via data simulation ;
Structural Equation Modeling (SEM);
Conducting Meta-Analysis.
see Shiny gallery
here’s a couple of recent real examples from Psicostat members:
this game-like shiny app developed for the science4all event in Padova; see here some explanation in Italian
practical ad-hoc shiny app for scoring experimental data collected by students
examples of other resources that can be created within the R ecosystem, integrating other tools such as GitHub and Quarto:
this very course support material is a website in its own right
this very course textbook is a book/website
this book by Daniël Lakens explaining Statistical Inference
first of all, for getting started, follow the instructions in Chapter 1 of Introduction2R to ensure that both
are installed
| Package | Used for what | Example(s) of functions |
|---|---|---|
base (base R) |
Basic functions | sum, mean, sqrt, abs, c, data.frame, summary, scale, plot, +, - |
stats (base R) |
Basic statistical calculations and functions | sd, cor, cor.test, t.test, lm, glm, AIC, rnorm, rbinom |
graphics (base R) |
Basic statistical calculations and functions | plot, boxplot, hist, barplot |
(You may actually use these “base” packages very often without even realizing that they are packages)
| Package | Used for what | Example(s) of functions |
|---|---|---|
effectsize |
Compute different effect sizes | cohens_d, hedges_g, cohens_f, d_to_r |
lme4 |
Fitting (generalized) (non-)linear mixed-effects models | lmer, glmer, ranef |
performance |
Useful tools for models | check_collinearity, r2_nagelkerke, icc |
effects |
Display effects for various statistical models | allEffects |
emmeans |
Estimate marginal means for various models | emmeans |
| Package | Used for what | Example(s) of functions |
|---|---|---|
ggplot2 |
Create beautiful plots using The Grammar of Graphics | ggplot, geom_point, geom_line, … |
lavaan |
Structural Equation Models (SEM) | sem, cfa |
semTools |
Useful tools for SEMs | compRelSEM, measEq.syntax |
metafor |
Perform meta-analysis | rma, rma.mv, forest, funnel, regtest |
brms |
Fitting practically any Bayesian model via MCMC with STAN | brm, set_prior |
blavaan |
Fitting Bayesian SEMs | bcfa, bsem |
Let’s run a few commands in RStudio to familiarize with its console and see if the installation works properly
[1] -2.9017454 1.6591803 -0.3806936 0.2842570 -2.1319494 -1.1003835
[7] 1.5540280 -1.5755473 -0.5630551 0.4359361
[1] 78 101 87 86 114 87 91 83 116 111