Exercise

Testing Assumptions I

Before we run a regression analysis we need to check whether several assumptions are met. A lot of these assumptions involve residuals.

Have a look at the graph. The circles represent data points - or how much someone liked you after you gave them a specific amount of money in reality. The line going through the graph is the slope, which gives an estimated amount amount that someone liked you after you gave them money based on the slope equation. The amount of space between a data point and the line is known as the residual, and its using the values of these residuals that we can test assumptions.

One way to get these would be to count them manually. Fortunately, it's not the 1800's anymore, and we can make R do this for us! In the same way as we used $ to index columns and rows from dataframes and matrixes (e.g. data$variable1 would give you the variable named variable1), we can use this indexing to obtain the values of the residuals from our regression model that we stored as mod1.

Instructions

100 XP

lm() automatically calculates the residuals for your model, which are saved in mod1 after.

In your script, add code to obtain the residuals (named residuals) from mod1 using $ and assign these to resmod1.