Skip to main content
Statistics LibreTexts

A.10: R packages

  • Page ID
    45304
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    This page describes basic steps for package installation from a CRAN mirror site and how to update installed packages following installation of a new version of R. See at the end of this page for a list of packages described in Mike’s Biostatistics Book.

    Adding packages to base R installation

    Installing R packages is straightforward, assuming the package is part of CRAN. Select a CRAN mirror site, e.g., 0-Cloud, RStudio’s mirror site.

    chooseCRANmirror()

    To find out what CRAN mirror was set for the current session use

    findCRANmirror()

    A list of mirror sites is stored on your computer once R is installed, see CRAN_mirrors.csv in the doc folder, e.g., ~/R-4.3.1/doc.

    Once the CRAN mirror is selected, and assuming you have the name of the package, e.g., package.name, then

    install.packages("package.name")

    will work.

    Useful additional command options include

    install.packages("package.name", dependencies=TRUE)

    which will also download and install any additional packages required, and

    install.packages("package.name", quiet=TRUE)

    cuts down on the amount of screen output during installation.

    If you receive the following warning message,

    Warning: package 'package.name' is not available (for R version 4.3.2)

    it may be possible that the package has not yet become available, but first double-check for typos.

    Another warning message may be that a binary version is available, but a more recent source version is available, prompted by the question, Do you want to install from sources the package which needs compilation? In most cases, the answer is no. R will install a previous binary version. In order to install from source, RTools must be installed.

    Update R packages after installing new R version

    After updating to new version of R you’ll need to download and update the user installed packages again. If you are running RStudio, see instructions here. For Win11 users you can download and run a package called installr, for macOS users download and install updateR, which will assist you to update R packages.

    I prefer to run a script, modified from R-Bloggers.com. This script works on any operating system, but updates only CRAN packages (e.g., not github or Bioconductor).

    Before installing the new version of base R, start up your current R installation and set your working directory, setwd(). Enter the following script to gather and save all installed R packages. Select CRAN mirror when prompted.

    tmp <- installed.packages()
    installedpkgs <- as.vector(tmp[is.na(tmp[,"Priority"]), 1])
    save(installedpkgs, file="installed_old.rda")

    Shutdown R, then install and start the new version of R (see Install R for help).

    In the new version of R, set your working directory as above. Enter the following script

    load(file="installed_old.rda")
    tmp <- installed.packages()
    installedpkgs.new <- as.vector(tmp[is.na(tmp[,"Priority"]), 1])
    missing <- setdiff(installedpkgs, installedpkgs.new)
    install.packages(missing)
    update.packages(ask=FALSE)

    Should be good to go. You can remove old R version installation.

    Note:

    To check installed packages, just view the object installedpkgs created earlier.

    R packages used in Mike’s Biostatistics Book

    list updated 12 August 2024

    package chapter
    agRee 16.5 – Instrument reliability and validity
    ape 20.11 - Plot a Newick tree
    baseline 20.3 - Baseline correction
    BiocManager 20.11 - Plot a Newick tree
    Bioconductor 20.11 - Plot a Newick tree
    BiodiversityR 5.6 - Sampling from Populations
    boot 19.2 - Bootstrap sampling
    bootstrap 19.1 - Jackknife sampling
    BSDA 11.4 - Two-sample effect size
    cairoDevice 13.3 - Test assumption of normality
    car 4.3 - Box plots
    carData 4.1 - Bar (column) charts
    cholera 2.3 - A brief history of (bio)statistics
    clipr 4 - How to report statistics
    combinat 6.3 - Combinations and permutations
    confintr 19.2 - Bootstrap sampling
    contingencytables 9.6 - McNemar’s test
    correlation 16.6 - Similarity and Distance
    cranlogs 2.2 - Why do we use R Software?
    datasets 4.5 - Scatter plots
    digitize 12.3 - Fixed effects, random effects, and ICC
    drc 20.10 - Growth equations and dose response calculations
    effectsize 12.5 – Effect size for ANOVA
    effsize 11.4 - Two-sample effect size
    epiR 5.4 - Clinical trials
    epitools 7.4 – Epidemiology: Relative risk and absolute risk, explained
    exact2x2 9.6 – McNemar’s test
    factoextra 20.6 – Dimensional analysis
    findpeaks 20.2 - Peak detection
    forecast 20.5 - Time series
    geepack 20.1 - Area under the curve
    geeM 20.1 - Area under the curve
    geodist 16.6 - Similarity and Distance
    ggplot2 4.1 - Bar (column) charts
    ggtree 20.11 - Plot a Newick tree
    gplots 4.1 - Bar (column) charts
    gtools 6.3 - Combinations and permutations
    GrapheR 4.10 - Graph software
    HH 12.4 - ANOVA from "sufficient statistics"
    HistData 3.2 - Measures of Central Tendency
    lattice 4.10 - Graph software
    lmboot 19.1 - Jackknife sampling
    irr 12.3 - Fixed effects, random effects, and ICC
    MASS 12.4 - ANOVA from "sufficient statistics"
    Matrix 20.1 - Area under the curve
    mcp 12.6 - ANOVA post-hoc tests
    MESS 20.1 - Area under the curve
    mlr3misc 8.2 – The controversy over proper hypothesis testing
    modeest 3.2 - Measures of Central Tendency
    multcomp 12.6 - ANOVA posthoc tests
    NCStats 3.3 - Measures of dispersion
    nlopt 20.10 - Growth equations and dose response calculations
    nortest 13.3 – Test assumption of normality
    PairedData 10.3 – Paired t-test
    peakDetection 20.2 - Peak detection
    Phylotools 20.11 - Plot a Newick tree
    Phytools 20.11 - Plot a Newick tree
    plotly 4.10 - Graph software
    plyr 4.1 - Bar (column) charts
    polychor 16.4 – Spearman and other correlations
    propCIs 7.6 - Confidence intervals
    psa 20.6 – Dimensional analysis
    psy 12.3 - Fixed effects, random effects, and ICC
    psych 3.2 - Measures of Central Tendency
    pwr 11.5 - Power analysis in R
    random 6.6 - Continuous distributions
    rattle 13.3 - Test assumption of normality
    Rcmdr 1.1 - A quick look at R and R Commander
    RcmdrMisc 1.1 - A quick look at R and R Commander
    RcmdrPlugin.EBM 4.4 - Mosaic plots
    RcmdrPlugin.EZR 11.5 - Power analysis in R
    RcmdrPlugin.HH 12.4 - ANOVA from "sufficient statistics"
    RcmdrPlugin.KMggplot2 4.1 - Bar (column) charts
    RcmdrPlugin.mosaic 4.4 - Mosaic plots
    RcmdrPlugin.survival 20.9 - Survival analysis
    Rcolorbrewer 4.4 - Mosaic plots
    reshape2 4.6 - Adding a second Y axis
    rgl 18.1 - Multiple Linear Regression
    Rmisc 3.5 - Statistics of error
    ROCR 20.1 - Area under the curve
    rptR 12.3 - Fixed effects, random effects, and ICC
    RGtk2 13.3 - Test assumption of normality
    season 20.5 – Time series
    shotGroups 3.5 - Statistics of error
    stats 4 – How to report statistics
    survival 3.1 - Data types
    tanggle 20.11 - Plot a Newick tree
    Ternary 4.8 - Ternary plots
    testequavar 13.4 - Tests for Equal Variances
    tidyverse 4.3 - Box plot
    tigerstats 8.4 - Tails of a test
    timeseries 20.5 - Time series
    TOSTER 16.1 - Product-moment correlation
    vegan 20.8 - Diversity indexes
    WRS2 3.3 - Measures of dispersion

    This page titled A.10: R packages is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Michael R Dohm via source content that was edited to the style and standards of the LibreTexts platform.

    • Was this article helpful?