# The install error for rethinking names its own cause

> The rethinking package is the code that accompanies McElreath's second edition, built around one idea: the model is written as a list of explicit distributional assumptions rather than a formula. It is never going to be on CRAN, a slim branch exists so you can stop before Stan, and the newest release is from 2021.

**rmcelreath/rethinking** — Statistical Rethinking course and book package

- Repository: https://github.com/rmcelreath/rethinking
- Stars: 2,428 · Forks: 629
- Language: R
- License: not declared
- Published: 2026-09-28 · Updated: 2026-09-28 · Language: en
- Canonical page: https://hysenlabs.com/projects/rmcelreath-rethinking

## The install error message explains itself

The installation section ends with the most useful error diagnosis in the file.

The package is not on CRAN, and the README states plainly that it never is going to be. So if you get an error saying rethinking is not available for your version of R, the diagnosis is already in the documentation: you tried to install it from CRAN. There is no compatibility problem and no version mismatch, only the wrong repository.

The install itself is three steps, in order. First the C++ toolchain, with a platform specific guide linked from the cmdstan installation page. Second, `cmdstanr`, and on the first install you also have to compile its libraries with `cmdstanr::install_cmdstan()`. Third, the package itself, from within R:

```
install.packages(c("coda","mvtnorm","devtools","loo","dagitty","shape"))
devtools::install_github("rmcelreath/rethinking")
```

The prose around that last step is unusually honest about cost: all of this bother is worth it, and you just have to do it once. The dependency list is six packages, and `devtools` is doing the work of installing from GitHub.

There is one escape hatch, and it is the next section.

## A slim branch lets you stop before Stan

If the first half of the course is what you need, there is a branch that skips the MCMC machinery entirely.

```
install.packages(c("coda","mvtnorm","devtools","loo","dagitty"))
devtools::install_github("rmcelreath/rethinking@slim")
```

The only difference in the dependency list is that `shape` is gone, five packages instead of six. Everything else is identical, because the slimmer package is a branch of the same repository rather than a separate project.

What survives is the point of the exercise. The `quap` function and its helpers still work, which is quadratic approximation, no sampler involved. The README frames it as being able to work through chapter eight before you need to install the full version with Stan.

That boundary is the design. The book front loads the way of writing a model down explicitly, and it takes several chapters before the reader needs a sampler at all, so the tool chain is split along the same line as the reading. The full version later is the same repository with the Stan compiler behind it.

## map was renamed because the name described the wrong thing

In the first edition of the textbook the quadratic approximation function was called `map`. It still answers to that name, as an alias, and the README explains the rename.

The reason is that `map` was misleading. The function does not produce maximum a posteriori estimates; it produces quadratic approximations of the posterior distribution. Those are different claims, and a name that promised the narrower one would mislead anyone who then interpreted the output as a point estimate.

The call itself takes the model list, a data list and starting values:

```
fit <- quap(
    f ,
    data=list(y=c(-1,1)) ,
    start=list(mu=0,sigma=1)
)
```

The summary is either `summary(fit)` or `precis(fit)`, and both print the same five column layout, a mean, a standard deviation and the two bounds that hold 89 percent of the posterior mass, labelled 5.5 percent and 94.5 percent. Vectorized parameters are supported, which the README notes is convenient for categorical data, and the examples are in `?quap`.

Almost any ordinary generalized linear model can be written this way, which is the boundary of the method: anything more structured needs the sampler.

## ulam and map2stan are the same for simple models

The same formula list can be compiled into a Stan model with one of two functions, and for simple models they behave identically.

`map2stan` is the original, carried over from the first edition of both package and book. `ulam` is the newer one, and it allows more: explicit variable types and custom distributions among them. The stated plan is that new features go into `ulam`, which settles the choice for anything new.

Both take the same input as `quap`, so a model moves between the three tools without being rewritten:

```
fit_stan <- ulam( f , data=list(y=c(-1,1)) )
```

One sentence in this section is about ergonomics rather than statistics. `ulam` is named after Stanislaw Ulam, one of the parents of the Monte Carlo method and the namesake of the Stan project, and the README insists on the pronunciation: something like OO-lahm, not YOU-lamm.

The result object is documented in three parts. Diagnostics come back through `precis(fit_stan)`, which adds `n_eff` and `Rhat` columns to the summary table, and for `ulam` models `plot` shows the same information while `traceplot` shows the chains. Samples come out through `extract.samples` as a list, and `extract.prior` does the same from the prior instead of the posterior.

## cmdstanr is the standard, yet the README still checks for rstan

The release titles carry the maintenance history in a way most packages do not.

The newest is v2.2.1, titled cmdstanr now standard, published on 2021-12-29. Before it, 2.12 in August 2020 was titled incremental cmdstanr support and 2.13 in the same month was titled minor maintenance. So the direction of travel was a move from RStan to cmdstanr, completed in the 2021 release.

The installation text reflects that move. The dependency you install and compile is cmdstanr, and the two toolchain links point at mc-stan.org.

But the section on `ulam` says the chain runs automatically, provided `rstan` is installed. That is the older interface surviving in the prose after the release that made cmdstanr the standard. Nothing breaks over it, since either backend can run a model, but it is the kind of sentence that sends a reader to install a package they no longer need.

The tag naming is inconsistent too. The newest tag carries a v prefix and the two before it do not, which means a script that sorts tags lexically will misorder these three.

## Distribution names are the one thing that changes between quap and ulam

The model list is portable across the tools with one exception: the distribution names inside it.

`quap` uses R distribution names, so `dnorm` and `dexp`. `ulam` does not care about R distribution names, and you can write the Stan names instead, `normal` and `exponential`, in the same list:

```
fit_stan <- ulam(
    alist(
        y ~ normal( mu , sigma ),
        mu ~ normal( 0 , 10 ),
        sigma ~ exponential( 1 )
    ), data=list(y=c(-1,1)) )
```

That is the whole adaptation, and it is why the list form matters. The three lines stay in the same order and the same meaning: the first is the likelihood, the second the prior for mu, the third the prior for sigma.

What the sampler produces is inspectable rather than opaque. The Stan source is available through `stancode(fit_stan)`, and the output is a data block declaring a two element vector, a parameters block with a lower bound of zero on sigma, and a model block that restates the three distributions in Stan syntax. The fitted object itself is in the `@stanfit` slot, so anything you would do with a Stan model can be done with that slot directly rather than through the package's own wrappers.

## link and sim do the work, and postcheck is a thin wrapper

Posterior prediction is three functions, and the README is candid about which one does the work.

`link` computes values of any linear model over samples from the posterior distribution. `sim` simulates posterior predictive distributions by simulating outcomes over those same parameter samples, and it doubles as the prior predictive simulator. The help pages are `?link` and `?sim`.

`postcheck` then computes posterior predictive checks automatically, and the README says in one clause that it merely uses `link` and `sim`. That is a useful thing to know when you want to understand what a check is doing rather than accept it as a plot.

There is also a parenthetical in that sentence, the word retrodictive with a question mark after it, which is the author thinking aloud about terminology rather than a claim. It is the only place in the file where the prose admits uncertainty, and it sits in the middle of an otherwise flat description of the API.

All three functions work on objects from `quap`, `ulam` and `map2stan` alike, so a model fitted by quadratic approximation can still be checked against simulated outcomes.

## quap stays flat while ulam goes multilevel

The boundary between the two tools is where the models get structured.

`quap` is limited to fixed effects models for the most part. `ulam` can specify multilevel models, including varying intercepts and varying slopes. The worked example prepares the UCBadmit data, converts a gender column to an integer, assigns a department index, drops the original column, and then fits a model with a department varying intercept, a global intercept mean and scale, and a single male coefficient, with the outcome as a binomial over applications.

Notice which distribution name appears in it. `half_normal` is not an R function; it is the Stan spelling, used here because the model is fitted with `ulam`. The same rule from the previous section, applied inside a multilevel formula.

The README stops in the middle of the next one, at a sentence beginning with the words The analogous varying slopes model, and does not finish the thought.

The repository root has the artefacts of a book package rather than a library. `ERRATA.md` collects corrections, `book_code_boxes.txt` and `book_code_boxes_ed1.txt` hold code taken from the book's boxes for both editions, `data/` holds the datasets the examples call, `man/` and `inst/` are the usual package directories, `tests/` is where checks would live, and `hex_stickers/` holds promotional images. There is no LICENSE file, and no licence is recorded for the repository.

## Conclusion

Install it from GitHub and expect to do the C++ toolchain work once, or take the slim branch and stay on quap through chapter eight. Two decisions are worth making before you start. First, which of the two tools you will write models in, because map2stan is the first edition path and new features are going into ulam, so a new course should use ulam. Second, whether you accept an R package with no licence recorded: the metadata names none and no LICENSE file sits at the root, which is unusual for a package this widely used, so check the terms yourself before redistributing it. Version tracking is not a concern to worry about here, because the last push was on 2026-06-10 and there has been no release since v2.2.1 in December 2021.

## FAQ

### how to install rethinking package

Three steps: install the C++ toolchain, install cmdstanr and compile its libraries once with cmdstanr::install_cmdstan(), then install coda, mvtnorm, devtools, loo, dagitty and shape and run devtools::install_github("rmcelreath/rethinking"). The package is not on CRAN and never will be, so an error saying it is not available for your version of R means you tried to install it from CRAN.

### Do I need Stan to work through the rethinking course?

No. A slim branch exists and is installed with devtools::install_github("rmcelreath/rethinking@slim"), with shape dropped from the dependency list. The quap function and its helpers still work, which covers the first half of the course up to chapter eight before the full version with Stan is needed.

### What is the difference between map and quap in rethinking?

They are the same function under two names. map was the first edition name and still works as an alias, and it was renamed because it produces quadratic approximations of the posterior distribution rather than only maximum a posteriori estimates, so the old name promised less than the function delivered.

### Should I use ulam or map2stan in rethinking?

For simple models they behave identically. ulam is the newer tool and allows more flexibility, including explicit variable types and custom distributions, while map2stan comes from the first edition, and new features are being added to ulam. It is named after Stanislaw Ulam and is pronounced like OO-lahm.

### Do I need R distribution names for ulam models?

No. ulam does not care about R distribution names, so normal and exponential can be written in the Stan style inside the same alist. Diagnostics come back through precis(fit_stan) with n_eff and Rhat columns added, and the Stan source is available from stancode(fit_stan).

## Sources

- [Issues](https://github.com/rmcelreath/rethinking/issues)
- [README](https://github.com/rmcelreath/rethinking/blob/master/README.md)
- [Releases](https://github.com/rmcelreath/rethinking/releases)
- [rmcelreath/rethinking on GitHub](https://github.com/rmcelreath/rethinking)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/rmcelreath-rethinking
