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 withlm,glm,multinom,polr,coxph,coxme,svyglm,svycoxph,rlm,lmerandlme, among others.linearHypothesis()(aliaslht) 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()andavPlots()(added-variable plots). - Preparing variables.
recode()/Recode(), the power transformationsbcPower(),yjPower()andbasicPower(), and contrast helpers such ascontr.Sum(),contr.Treatment()andcontr.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.
- Load the package.
library(car)also attaches carData, which makesDuncanavailable. - Fit a linear model.
mod <- lm(prestige ~ income + education + type, data = Duncan). This is the model used in the manual’sqqPlot()example. - Test the terms.
Anova(mod). The default istype = "II"; request Type III withAnova(mod, type = "III"). - Check collinearity.
vif(mod). - Inspect residuals.
qqPlot(mod), optionally with a confidence level for the envelope as in the manual’s example,qqPlot(mod, envelope = .99). - Look for outliers.
outlierTest(mod). - Test constant variance.
ncvTest(mod). - 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 aGVIF^(1/(2*Df))column. Read each term by itsDf. 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 arecutoff = 0.05andn.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(). SignaturedurbinWatsonTest(model, max.lag = 1, simulate = TRUE, reps = 1000, method = c("resample","normal"), alternative = c("two.sided","positive","negative")), aliasdwt. Withsimulate = TRUEthe 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; usecenter = meanto match it.qqPlot()has different defaults for the default andlmmethods. The default method usesdistribution = "norm",envelope = TRUEandline = "quartiles"; thelmmethod usesdistribution = "t"as its first-listed choice,line = "robust",simulate = TRUEandreps = 100.vif()with the defaulttype = "terms"ignores marginality in models with interactions; the manual says GVIFs computed this way “aren’t generally sensible”, andtype = "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
- CRAN, car: Companion to Applied Regression, version 3.1-5, read 2026-11-12.
- CRAN, car reference manual, read 2026-11-12.
- CRAN, lmtest package page and reference manual, read 2026-11-12.
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.
| Function | Task | Documented signature | Key default |
|---|---|---|---|
| Anova | Type II/III ANOVA tables for fitted models | Anova(mod, error, type=c("II","III",2,3), white.adjust=c(FALSE,TRUE,"hc3",...), vcov.=NULL, singular.ok, ...) | type = "II" |
| vif | Variance-inflation factors (GVIF when a term has more than 1 df) | vif(mod, type=c("terms","predictor"), ...) | type = "terms" |
| leveneTest | Levene test of equal variances across groups | leveneTest(y, group, center=median, ...) | center = median |
| qqPlot | Quantile-comparison plot with confidence envelope | qqPlot(x, distribution, envelope, line, ...) | default method: norm, envelope=TRUE, line=quartiles; lm method: t, line=robust, simulate=TRUE, reps=100 |
| outlierTest | Bonferroni outlier test from studentized residuals | outlierTest(model, cutoff=0.05, n.max=10, order=TRUE, ...) | cutoff = 0.05, n.max = 10 |
| ncvTest | Score test of non-constant error variance | ncvTest(model, var.formula, ...) | glm method gives an error |
| durbinWatsonTest | Durbin-Watson test of autocorrelated errors | durbinWatsonTest(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 |
| linearHypothesis | Tests of general linear hypotheses (alias lht) | linearHypothesis(model, hypothesis.matrix, rhs=NULL, test=c("F","Chisq"), ...) | test = F for lm |
| recode | Recode a variable from a string of rules | recode(var, recodes, as.factor, as.numeric=TRUE, levels, to.value="=", interval=":", separator=";") | as.numeric = TRUE |
Sources
- car reference manual (CRAN) (accessed 2026-11-12)
- car: Companion to Applied Regression (CRAN) (accessed 2026-11-12)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







