---
title: 'PSYC 193R: Homework 1'
output: html_notebook
---

Due date: 11:59pm, Friday Jan 19, 2017

- Name: 
- PID: 

Grading Rubic | Percentage
------------- | -------------
Part 1        | 35%
Part 2        | 35%
Part 3        | 20%
Code Clarity (e.g., commenting, breaking down problems) | 10%

# Homework Assignment 1
### Notes: 
To make sure your code runs: When you are done programming, close RStudio so that everything in the Console and the Environment is cleared. Then press "Run All" from the menu bar and make sure there are no errors. 

- Save a copy of this R Notebook and rename it to psyc193r_hw01_(your pid).Rmd; e.g., psyc193r_hw01_A01234567.Rmd
- When you hit "Preview" in the menu bar, an html file will be generated
- You will have to send in (silau -et- ucsd.edu) this R Notebook and the html output; i.e., psyc193r_hw01_A01234567.Rmd & psyc193r_hw01_A01234567.nb.html
- Codes are run in sequential order: the code appear earlier on may be needed for later parts. When you run some codes, make sure the gray boxes above it are also executed

### Goals:
The objective of this assignment is to familiar yourself with some basic programming that R has to offer. Your task is to complete the missing code marked with "Your task / Your code here".
Make sure you put in enough comments as if you have to refer to those notes later. Lines starting with the pound sign (#) within the gray boxes are not executed.

## Part 1: Arrays & data frames
PSYC 1 has 5 students: Anna, Kat, Kelsey, MJ, Sean  
Their midterm scores are: 6, 7, 5, 6, 5  

#### Your task: 
1. Make a character array, called "name", that contains 5 names
2. Make a numeric array, called "midterm", that contains the 5 scores
```{r}
# your code here (2 lines)
# Array of students

# Array of midterm scores

# your code ends here
```

#### Your task: 
3. make a data frame, called "psyc1", that contains the two variables, "name" & "midterm" 
4. Also, remove the two arrays to release some memory
```{r}
# your code here (2 lines)
# Data frame of the class

# Remove individual arrays

# your code ends here
```

A new student, Taylor, added the class after the midterm, and she took a make-up midterm and got a score of 7.

#### Your task: 
5. Make a new data frame ("new_psyc1") for Taylor, and add her entry to the psyc1 data frame
6. Remove Taylor's data frame to release some memory
```{r}
# your code here
# New data frame for Taylor (1 line)

# Combine Taylor's data frame with the psyc1 data frame (1 line)

# Remove Taylor's data frame (1 line)

# your code ends here
```

#### Your task: 
7. Calculate the class mean for the midterm using the psyc1 data frame, save the value to a variable called "psyc1_mu"
```{r}
# your code here
# Calculate the class mean (1 line)

# your code ends here
```

- Implementation check: (Do not change anything in this box)
```{r}
# Number of entries in the psyc1 data frame
# nrow(): get the dimension of the data frame
# Expected result: 6
nrow(psyc1)

# mean of the class
# Expected result: 6
print(psyc1_mu)
```


## Part 2: Functions
1. As you may know, some people in the class are more familiar with the [International System of Units for weight](https://en.wikipedia.org/wiki/Kilogram) -- "Kilogram"" than the US system (pound, oz). 
Write a function to convert "pounds and oz" to "kg". The function takes in two arguments, and return the weight in kilograms (kg).  

Reference: 1 lb = 16 oz = 0.45359237 kg
Note: Include enough comments for future reference of each step

#### Your task: 
- function name: pounds_to_kg
- arguments: lb, oz
- output: weight in kg
```{r}
# Function for pounds-to-kg conversion
pounds_to_kg = function(lb, oz){
  # Your code here (1-3 lines)
  
  
  # Return the weight in kg (1 line)
  
}
```

- Implementation check: (Do not change anything in this box)
A person weighing 125lb & 5oz should be equivalent to:
```{r}
pounds_to_kg(125, 5)
#Expected answer: 56.84079 kg
```

2. It also happens that the SI for length is [Meter](https://en.wikipedia.org/wiki/Metre), instead of "feet and inches". Write a function to convert "feet and inches" to "meter". The function takes in two arguments, and return the length in meters (m). 

Reference: 1 ft = 12 in = 0.3048 m

#### Your task: 
function name: feet_to_meters
- arguments: ft, inches
- output: length in meters
```{r}
feet_to_meters = function(ft, inches){ # "in" is a reserved keyword so we'll use inches instead
  # Your code here (1-3 lines)
  
  
  # Return the length in meters (1 line)
  
}
```

- Implementation check: (Do not change anything in this box)
A person with a height of "6 ft & 11 in" should be equivalent to:
```{r}
feet_to_meters(6, 11)
#Expected answer: 2.1082 m
```

3. [Body-mass Index (BMI)](https://en.wikipedia.org/wiki/Body_mass_index) is often used as a rough index to assess whether a person is overweight. A BMI of 18.5 to 25 is considered in the normal range. The formula for BMI is as follow, while both mass and height are measured in SI units (kg and m, respectively). 

Reference: $bmi = mass / height^{2}$

Write a function that takes in 4 argument, mass in "lb & oz", and height in "ft and in", and calculate the corresponding BMI. You may use the functions you created above to save some lines. 

#### Your task: 
function name: bmi
- arguments: ft, inches, lb, oz
- output: body-mass-index
```{r}
bmi = function(ft, inches, lb, oz){ 
  # Your code here
  # Convert the height to m (1 line): use function created above
  
  # Convert the weight to kg (1 line): use function created above
  
  # Calculate BMI (1 line)
  
  # Return BMI (1 line)
  
}
```

- Implementation check: (Do not change anything in this box)
A person with a height of "5 ft, 7 in" and a weight of "125 lb, 5 oz" should have a BMI of 
```{r}
bmi(5,7,125,5)
#Expected answer: 19.62651
```


## Part 3: Design a study (No coding needed)
"Social Media Addiction"" has become a public health issue. Those sites / apps are affecting people's day-to-day functioning, like sleep,  study, and work. Design a study that could potentially help solve / alleviate this blooming global crisis.  

Some references:  
[Students 'cannot multi-task with mobiles and study'](http://www.bbc.com/news/education-33047927)  
[Teenagers 'checking mobile phones in night'](http://www.bbc.com/news/education-37562259)

The research question is vague by design. I would like you to pick a more specific area to investigate and design a study around your specific research question. 

#### Your task:  
To fill in the information below. Use the "Practical Research Tips" in the lecture slides if possible, or give a short justification of not using it. 
There are usually no right or wrong answers for a research design, but there are better or not as good ones. Keep your answers to the point and within 3 sentences. 

- What is your specific research question?


- What is the population?


- How are you going to sample the population?


- Is it an experiment, quasi-experiment, or observational study


- Independent / Dependent Variable(s)


- Operational definitions of the IV(s) & DV(s)


- Scales of Measurement of the IV(s) & DV(s)


- Is it a between- / within-subjects design?


- What is the study like? Specifically, what will you ask participants to do?



#### End of Homework Assignment 1
