Homework 1
Introduction to R, RStudio, and Time Series
The goal of this assignment is to introduce you to R, RStudio, and Time Series!
Getting started
Terminology
We’ve already thrown around a few new terms, so let’s define them before we proceed.
R: The name of the programming language we will be using throughout the course.
RStudio: An integrated development environment for R. In other words, it is a convenient interface for writing and running R code.
R/Rstudio in Class
Go to our RStudio Server at http://turing.cornellcollege.edu:8787/
On the bottom right of RStudio, you should see a
Files
tab. Click that tab.- You should now see a folder with your name on it. In this shared folder, we can both create, edit, and delete files.
- You should also see a folder named
STA364_inst_files
. This is where I will place the files you will need for homework, exams, labs, etc.
Each of your assignments will begin with the following setup steps.
Finding the instructions on our website: https://stats-tgeorge.github.io/STA363_AdvReg/
Going to our RStudio Server at http://turing.cornellcollege.edu:8787/
Open the respective file from the shared STA364_inst_files folder mentioned above. It will be named something like hw-01_LAST_NAME.qmd.
Then you need to save your copy. Click File -> Save as -> Navigate to the folder
STA364_Projects
(that we share) -> Change the “LAST_NAME part of the file name to your last name -> Save.Update the top of the document, called the
YAML
with your name.
Hello RStudio!
RStudio is comprised of four panes.
- On the bottom left is the Console, this is where you can write code that will be evaluated. Try typing
2 + 2
here and hit enter, what do you get? - On the bottom right is the Files pane, as well as other panes that will come handy as we start our analysis.
- If you click on a file, it will open in the editor, on the top left pane. *The image shows an rmd file but we will be working with Quarto files (qmd).
- Finally, the top right pane shows your Environment. If you define a variable it would show up there. Try typing
x <- 2
in the Console and hit enter, what do you get in the Environment pane?
Packages
R is an open-source language, and developers contribute functionality to R via packages. In this assignment we will use the following packages:
- tidyverse: a collection of packages for doing data analysis in a “tidy” way
- fpp3: a package that contains functions and datasets for our course/book
We use the library()
function to load packages. In your Quarto document you should see an R chunk labelled load-packages
which has the necessary code for loading both packages. You should also load these packages in your Console, which you can do by sending the code to your Console by clicking on the Run Current Chunk icon (green arrow pointing right icon).
Note that these packages also get loaded in your Quarto environment when you Render your Quarto document.
Homework Instructions
Be sure to include the relevant R code and full sentences answering each of the questions (e.g., if I ask for the average, you can output the answer in R but also write a full sentence with the answer). Be sure to save your files frequently!
Data for the homework will be in the STA364_inst_files -> data folder.
Exercises
Reading
Read fpp3 1.1-1.4. You do not need to watch the videos but if would like the concepts explained again, or differently, they are available!
Problems
All problems are from The textbook is: Forecasting: Principles and Practice by Rob J Hyndman and George Athanasopoulos – it is freely available online. Chapters 1-9. Abbreviated fpp3.
For cases 3 and 4 in Section 1.5, list the possible predictor variables that might be useful, assuming that the relevant data are available.
For case 3 in Section 1.5, describe the five steps of forecasting in the context of this project.
What are you most interested in forecasting?
Submission
When you are finished with your homework, be sure to Render the final document. Once rendered, you can download your file by:
- Finding the .html file in your File pane of RStudio (on the bottom right of the screen)
- Click the check box next to the file
- Click the blue gear above and then click “Export” to download
- Submit your final HTML document to the respective assignment on Moodle