Skip to content

R Statistics II: Linear Regression

Bioinformatics Core Facility Gothenburg edited this page Sep 5, 2017 · 5 revisions

We will continue with the iris data set and check if there might be an association between the Sepal length and the Petal length.

  1. Plot the petal length against the sepal length to see if there might be a linear relationship between them.
  2. Do histograms of the Sepal Length and the Petal Length to check that they seem to follow a normal distribution

You will probably notice that the histograms shows something that doesn’t look completely normal. The reason is that the two length variables depends a lot on the species. In the plot below you can see the different species in different colors. Since the species influence the length so much we need to consider it when analyzing the lengths.

Iris Scatterplot

  1. Use the lm() function to do a linear regression. Use Sepal Length as response variable and Petal Length as predictor. Save the regression in a variable and look at the results using the summary() function.

  2. Now, do the same regression again, but include Species as covariate (predictor). Compare the effects (i.e. the slopes) for Petal Length in both models. In the second model the effect is smaller. That is because a lot of the Sepal Length is described by the Species.


Previous: T-test

Clone this wiki locally