Analysis Goal

Use the given data to detect the presence of heart disease. There are three tasks associated with this analysis:

• Quiz
• Reflection

Data

The response num variable has five levels. The documentation does not appear to be extremely clear about this, so we will assume that the levels mean the following.

• v0: 0 vessels with greater than 50% diameter narrowing. (No presence of heart disease.)
• v1: 1 vessels with greater than 50% diameter narrowing. (Some presence of heart disease.)
• v2: 2 vessels with greater than 50% diameter narrowing. (Some presence of heart disease.)
• v3: 3 vessels with greater than 50% diameter narrowing. (Some presence of heart disease.)
• v4: 4 vessels with greater than 50% diameter narrowing. (Some presence of heart disease.)

In other words, the response variable num is the number of vessels with greater than 50% diameter narrowing.

The following code is available to show how the data was created, but please use the .csv linked above.

# load packages
library("tidyverse")
library("caret")
# install.packages("devtools")
# devtools::install_github("coatless/ucidata")

# load data for each location form ucidata package
hd_ch = as_tibble(ucidata::heart_disease_ch)
hd_cl = as_tibble(ucidata::heart_disease_cl)
hd_hu = as_tibble(ucidata::heart_disease_hu)
hd_va = as_tibble(ucidata::heart_disease_va)

# add location variable for each dataset
hd_ch$location = "ch" hd_cl$location = "cl"
hd_hu$location = "hu" hd_va$location = "va"

# determine number of NA values in each column of "combined" dataset
# bind_rows(hd_ch, hd_cl, hd_hu, hd_va) %>%
#   mutate_all(is.na) %>%
#   summarise_all(sum)

# combine the four locations into one dataset
# remove columns with large proportion of NA values (reasonable in practice)
# remove remainder of rows with NA values (not the best idea in practice)
hd = bind_rows(hd_ch, hd_cl, hd_hu, hd_va) %>%
select(-slope, -ca, -thal) %>%
na.omit()

# coerce location variable to factor
# may need to do this again after reading data
hd$location = factor(hd$location)

# re-define response variable (names will play better with caret)
hd$num = factor(case_when( hd$num == 0 ~ "v0",
hd$num == 1 ~ "v1", hd$num == 2 ~ "v2",
hd$num == 3 ~ "v3", hd$num == 4 ~ "v4"
))

# write to disk
write_csv(hd, "analyses/analysis-02/heart-disease.csv")

For this analysis, do the following:

• Analyze the data however your please! You should keep the stated goal in mind, but you may define a more specific goal that you are working towards.
• Write a report in R Markdowng using the IMRAD template.
• Write an abstract.
• Write an introduction.
• Write an methods section.
• Write an results section.
• Write an discussion.

Submit a .zip file to Compass that contains:

• A .Rmd file that is your IMRAD.
• This file should be written assuming that it is in the same folder as a folder called /data/ which contains heart-disease.csv.
• Hint: Create an RStudio Project.
• A .html file that is the result of knitting your .Rmd file.

The zip file should contain no other files. (Whether or not these two files are within another folder does not matter.)

Submit your .zip file to the correct assignment on Compass2g. You are granted an unlimited number of submissions. Only your final submission will be graded.

R Environment

We assume that your R, R packages, and RStudio are all up-to-date. (Or at least as recent as the versions found on RStudio Cloud.) You’ve been warned.

R Style

Your code will be graded based on its style. We don’t expect you to have a mature coding style, so we have a list of rules which must be followed.

The following will be explicitly checked for in your code:

• All commas must be followed by a space. (Additionally, commas should never be preceded by a space.)
• Infix operators (==, +, -, <-, etc.) should always be surrounded by spaces.
• Exceptions: :, ::, \$, [, [[, ], ]]
• ^: Use x ^ 2 instead of x^2.
• Use a consistent assignment operator. Either <- or =, not both.
• If you choose to use the <- operator, you will need to replace the = operator in the given code.
• Do not use T or F.
• Do not use absolute paths.
• Do not use semicolons, ;.
• Do not use theattach() function.
• No more than one newline (blank line) in a row in an R Markdown document.
• No more than one newline (blank line) in a row in an R chunk.
• A newline before and after each chunk in an R Markdown document.
• No newline to start a chunk. No newline at end of chunk. (The first and last line of each chunk should contain code, or a comment for the first line.)
• A newline at the end of the file.

The following are suggested, but will not be directly assessed:

• Variable and function names (that are user created) should only contain lowercase letters, numbers, and underscores.
• Do not use periods, ., or capital letters in variable and function names.
• Opening (left) curly braces should not be on their own line.
• A space should precede a parenthesis, except in a function call.
• Good: for (i in 1:10)
• Bad: for(i in 1:10)
• Good: mean(x)
• Bad: mean (x)
• Except for the first, argument names should be written in function calls. (Exception for the predict() function.)
• This will be encouraged, but not enforced, as often it is better to make a judgement call than to be dogmatic.

Much of this is derived from the tidyverse style guide. If you follow the tidyverse guide, be aware of our use of ^ and =.

Analysis Quiz

There will be a PL quiz associated with this analysis to check some of the “objective” numeric results of your analysis.

Self Assessment

After submission of the analysis, an example “solution” will be released. In addition, a set of reflection questions will be released. By comparing your submitted analysis to the “solution” together with the reflection questions, you will write a short self-assessment of you analysis.

• Specifics on formatting, submission, etc, will be released after the analysis is due.

This analysis is worth a total of 10 points.

• IMRAD .Rmd and .html (4 points)
• Code Style in .Rmd (0 - 1 - 2)
• Eye Test of .html (0 - 1 - 2)
• Does it look like you’ve done an analysis? Is it reasonably formatted?
• Analysis Quiz (4 points)
• Reflection (2 points)

Failure to submit the correct files will results in 0 points for the IMRAD.

Quiz grading will be similar to regular quizzes.

Grading of the self reflection will largely be based on completion. A template will be provided after submission of the analysis.

Late Policy

The late policy will apply to each individual task. See above for due dates.

Late submissions for both will be accepted up to 48 hours after the initial deadline.

• Up to 24 hours late, the assignment will incur a 10 percent reduction.
• Up to 48 hours late, the assignment will incur a 30 percent reduction.
• No exceptions! Start early and make sure your environment is working correctly and you are able to produce a working document.

If you submit multiple attempts, the final attempt will be graded. If your first submission is on time, but your final submission is late, you will incur the late submission penalty.