---
title: "PSYC 193R: Lecture 2"
output: html_notebook
---

# Write your own function
## Example: addition
```{r}
addition = function(x,y){
  # sum of the two numbers
  z = x + y
  return (z)
}
```
To test our addition() function
```{r}
addition(4,5)
# Expected value: 9
```

## Fahrenheit to Celsius conversion
```{r}
f_to_c = function(degrees_f = 0){
  # your code starts here (1 line)
  degrees_c = NA
  # your code ends here
  return (degrees_c)
}
```
To test our f_to_c() function
```{r}
f_to_c(85)
# Expeced answer: 29.4444
```

## Raw to Z-score conversion
```{r}
raw_to_z = function(x, mu, sd){
  #your code starts here (1 line)
  z = NA
  # your code ends here
  return (z)
}
```
To test our raw_to_z function
```{r}
raw_to_z(110, mean = 100, sd = 15)
# Expected value: 0.6666667
```

## Class Challenge Question: 
```{r}
pop_sd = function(x){
  # Your code starts here
  # Mean of the scores
  M = NA
  
  # Deviation scores (a vector)
  deviation = NA

  # Squared deviations (a vector)
  sq_deviation = NA

  # Sum of squares (a number)
  SS = NA

  # Number of scores in the array (a number)
  N = NA

  # Calculate the population SD
  std_dev = NA

  # your code ends here

  # return the output
  return (std_dev)
}

```

To test pop_sd() function
```{r}
pop_sd(c(1,2,3,4,5))
#Expected value: 1.414214
```

#The Normal Distribution
## Unit Normal Distribution
## Z-score to Probability conversion
```{r}
# finding the percentile associated with a Z score
pnorm(-1.5, mean = 0, sd = 1)
```

## IQ distribution
```{r}
# Percentile associated with an IQ score
pnorm(88, mean = 100, sd = 15)
```

## From percentile to quantile
```{r}
# Finding cut-off Z-score at the lower end
qnorm(0.05, mean = 0, sd = 1)
```

## Mensa International Example
```{r}
# Given 98th percentile, find cut-off IQ score
qnorm(NA, mean = NA, sd = NA)
```

## Class Challenge problems
```{r}
#1. 

#2. 

#3. 
```

