class: center, middle, inverse, title-slide # Lab 02 ## Simple Linear Regression ### 01.23.20 --- class: center, middle ## Welcome to lab! --- ### Agenda 1. **Teams!** 2. **Tips:** Working in RStudio & GitHub 3. **Starting a new project:** 5. **Warm-up:** Make sure you know how to push and pull. --- ### Teams - Find your teammates: [STA210 Teams](https://prodduke-my.sharepoint.com/:x:/g/personal/mt324_duke_edu/EZaLCjdJR7hKhHScho6x66IB-p48xcaVwzMy2-0G2e3xKg?e=HQglFh) - By the end of today's lab: - Come up with a **team name** - Find a **weekly 2-hour block between Thursday and Tuesday (outside of the lab session)** that the team can meet to finish lab. You may not need to use the time every week, but it will be helpful to already have a plan for the weeks that you do need extra time. - Come up with away to communicate outside of labs and group meetings (email, text, Slack, etc.). - One person: [click here](https://forms.gle/kTz8NKEDeVj28hSX9) to report your team name, weekly meeting time, and primary form of group communication --- ### Working on a team - Do not pressure each other to finish early; use the time wisely to really learn the material and produce a quality report. - The labs are structured to help you learn the steps of a regression analysis. Do not split up the lab among the team members; work on it together in its entirety. - Everyone has something to contribute! Use the lab groups as an opportunity to share ideas and learn from each other. --- ### Starting a new project You may watch or follow along: - Find the GitHub repo with the prefix `lab-02-`. - On GitHub, click on the green **Clone or download button**, select **Use HTTPS** if it is not already selected. Click on the clipboard icon to copy the repo URL. - Go to https://vm-manage.oit.duke.edu/containers and login with your Duke NetId and Password. - Click to log into the Docker container **STA 210 - Regression Analysis**. You should now see the RStudio environment. --- ### Starting a new project - Go to *File* ➡️ *New Project* ➡️ *Version Control* ➡️ *Git*. - Copy and paste the URL of your assignment repo into the dialog box *Repository URL*. You can leave the direct name empty. It will default to the name of the GitHub repo. - Click *Create Project*, and you should see the contents from your GitHub repo in the **Files** pane in RStudio. --- ### Configure Git - If you need to configure git, type the following lines of code in the console in RStudio filling in your name and email address. ```r library(usethis) use_git_config(user.name="your name", user.email="your email") ``` - Before starting on lab, let's talk about the workflow now that you're on a team --- ### Team Workflow - You and your teammates are working from the same lab-02 GitHub repo. This means you are all contributing to the same R Markdown document! - For today's lab, **<i>only one person should be typing the code/narrative in the R Markdown document at at time</i>**. - Rotate who updates the document based on the markers in the lab instructions. **<i>Each team member should have at least one commit in the lab.</i>** - When you're not typing, you should still be contributing to the discussion but do not actually touch the files on your computer. --- ### Team Workflow We will now walk through the steps in the warmup exercise: - **Every team member**: Click the **Pull** button in the Git pane. This brings the most updated files from GitHub to your RStudio project. - **<u>ONE</u> team member**: - Update the "author" in the YAML of the .Rmd file. - Knit the .Rmd file. - Click the box next to <u>every</u> file in the Git pane. - Write a short and informative commit message. - Push the changes to GitHub. - **Every team member**: Click the **Pull** button in the Git pane. You should now see the changes reflected in the .Rmd and .pdf in your RStudio project. --- ### Lab Tips - Be ready to troubleshoot your document, since it will likely fail to knit on multiple occasions throughout the process. Read the error message carefully and take note of which line is preventing a successful knit. - Make sure to keep track of your various chunks and to keep text and code in the right place. - Remember that your R Markdown file is not aware of your project's global environment and can only make use of variables, functions, etc. that you have loaded or defined in the document. - If you're unsure how a function works or what its arguments are, simply type `?` in front of it and hit enter (`?read_csv` for instance). The "Help" tab will open and provide a summary of the function as well as some examples. --- ### Submitting Assignments - You will be submitting your final assignment in [Gradescope](http://www.gradescope.com). - There is only one submission per group. One person should connect to the team's repo in GitHub and click *Add Group Members* to add the names of all group members to the assignment. - We will be grading the **PDF** in your GitHub repo, so make sure it has all of your final code, output, graphs, and narrative. - Detailed instructions on how to submit the lab are at the [end of the lab instructions](https://www2.stat.duke.edu/courses/Spring20/sta210.001/labs/lab-02-slr.html#submitting-the-assignment). --- ### Need more practice with R? - [Chapter 2: Get Started](https://socviz.co/gettingstarted.html#work-in-plain-text-using-rmarkdown) *Data Visualization by Kieran Healy* - [Chapter 3: Data visualization](https://r4ds.had.co.nz/data-visualisation.html) in *R for Data Science* by Hadley Wickham - RStudio Cloud Primers - Visualization Basics: https://rstudio.cloud/learn/primers/1.1 - Work with Data: https://rstudio.cloud/learn/primers/2 - Visualize Data: https://rstudio.cloud/learn/primers/3 - Visualization in R using ggplot2 workshop by the Center for Data and Visualization Sciences - Jan 30, 1p - 3p - More info & registration: https://duke.libcal.com/event/6085379