This worksheet introduces linear regressions between variables. After completing this worksheet you should know how to compute a linear regression model between two variables (in general two columns of a data frame).
First things first: the following analysis is build on top of your script from W02-1. Please copy your script “W02-1.R”, rename the copy to “W04-1.R” and use it for the programming tasks of this worksheet.
After finding some relationships between the variables let's start with regressions!
Please visualize once again the relationship between animal activity and vegetation coverage using the plot() function.
Although it is not a perfectly clear relationship, let's fit a linear model using the lm() function anyway.
Please summarize the result to get all the important information about the linear model. You can use the summary() function. To interpret these results, you might want to check the distribution of the residuals for which you can use the qqPlot() function.
After all the theoretical stuff, let's see what our linear model looks like using the regLine() function
1. You need to download the function from the internet and install it on your computer! It's as easy as: install.packages(“<function name without brackets>”) Great thing about that: you only need to do that one time for each function, because it's on your computer now.
2. If you want to use the function in a script, you have to load that package you just installed. Just write: library(<function name without squared brackets>) Unfortunately you have to do that every time you restart that script in R. That is why normally you will load all the packages you need right before you start reading the data.
After analyzing the relationship between animal activity and vegetation coverage, please check how the animal activity is related to the diversity of agricultural vegetation (i.e. number of different species per plot) and natural vegetation.
After all the technical stuff let's recap what we have done. Do our linear models make sense in a ecological manner?