Dataset 2: Iris petals

Iris image

As written in the module. These data are from three species of the plant, iris. They include measures of petal width and length. Here you will look at how the length of petals influences their width.

You can find the data here: it is a .csv with a header.

Important! When you import the data it is important to make sure it is in the right format. Here you need Species to be a factor and PetalLength to be numeric. See code below.

irisdata <- read.csv("https://www.math.ntnu.no/emner/ST2304/2020v/Week09/irisdata.csv", header=T)

# str() checks the data structure
str(irisdata)

# we can see that the variables are ok but best to be sure
irisdata$Species <- as.factor(irisdata$Species)
irisdata$PetalLength <- as.numeric(irisdata$PetalLength)

# now check again
str(irisdata)

The columns in the dataframe are:

You want to find out how petal length and species effect petal width.

1. What model will you use to answer this? (1 mark)

2. What type of variables do you have and which are response or explanatory? (3 marks)

We have given code to run a model for the data below. Think about what type of model is being run? It is good practice to consider if you would have chosen the same one.

# Model 1
model1 <- lm(PetalWidth ~ Species+PetalLength, data = irisdata)

coef(model1)

confint(model1)

3. Interpret the output of the model. What does it tell you about the effect of petal length on petal width? (5 marks)

Below is the code to make some graphs to check the model fit.

# Graph 1

residuals <- residuals(model1)
fitted <- fitted(model1)
plot(fitted, residuals)

qqnorm(residuals)
qqline(residuals)

4. What are the assumptions of the model? (5 marks)

5. Are the assumptions met? Reference which plot you use to decide and why you make the choice. (6 marks)

6. What other plot might you also want for checking assumptions? (1 mark)

Here is code for another model on the same data.

# Model 2
model2 <- lm(PetalWidth ~ Species*PetalLength, data = irisdata)

coef(model2)

confint(model2)

7. How is this model different to the first one? (1 mark)

8. Given the new model, does this change your interpretation of the effect of petal length on petal width? Why? (4 marks)

9. Which model do you prefer, why? (3 marks)

Show me the answers