Skip to main content
v2026.11,986 entries · CC-BY 4.0

car Package in R: Install, Key Functions and Defaults

Install the car package in R, then use its Anova, vif, Levene and diagnostic functions, with the documented defaults that affect results.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

The car package in R (the package name is car, short for “Companion to Applied Regression”) is a free add-on for regression analysis. It supplies Type II and Type III analysis-of-variance tables through Anova(), variance-inflation factors through vif(), and a set of diagnostic tests and plots for linear models: leveneTest(), qqPlot(), outlierTest(), ncvTest() and durbinWatsonTest(). Install it with install.packages("car") and load it with library(car). The “package car in r” wording searchers sometimes use refers to the same package.

This guide is organised by task. Its distinguishing feature is the defaults: several car functions behave differently from what many users assume, and the data table below the article lists the signature and default of each function, taken from the package’s reference manual. Version details here are from the CRAN package page and manual read on 2026-11-12.

What the car package is used for in research

The CRAN page describes car as “Companion to Applied Regression”, maintained by Brad Price, at version 3.1-5 (published 2026-02-03) and licensed GPL-2 or GPL-3. The reference manual names two books as the intellectual home of the package: Fox and Weisberg (2019), An R Companion to Applied Regression, third edition (Sage), and Fox (2016), Applied Regression Analysis and Generalized Linear Models, third edition (Sage).

In practice researchers reach for car at four points in a regression workflow:

  • Testing terms in a fitted model. Anova() produces Type II or Type III tables for models fitted with lm, glm, multinom, polr, coxph, coxme, svyglm, svycoxph, rlm, lmer and lme, among others. linearHypothesis() (alias lht) tests general linear hypotheses.
  • Checking collinearity. vif() returns variance-inflation factors; see VIF in R for interpretation.
  • Diagnosing assumptions and outliers. leveneTest(), ncvTest(), durbinWatsonTest(), qqPlot(), outlierTest() and avPlots() (added-variable plots).
  • Preparing variables. recode() / Recode(), the power transformations bcPower(), yjPower() and basicPower(), and contrast helpers such as contr.Sum(), contr.Treatment() and contr.Helmert().

The manual also documents bootstrap and summary helpers (Boot(), S(), Confint(), Predict()), plotting functions (Boxplot(), scatterplot(), dataEllipse(), confidenceEllipse()) and Import() / Export(), which work through the rio package.

How to install or access it

car is distributed on CRAN, the Comprehensive R Archive Network, at cran.r-project.org/web/packages/car. The canonical short link is https://CRAN.R-project.org/package=car. From an R session:

install.packages("car")library(car)

The CRAN page lists R (>= 3.5.0) and carData (>= 3.0-0) under Depends, so carData, which holds the example datasets used in the car documentation, is installed alongside it. The Imports field lists abind, Formula, MASS, mgcv, nnet, pbkrtest, quantreg, lme4, nlme and scales, plus the base packages grDevices, utils, stats and graphics. A fresh install therefore downloads several dependencies; this is normal. For citation, the CRAN page links a citation page; in R, citation("car") prints the recommended reference. The package also ships a vignette, “Using car functions inside user functions”, relevant if you wrap car calls in your own functions. For the datasets that ship in R packages generally, see datasets in R packages.

Step-by-step: a basic diagnostic workflow with car

The reference manual uses the Duncan dataset (from carData) in its qqPlot() example, and the steps below follow that pattern. They show commands only; run them in your own session and read your own output.

  1. Load the package. library(car) also attaches carData, which makes Duncan available.
  2. Fit a linear model. mod <- lm(prestige ~ income + education + type, data = Duncan). This is the model used in the manual’s qqPlot() example.
  3. Test the terms. Anova(mod). The default is type = "II"; request Type III with Anova(mod, type = "III").
  4. Check collinearity. vif(mod).
  5. Inspect residuals. qqPlot(mod), optionally with a confidence level for the envelope as in the manual’s example, qqPlot(mod, envelope = .99).
  6. Look for outliers. outlierTest(mod).
  7. Test constant variance. ncvTest(mod).
  8. Test for autocorrelation when observations have a natural order: durbinWatsonTest(mod).

Anova(): Type II versus Type III

The manual states that Anova() “calculates type-II or type-III analysis-of-variance tables for model objects” from the classes listed above. For lm objects the signature is Anova(mod, error, type = c("II","III",2,3), white.adjust = c(FALSE, TRUE, "hc3", "hc0", "hc1", "hc2", "hc4"), vcov. = NULL, singular.ok, ...), and type defaults to "II". The default test statistic depends on the model class: likelihood-ratio tests for glm and coxph, Pillai for multivariate linear models, and a default method whose test.statistic is "Chisq". white.adjust requests heteroscedasticity-corrected coefficient covariance, and Manova() is a synonym of Anova() for multivariate linear models, including repeated-measures designs specified through idata and idesign. For the contrast setup that Type III tests require, see running ANOVA in R, and for adjusting for a covariate see ANCOVA in R. For Cox models, survival analysis in R covers the modelling side that Anova() then tests.

Levene’s test

leveneTest(y, group, center = median, ...) is the default form; the formula form is leveneTest(y, data, ...). With formula or lm input, the right-hand-side variables must all be factors and completely crossed. Setting center = mean gives the original Levene test; the default median is described in the manual as more robust.

Recoding variables

recode(var, recodes, as.factor, as.numeric = TRUE, levels, to.value = "=", interval = ":", separator = ";") takes a single character string of recode rules. Recode() is an alias provided to avoid name clashes with packages such as Hmisc that have their own recode function.

Output and how to read it

The package documentation defines what each function returns; this page does not reproduce numerical output.

  • vif(). If all terms in an unweighted linear model have one degree of freedom, the usual variance-inflation factors are returned. If any term has more than one degree of freedom (for example a multi-level factor), generalized variance-inflation factors (Fox and Monette, 1992) are returned instead, together with a GVIF^(1/(2*Df)) column. Read each term by its Df. Thresholds are discussed in VIF in R.
  • outlierTest(). Reports Bonferroni p-values for each observation as a mean-shift outlier, computed from studentized residuals; defaults are cutoff = 0.05 and n.max = 10, ordered by size.
  • ncvTest(). A score test of constant error variance against variance that changes with the fitted values or a linear combination of predictors. The manual notes it is often called the Breusch-Pagan test (the Cook and Weisberg 1983 extension).
  • durbinWatsonTest(). Signature durbinWatsonTest(model, max.lag = 1, simulate = TRUE, reps = 1000, method = c("resample","normal"), alternative = c("two.sided","positive","negative")), alias dwt. With simulate = TRUE the p-value is bootstrapped, so repeated runs can differ slightly unless you set a seed.
  • qqPlot(). Plots empirical quantiles of a variable, or of studentized residuals from a linear model, against theoretical quantiles, with a confidence envelope.

Defaults that change the result

These are the points most likely to cause a silent mismatch between what you intended and what the function did, all from the 3.1-5 manual:

  • Anova() defaults to Type II, not Type III. Software that defaults to Type III will give different tables for models with interactions.
  • leveneTest() centres on the median by default, which is not the original Levene test; use center = mean to match it.
  • qqPlot() has different defaults for the default and lm methods. The default method uses distribution = "norm", envelope = TRUE and line = "quartiles"; the lm method uses distribution = "t" as its first-listed choice, line = "robust", simulate = TRUE and reps = 100.
  • vif() with the default type = "terms" ignores marginality in models with interactions; the manual says GVIFs computed this way “aren’t generally sensible”, and type = "predictor" is the alternative.
  • ncvTest() does not have a working glm method: the glm method produces an error.
  • durbinWatsonTest() p-values are simulated by default (1000 replications), so they are not deterministic.

Troubleshooting

“there is no package called car” or install fails

Run install.packages("car") again and confirm your R version meets the R (>= 3.5.0) requirement listed on CRAN. A failed dependency such as lme4 or quantreg stops the install; read the first error message, which names the package that failed.

Function masking messages after library(car)

Because other packages define functions with the same names, R prints a masking message when two attached packages share one. The manual’s Recode() alias exists precisely to avoid a clash with Hmisc’s recode. Call a function unambiguously with car::recode() if needed.

leveneTest() refuses the formula

For formula or lm input the right-hand side must contain only factors that are completely crossed. A numeric predictor on the right-hand side is not allowed; convert it with factor() or test a grouping variable instead.

ncvTest() errors on a glm

This is documented behaviour. Use an lm object, or a different heteroscedasticity approach suited to your model.

The dataset is not found

Example data such as Duncan live in carData. Run library(carData) or library(car), which depends on it.

Free alternatives and overlapping packages

car is itself free software (GPL-2 or GPL-3). Some of its tests have equivalents in other CRAN packages. The comparison below uses only the functions whose documentation was read for this page.

Task car function Alternative Documented difference
Constant-variance test ncvTest(model, var.formula, ...) lmtest bptest(formula, varformula = NULL, studentize = TRUE, ...) Both are described as Breusch-Pagan-type tests. The lmtest manual states bptest regresses residuals on the explanatory variables; the car manual describes ncvTest as a score test of non-constant variance.
Autocorrelation test durbinWatsonTest(model, max.lag = 1, simulate = TRUE, ...) lmtest dwtest(formula, order.by = NULL, alternative = c("greater","two.sided","less"), ...) The car default alternative is "two.sided" and p-values are simulated by default; the lmtest default alternative is "greater".

lmtest (version 0.9-40, published 2022-03-21, GPL-2 or GPL-3 per its CRAN page) is “a collection of tests, data sets, and examples for diagnostic checking in linear regression models.” Note that the two defaults for the alternative hypothesis differ, so the same data can give different p-values from the two functions even when the statistic is similar.

Frequently asked questions

What is the car package in R?

It is the CRAN package “Companion to Applied Regression”, which accompanies Fox and Weisberg’s book of the same name. It provides Type II and III ANOVA tables, variance-inflation factors, regression diagnostics and variable-recoding tools.

How do I install and load it?

Run install.packages("car") once, then library(car) in each session.

Is package car in R free?

Yes. CRAN lists its license as GPL-2 or GPL-3.

Which R version does it need?

The CRAN page for version 3.1-5 lists R (>= 3.5.0) and carData (>= 3.0-0).

Does Anova() in car use Type II or Type III?

Type II by default. Pass type = "III" for Type III.

How do I cite car?

Run citation("car") in R, or use the citation page linked from the CRAN package page.

Sources

Data: Selected car package (version 3.1-5) functions: task, signature and key default

Compiled from the car reference manual on CRAN (version 3.1-5, published 2026-02-03): for each commonly used function, the task it serves, its documented usage signature and the default behaviour most likely to affect results.

Period covered: 2026.

Selected car package (version 3.1-5) functions: task, signature and key default
FunctionTaskDocumented signatureKey default
AnovaType II/III ANOVA tables for fitted modelsAnova(mod, error, type=c("II","III",2,3), white.adjust=c(FALSE,TRUE,"hc3",...), vcov.=NULL, singular.ok, ...)type = "II"
vifVariance-inflation factors (GVIF when a term has more than 1 df)vif(mod, type=c("terms","predictor"), ...)type = "terms"
leveneTestLevene test of equal variances across groupsleveneTest(y, group, center=median, ...)center = median
qqPlotQuantile-comparison plot with confidence envelopeqqPlot(x, distribution, envelope, line, ...)default method: norm, envelope=TRUE, line=quartiles; lm method: t, line=robust, simulate=TRUE, reps=100
outlierTestBonferroni outlier test from studentized residualsoutlierTest(model, cutoff=0.05, n.max=10, order=TRUE, ...)cutoff = 0.05, n.max = 10
ncvTestScore test of non-constant error variancencvTest(model, var.formula, ...)glm method gives an error
durbinWatsonTestDurbin-Watson test of autocorrelated errorsdurbinWatsonTest(model, max.lag=1, simulate=TRUE, reps=1000, method=c("resample","normal"), alternative=c("two.sided","positive","negative"))max.lag = 1, simulate = TRUE, reps = 1000, two.sided
linearHypothesisTests of general linear hypotheses (alias lht)linearHypothesis(model, hypothesis.matrix, rhs=NULL, test=c("F","Chisq"), ...)test = F for lm
recodeRecode a variable from a string of rulesrecode(var, recodes, as.factor, as.numeric=TRUE, levels, to.value="=", interval=":", separator=";")as.numeric = TRUE

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about car Package in R: Install, Key Functions and Defaults

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →