Summary
Get a summary of the essential points that were covered in this chapter.
Let’s summarize what we’ve learned so far.
Hopefully, this has helped demystify the process of writing loops and functions and demonstrated that it isn’t too difficult. If we wanted, we could use our predTrialSim
function to build another function that takes a vector of differences between predators or a vector of sample sizes, runs all the models, and lays it all out in a single table for us to interpret. Wouldn’t that be something?
We also hope we’ve demonstrated the power of simulating our data. If we have some inkling of how different our treatments may be, we can simulate our data to get a good idea of how many trials we may need to run. That is extremely powerful.
Remember the following:
-
We should start small and build up from there. If we try to dive right into a significant complex function, we’re more likely to make mistakes and get very frustrated.
-
Taking the time to plan and thinking carefully about what we want our function to do can be invaluable. Think about what we need the function to do and walk through how we’ll do it. Do we need to make a data frame or matrix to store values? Do we need to use a
for
loop to cycle through something? -
We must include the
return()
function at the end.
Get hands-on with 1400+ tech skills courses.