---
title: "Lab 2: Getting Started With Homework"
subtitle: Biostat 203B
author: "Dr. Hua Zhou @ UCLA"
date: today
format:
  html:
    theme: cosmo
    embed-resources: true
    number-sections: true
    toc: true
    toc-depth: 4
    toc-location: left
    code-fold: false
knitr:
  opts_chunk: 
    echo: true
    fig.align: 'center'
---

This tutorial assumes that you have already installed R, RStudio, and Git on your computer. If not, please refer to the [Lab 1](https://ucla-biostat-203b.github.io/2024winter/labs/lab01/lab01.html).

# Set up GitHub repo for 203B homework

- On <https://github.com/>, create a **private** repository `biostat-203b-2024-winter` and add `Hua-Zhou` and TA team (`Tomoki-Okuno` for Lec 1; `jonathanhori` and `jasenzhang1` for Lec 80) as your collaborators with write permission. This repository is for submitting your 203B homework.

- You can use RStudio to git clone the `biostat-203b-2024-winter` repository to your local machine: `File` -> `New Project...` -> `Version Control` -> `Git` -> input `Repository URL:`, `Project directory name:` (203b-hw).

- Alternatively, in Terminal (Mac Terminal, Windows Git Bash, or Windows WSL), you can run
```{bash}
#| eval: false
git clone [SSH_ADDRESS] ~/203b-hw
```
to clone your homework repository to a folder called `203b-hw` under your home directory on your computer. `[SSH_ADDRESS]` is obtained by clicking the menu `<> Code` -> `SSH` on the repository page on GitHub. Then you can double click the `biostat-203b-2024-winter.Rproj` file to open the RStudio project.

# MIMIC Data

Much of homework and exercises are demonstrated on the [MIMIC-IV](https://physionet.org/content/mimiciv/2.2/) v2.2 data set. Download the data to your computer from [here](https://ucla.box.com/s/u90zkq9cvpv8p5s064s8bvy40c0tqx33) (7.69 GB), and make it available at `~/mimic`. For example, you can create a symbolic link by
```{bash}
#| eval: false
ln -s /PATH/TO/YOUR/MIMIC_FOLDER ~/mimic
```
Your homework solution should always read data from `~/mimic`. This is critical for TA team to reproduce your homework.
```{bash}
ls -l ~/mimic/
```

# Start with homework 1

On your local machine: 

- Clone the repository, create `develop` branch, where your work on solutions.

```{{bash}}
#| eval: false
# clone the project
git clone git@github.com:[USERNAME]/biostat-203b-2024-winter.git
# enter project folder
cd biostat-203b-2024-winter
# what branches are there?
git branch
# create develop branch
git branch develop
# switch to the develop branch
git checkout develop
# create folder for HW1
mkdir hw1
cd hw1
# let's write solutions
echo "sample solution" > hw1.Rmd
echo "some bug" >> hw1.Rmd
# commit the code
git add hw1.Rmd
git commit -m "start working on problem #1"
# push to remote repo
git push
```

- Submit and tag HW1 solution to the `main` branch.

```{{bash}}
#| eval: false
# which branch are we in?
git branch
# change to the main branch
git checkout main
# merge develop branch to main branch
# git pull origin develop 
git merge develop
# push to the remote main branch
git push
# tag version hw1
git tag hw1
git push --tags
```

- RStudio has good Git integration. But practice command line operations also.

# Homework 1

- Demo Q2, Q3.1, Q3.2, Q5, Q6.