As an exercise on linear regression, we will analyse the fish tank dataset.
Fish tank dataset
In this experiment, 96 fish (dojofish, goldfish and zebrafish) were placed separately in a tank with two litres of water and a certain dose (in mg) of a certain poison EI-43,064. The resistance of the fish a against the poison was measured as the amount of minutes the fish survived upon adding the poison (Surv_time, in minutes). Additionally, the weight of each fish was measured.
Goal
The research goal is to study the association between the dose of the poison that was administered to the fish and their survival time by using a linear regression model.
Read the required libraries
Import the data
poison <- read_csv("https://raw.githubusercontent.com/GTPB/PSLS20/master/data/poison.csv")
Data tidying
We can see a couple of things in the data that can be improved upon:
- Capitalise the fist column name
- Set the Species column as a factor
- Change the species factor levels from 0, 1 and 2 to Dojofish, Goldfish and Zebrafish. Hint: use the fct_recode function.
Data Exploration and Descriptive Statistics
Explore the data, there are multiple variables in the dataset.
How many fish do we have per species?
Which variables might influence survival.
Make a suitable visualisation of the association between the dose and the survival time.
Modelling the data
In principle we have multiple variables that can affect the survival. We have not seen in the lecture how to model the response based on multiple predictors. In order to get familiar with simple linear regression
Check the remaining assumptions
Interpret the model parameters of the linear model
Interpret the results, both for the intercept as well as for the slope
Write a conclusion that answers the research hypothesis.
LS0tCnRpdGxlOiAiVHV0b3JpYWwgNi4zOiBMaW5lYXIgcmVncmVzc2lvbiAoY29udGludW91cykgb24gdGhlIGZpc2ggdGFuayBkYXRhc2V0IiAgIApvdXRwdXQ6CiAgICBodG1sX2RvY3VtZW50OgogICAgICBjb2RlX2Rvd25sb2FkOiB0cnVlICAgIAogICAgICB0aGVtZTogY29zbW8KICAgICAgdG9jOiB0cnVlCiAgICAgIHRvY19mbG9hdDogdHJ1ZQogICAgICBoaWdobGlnaHQ6IHRhbmdvCiAgICAgIG51bWJlcl9zZWN0aW9uczogdHJ1ZQotLS0KCkFzIGFuIGV4ZXJjaXNlIG9uIGxpbmVhciByZWdyZXNzaW9uLCB3ZSB3aWxsIGFuYWx5c2UKdGhlIGZpc2ggdGFuayBkYXRhc2V0LgoKIyBGaXNoIHRhbmsgZGF0YXNldA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