Www.cybertestbank.com
Chapter 1 exercises: Coder editionUse the National Health and Nutrition Examination Survey (NHANES) data to examine marijuana use in the United States. Spend a few minutes looking through the NHANES website () before you begin, including finding the online codebook for the 2013–2014 data. Complete the following tasks to explore whether age is related to marijuana use in the United States.Open the 2013–2014 NHANES data file saved as nhanes_2013_ch1.csv with the book materials at edge.harris1e (Achievement 1)Examine the data types for DUQ200, RIDAGEYR, and RIAGENDR, and fix data types if needed based on the NHANES codebook (Achievements 2 and 3)Based on the online NHANES codebook, code missing values appropriately for DUQ200, RIDAGEYR, and RIAGENDR (Achievement 4)Create a bar chart showing the percentage of NHANES participants answering yes and no to marijuana use (Achievement 5)Recode age into a new variable called age.cat with 4 categories: 18–29, 30–39, 40–49, 50–59 (Achievement 7)Create a bar chart of marijuana use by age group (Achievement 6)Add a prolog and comments to your code (Achievement 1)Following the R code in your code file, use comments to describe what you found. Given what you found and the information in the chapter, what do you predict will happen with marijuana legalization in the next 10 years? Discuss how the omission of older people from the marijuana use question for NHANES influenced your prediction. Write your prediction and discussion in comments at the end of your code file. (Achievement 1)Chapter 1 exercises: Hacker editionRead the coder instructions and complete #1–#5 from the coder edition. Then do the following:Create a bar chart of marijuana use by age group and sex with side-by-side bars (Achievement 5)Add a prolog and comments to your code (Achievement 1)Following the R code in your code file, use comments to describe what you found in no more than a few sentences. Given what you found and the information in the chapter, what do you predict will happen with marijuana legalization in the next 10 years? Discuss how the omission of older people from the marijuana use question for NHANES influenced your prediction. Write your prediction and discussion in comments at the end of your code file. (Achievement 1)# Chapter 1 Coder & Hacker Key --------------------------------------------# Instructors please note that there are multiple ways to do almost everything in R. What you'll find in this key is consistent with the way the material was explained in the text, but it is not the only way, so student work may use other strategies and still get to the same place.# Note that this document can be navigated by using the hashtag bookmarks at the bottom of the source code window. # Coder Exercises ---------------------------------------------------------# 1 -----------------------------------------------------------------------# open the NHANES data saved in [location]nhanes2013 <- read.csv("[location]/nhanes_2013_ch1.csv")# 2 -----------------------------------------------------------------------# examine data types with class function# DUQ200 and RIAGNDR should be factors# RIDAGEYR should be numericclass(nhanes2013$DUQ200)class(nhanes2013$RIDAGEYR)class(nhanes2013$RIAGENDR)# convert to factors and numericlibrary(package = "tidyverse")nhanes2013.clean <- nhanes2013 %>% mutate(DUQ200 = as.factor(x = DUQ200)) %>% mutate(RIAGENDR = as.factor(x = RIAGENDR)) %>% mutate(RIDAGEYR = as.numeric(x = RIDAGEYR))# check the recodingsummary(object = nhanes2013.clean)# 3 -----------------------------------------------------------------------# missing values are fine for age, gender# recode 7 and 9 as NA for DUQ200# adding to prior code nhanes2013.clean <- nhanes2013 %>% mutate(DUQ200 = as.factor(x = DUQ200)) %>% mutate(RIAGENDR = as.factor(x = RIAGENDR)) %>% mutate(RIDAGEYR = as.numeric(x = RIDAGEYR)) %>% mutate(DUQ200 = na_if(x = DUQ200, y = 7)) %>% mutate(DUQ200 = na_if(x = DUQ200, y = 9)) %>% droplevels()# check recodingsummary(object = nhanes2013.clean)# 4 -----------------------------------------------------------------------# add labels for Yes and No to DUQ200nhanes2013.clean <- nhanes2013 %>% mutate(DUQ200 = as.factor(x = DUQ200)) %>% mutate(RIAGENDR = as.factor(x = RIAGENDR)) %>% mutate(RIDAGEYR = as.numeric(x = RIDAGEYR)) %>% mutate(DUQ200 = na_if(x = DUQ200, y = 7)) %>% mutate(DUQ200 = na_if(x = DUQ200, y = 9)) %>% mutate(DUQ200 = recode_factor(DUQ200, `1` = "Yes", `2` = "No")) %>% droplevels()# check recodingsummary(object = nhanes2013.clean)# make a bar graph of marijuana usenhanes2013.clean %>% drop_na(DUQ200) %>% ggplot(aes(x = DUQ200)) + geom_bar() + labs(x = "Ever used marijuana")# 5 -----------------------------------------------------------------------# add age categories variablenhanes2013.clean <- nhanes2013 %>% mutate(DUQ200 = as.factor(x = DUQ200)) %>% mutate(RIAGENDR = as.factor(x = RIAGENDR)) %>% mutate(RIDAGEYR = as.numeric(x = RIDAGEYR)) %>% mutate(DUQ200 = na_if(x = DUQ200, y = 7)) %>% mutate(DUQ200 = na_if(x = DUQ200, y = 9)) %>% mutate(DUQ200 = recode_factor(DUQ200, `1` = "Yes", `2` = "No")) %>% mutate(age.cat = cut(x = RIDAGEYR, breaks = c(-Inf, 29, 39, 49, 59), labels = c('18-29', '30-39', '40-49', '50-59'))) %>% droplevels()# check recodingsummary(object = nhanes2013.clean)# 6 -----------------------------------------------------------------------# make a bar graph of marijuana usenhanes2013.clean %>% drop_na(DUQ200) %>% ggplot(aes(x = age.cat, fill = DUQ200)) + geom_bar(position = "dodge") + labs(x = "Age in years")# 7 -----------------------------------------------------------------------##################################### Project name: Chapter 1 Coder exercises# Project purpose: Practice coding# Code author name: Jenine Harris# Date last edited: 30112019 # Location of data used: [location]/nhanes_2013_ch1.csv##################################### 8 -----------------------------------------------------------------------# More people have ever used marijuana or hashish than not used marijuana or hashish. The only age group where this was not true was the 40-49 year old age group. I would predict that states will continue to legalize for medicinal and recreational purposes. By the end of 10 years I would guess it will be moving toward legalization at the federal level. The omission of older people from the NHANES question on use made it more difficult to understand trends across the entire spectrum, especially given that older voters vote at a higher rate in the US.# Hacker Exercises --------------------------------------------------------# 6 -----------------------------------------------------------------------# clean sex variablenhanes2013.clean <- nhanes2013 %>% mutate(DUQ200 = as.factor(x = DUQ200)) %>% mutate(RIAGENDR = as.factor(x = RIAGENDR)) %>% mutate(RIDAGEYR = as.numeric(x = RIDAGEYR)) %>% mutate(DUQ200 = na_if(x = DUQ200, y = 7)) %>% mutate(DUQ200 = na_if(x = DUQ200, y = 9)) %>% mutate(DUQ200 = recode_factor(DUQ200, `1` = "Yes", `2` = "No")) %>% mutate(RIAGENDR = recode_factor(RIAGENDR, `1` = "Male", `2` = "Female")) %>% mutate(age.cat = cut(x = RIDAGEYR, breaks = c(-Inf, 29, 39, 49, 59), labels = c('18-29', '30-39', '40-49', '50-59'))) %>% droplevels()# check recodingsummary(object = nhanes2013.clean)# make a bar graph of marijuana usenhanes2013.clean %>% drop_na(DUQ200) %>% group_by(DUQ200, age.cat, RIAGENDR) %>% count() %>% group_by(age.cat, RIAGENDR) %>% mutate(perc.grass = 100*n/sum(n)) %>% ggplot(aes(x = age.cat, y = perc.grass, fill = RIAGENDR)) + geom_col(position = "dodge") + labs(x = "Age in years", y = "Percent used marijuana or hashish")# 7 -----------------------------------------------------------------------##################################### Project name: Chapter 1 Hacker exercises# Project purpose: Practice coding# Code author name: Jenine Harris# Date last edited: 30112019 # Location of data used: [location]/nhanes_2013_ch1.csv##################################### 8 -----------------------------------------------------------------------# More than half of males and females in every age group had ever tried marijuana or hashish. With the exception of 40-49 year olds, a higher percentage of males than females had ever tried marijuana or hashish. Given the addition of new policies recently and the highf percentage of people who have ever tried marijuana or hashish, I would anticipate additional policies permitting medical and recreational use in the next 10 years. ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- getroman com reviews
- acurafinancialservices.com account management
- https www municipalonlinepayments
- acurafinancialservices.com account ma
- getroman.com tv
- http cashier.95516.com bing
- http cashier.95516.com bingprivacy notice.pdf
- connected mcgraw hill com lausd
- education.com games play
- rushmorelm.com one time payment
- autotrader.com used cars
- b com 2nd year syllabus