

Residual standard error: 4.252 on 29 degrees of freedom So, for my example, if I save the results to an object called results, I would use the following code: #Perform the linear regression Dataset – The data frame (or list) containing the variables of interest.Y – The Y (dependent) variable this is the one you want to predict.The code to run the linear regression is displayed below: #Perform the linear regression The great thing about performing a simple linear regression test in R is that there are no other packages required. Step 2: Perform the linear regression test in R The trees data frame should now be visible in the environment. To load the dataset into R, I will use the following code: #Load the trees dataset To be able to perform the linear regression, you first need some data containing the two variables of interest.Īs mentioned above, I will be using the trees dataset. If you’re interested in learning more about regression in R, then check out DataCamp’s interactive Correlation and Regression in R online course. What I want to do is to perform a simple linear regression to see how well the measures of girth can predict the measures of volume of the trees. The trees dataset contains measures of girth, height and volume of 31 different cherry trees.

How to perform a simple linear regression in Rįor this tutorial I will use the trees dataset that is freely available within R, so you can follow along with this tutorial if you wish. In this tutorial, I’m going to show you how to perform a simple linear regression test in R.
