Quadratic Regression in R

Sometimes linear regression doesn’t quite cut it – particularly when we believe that our observed relationships are non-linear.  For this reason, we should turn to other types of regression.  This page is a brief lesson on how to calculate a quadratic regression in R.  As always, if you have any questions, please email me at MHoward@SouthAlabama.edu!

The typical type of regression is a linear regression, which identifies a linear relationship between predictor(s) and an outcome.  Sometimes our effects are non-linear, however.  In these cases, we need to apply different types of regression.

A common non-linear relationship is the quadratic relationship, which is a relationship that is described by a single curve.  In these instances, the relationship between two variables may look like a U or an upside-down U.  Often, we call the latter of these relationships (the upside down U) a “too much of a good thing” effect.  That is, when one variable goes up, then the other goes up too; however, once you get to a certain point, the relationship goes back down.  For example, conscientiousness may relate to life satisfaction.  If you are hard working, then you are generally happier with your life.  However, once you get to a certain level of conscientiousness, your life satisfaction might go back down.  If you are too hard working, then you may be stressed and less happy with your life.

There is more that could be stated about quadratic regression, but we’ll keep it simple.  To calculate a quadratic regression, we can use R.  If you don’t have a dataset, you can download the example dataset here.  Using this dataset, we are going to investigate the linear and quadratic relationship of Var2 predicting Var1.

To perform our analysis, we first need to open our data as well as create the new variable that will detect the non-linear effect.  For a quadratic regression, this is our predictor squared (Var2^2).  To create this new variable, we would need to give it a label.  In this example, we will type: Var2SQ <- .  Then, creating squared variables in R is very easy.  We would just type: MyData$Var2 * Mydata$Var2 .  So, our syntax should look like the following:

Quadratic Regression in R 1

Then, we need to add our new variable to our dataset.  To do so, we need to refer to our dataset by typing: MyData <- .  Then, we need to use the cbind() command to add the new column (e.g. variable) to our dataset.  So, we would type: cbind( .  This would be followed by a reference to our dataset and the new variable to be added, separated by a comma and with a closed parenthesis.  In other words, we would type: MyData, Var2SQ) .

Quadratic Regression in R 2

Lastly, we would conduct our regression analysis with Var1 as our outcome and Var2 and Var2SQ as our predictors.  If you do not know how to conduct a regression analysis in R, please refer to my page on the topic.  Our syntax for conducting the analysis should be:

Quadratic Regression in R 3

Now run your syntax!

Quadratic Regression in R 4

Did you get these results?  Or something similar?  From these results, we can see that the quadratic effect, Var2SQ, was indeed statistically significant.  So, we could say that a non-linear relationship exists between Var2 and Var1.  Pretty neat!

More information about interpreting regression output in R can be obtained from my page on performing a regression in R.  If you have any questions or comments about performing a regression in R, please contact me at MHoward@SouthAlabama.edu.