]---
title: HW02
subtitle: Basic Rmd and Statistics
output:
  html_document:
    theme: spacelab
    highlight: tango
    toc: true
---

## Assignment overview

The purpose of this assignment is to get you working in R, to do a little self reflection and examination of your learning habits, and assess understanding of first week statistical concepts.

## Instructions

Put your answers for each question in this document where it says `ANSWER HERE`. You don't have to put your answers in between the bartacks. They are there just to make it easier to see where your answer should go. Read the questions carefully. Make sure you answer completely and to give explanations. It is better to be overly wordy than to put too little. The file `03_Describing-Distributions` is a useful reference for the Rmd section in addition to last week's lecture recordings.

## Part 1: Examination and Improvement of our Learning

Because we all have room for improvement, here are a few tasks for you to become a better learner.

### Metacognition

1. Introduce yourself to the concept of metacognition at;  
   https://sites.google.com/a/uwlax.edu/exploring-how-students-learn/what-s-all-the-fuss-about-metacognition

2. Take the _Metacognition Awareness Inventory_ at;  
   https://www.harford.edu/~/media/PDF/Student-Services/Tutoring/Metacognition%20Awareness%20Inventory.ashx

3. Write a reflection on metacognition. Discuss your scores and what you learned from the readings.

My lowest scores were in the sections of planning and comprehension monitoring. I would agree with thees assumptions, I think that I am really baf at planning out my studying and my time while I am studying as well as my understanding of what I know and dont know, I loose track of what i have been reading a lot of the time and probrably can be much better at it.]

### Habits for Success

4.  Watch or listen to one of the following choices and write **one** observation or question.

- Video - **Hidden Key to Understanding and Overcoming Procrastination**  
  https://mcgraw.princeton.edu/node/2641

- Podcast - **NPR - Hidden Brain | I'm Right, You're Wrong | Mar 13, 2017**  
  https://www.npr.org/2017/03/13/519661419/when-it-comes-to-politics-and-fake-news-facts-arent-enough

- YouTube - **Becoming aware of our biases | Tali Sharot | Huxley Summit Dec 21, 2017**  
  https://www.youtube.com/watch?v=hdnGkFdtA-A

I have seen the video about challenging our own beliefs before and I find it very interesting. Just the fact that people always look to confirm what they think is right, for example I saw anoter video on the experimant about hte numbers, and a man keot on trying to confirm his own sequence about the numbers because he thought it was right and he wouldnt get that off his mind. And only if he had just gone oh maybe I am wrong he would have gotten there much faster.

5.  Select one link to examine from this site https://mcgraw.princeton.edu/undergraduates/resources-handouts-and-advice-undergraduates , and write **one** thing that you will attempt to incorporate into your studies this semester.

I clicked on the " Putting Your Extracurricular Skills to Use in Your Studies ". And I liked how they talked about the zone that, well in my case I get into while I am playing baseball and I am pitching, just being able to block out all of the outside distractions while studying and really focus on that one thing at a time could be really useful. I have actually found myself doing this before, if I am annoyed or angry at something I can easily just block everything out and have not hear a single thing other than what is in my head.

## Part 2: Statistics

The following questions are to assess your understanding of our first week's statistical topics.

8.  **Infections Can Lower IQ** A headline in June 2015 proclaims “Infections can lower IQ.” The headline is based on a study in which scientists gave an IQ test to Danish men at age 19. They also analyzed the hospital records of the men and found that 35% of them had been in a hospital with an infection such as an STI or a urinary tract infection. The average IQ score was lower for the men who had an infection than for the men who hadn’t.

- What are the cases in this study?
- What is the explanatory variable? Is it categorical or quantitative?
- What is the response variable? Is it categorical or quantitative?
- Does the headline imply causation?
- Is the study an experiment or an observational study?
- Is it appropriate to conclude causation in this case?

-The cases are the people that have and dont have an infection
-The explanitory variable is whether or not the person had an infection or not, and it is categorical
-The response variable is the persons IQ, and this is numerical
-Yes, saying that infections cam lower IQ is saying that an infection can Cause a lower IQ in a person
-It is an observational study because they are not controlling whether or not the perons has an infection, they are recoding what they see
-I do not think that we have enough information to say whether or not causation is present, If we had more informaion about medicines they were on and other variables in the hospital then mayeb we could make an assumption but right now I dont think we can say if it does or does not

9. **Hormones and Fish Fertility** When women take birth control pills, some of the hormones found in the pills eventually make their way into lakes and waterways. In one study, a water sample was taken from various lakes. The data indicate that as the concentration of estrogen in the lake water goes up, the fertility level of fish in the lake goes down. The estrogen level is measured in parts per trillion (ppt) and the fertility level is recorded as the percent of eggs fertilized.

- What are the cases in this study?
- What are the variables?
- Classify each variable as either categorical or quantitative.
- Identify the explanatory and response variables.

-The case is the lake water, that has the level s of estrogen and the fish fertility variables
-The variables are the estrogen levels of the water and the fertility levels of the fish
-Both of the variables are quantitiative 
-The explanitory variable is the estrogen levels of the water and the response variable is the fertility rate of the fish

10. **Drinking Age** A biased sampling situation is described for the following study;

    To estimate the proportion of Americans who support changing the drinking age from 21 to 18, a random sample of 100 college students are asked the question, “Would you support a measure to lower the drinking age from 21 to 18?”

- What is the sample?
- What is the researcher's population of interest?
- To what population we can generalize to, (for our given sample)?

-The sample is the 100 college students
-The population instrest is all of of the US
-We can generalize about college students thoughts on the drinking age, not the whole united states

## Part 3: Rmd

1. Write a code block which loads the necessary libraries and data but also does not print out unnecessary stuff. The file you should load is `~/Data/output/ACS_clean.RData`.

```{r, include=F}
library(dplyr)
library(knitr)
library(janitor)
library(ggplot2)
load("~/Data/output/ACS_clean.RData")
```

2. What is the name of the data which was loaded?

```{r}
ls()
```

3. How many observations and variables are there in the data? How do you know?

```{r}
mydata_clean %>%
glimpse()
```

4. The variable `JWTR_cat` is categorical and indicates how the person got to work. How many males are there in the sample that `Walked` to work?

```{r}
mydata_clean %>%
select (JWTR_cat, SEX_cat) %>%
filter (SEX_cat == "Male", JWTR_cat == "Walked")
```
266 males walk to work

5. Find the average wage (use the variable `WAGP` and the command `mean`) for `Male`(s) and `Female`(s) who have `Never married`.

```{r}
mydata_clean %>%
select( WAGP, SEX_cat, MSP_cat) %>%
filter( SEX_cat == "Male", MSP_cat == "Never married") %>%
summarize (average_wage = mean (WAGP, na.rm=TRUE))

mydata_clean %>%
select( WAGP, SEX_cat, MSP_cat) %>%
filter( SEX_cat == "Female" , MSP_cat == "Never married") %>%
summarize (average_wage = mean (WAGP, na.rm=TRUE))
```


6. Write a code block which counts the number of `Male`(s) and `Female`(s) for each race (use the variable `RAC1P_cat`).

```{r}
mydata_clean %>%
count (SEX_cat, RAC1P_cat)
```