*43*

One error you may encounter in R is:

Error in vif.default(model) : there are aliased coefficients in the model

This error typically occurs when multicollinearity exists in a regression model. That is, two or more predictor variables in the model are highly (or perfectly) correlated.

When this occurs, we say that one variable is an â€˜aliasâ€™ of another variable, which causes problems when fitting a regression model.

The following example shows how to fix this error in practice.

**How to Reproduce the Error**

Suppose we fit the following regression model in R:

**#make this example reproducible
set.seed(0)
#define data
x1 #fit regression model
**model

We can use the **vif()** function from the **car** package to calculate the VIF values for each predictor variable in the model to determine if multicollinearity is a problem:

**library(car)
#calculate VIF values for predictor variables
vif(model)
Error in vif.default(model) : there are aliased coefficients in the model
**

We receive an error that â€œ**there are aliased coefficients in the model.**â€œ

This tells us that two or more predictor variables in the model are perfectly correlated.

**How to Fix the Error**

To determine which predictor variables are perfectly correlated, we can use the **cor()** function to create a correlation matrix for the variables:

#place variables in data frame df frame(x1, x2, x3, y) #create correlation matrix for data frame cor(df) x1 x2 x3 y x1 1.00000000 0.126886263 0.126886263 0.065047543 x2 0.12688626 1.000000000 1.000000000 -0.009107573 x3 0.12688626 1.000000000 1.000000000 -0.009107573 y 0.06504754 -0.009107573 -0.009107573 1.000000000

We can see that the variables **x2** and **x3** have a correlation coefficient of 1. This tells us that these two variables are causing the error because theyâ€™re perfectly correlated.

To fix this error, we simply need to fit the regression model again and leave out one of these two variables.

It doesnâ€™t matter which variable we leave out since they both provide the exact same information in the regression model.

For simplicity, letâ€™s remove **x3** and fit the regression model again:

library(car) #make this example reproducible set.seed(0) #define data x1 #fit regression model model #calculate VIF values for predictor variables in model vif(model) x1 x2 1.016364 1.016364

Note that we donâ€™t receive any error this time when calculating the VIF values for the model because multicollinearity is no longer an issue.

**Related:** How to Calculate and Interpret VIF Values in R

**Additional Resources**

The following tutorials explain how to fix other common errors in R:

How to Fix in R: replacement has length zero

How to Fix in R: Arguments imply differing number of rows

How to Fix in R: argument is not numeric or logical: returning na