The data set is from a case-control study of smoking and Alzheimer’s disease. The data set has two variables of main interest:

library(tidyverse)

# Import data
data("alzheimer", package = "coin")

# create a table
tbl <- xtabs(~disease + smoking, alzheimer)
ftable(tbl)

# create a mosaic plot from the table
library(vcd)
mosaic(tbl, 
       shade = TRUE,
       legend = TRUE,
       labeling_args = list(set_varnames = c(disease = "")),
       set_labels = list(disease = c("Alzheimer", "Other\ndementias", "Other\ndiagnoses")))

Q1 Describe the largest group that has other dementias. Discuss it by number of cigarettes per day.

The largest group that has dementia are people who smoke 0 cigarettes each day.

Q2 Describe one group that has more cases than expected given independence (by chance). Discuss it by number of cigarettes per day.

People with dementia that smoke more than 20 cigarettes a day have more cases than expected.

Q3 Does smoking seem to matter in determining other dementias? Discuss your reason using the masaic chart above.

Yes, because smoking is known to increase the risks of having dementia. Using the chart, people are more likely to die of dementia if they smoke more than 20 cigarettes a day.

Q4 Create correlation plot for RailTrail.

Hint: The RailTrail data set is from the mosaicData package.

# import data
data(RailTrail, package="mosaicData")

# select numeric variables
df <- dplyr::select_if(RailTrail, is.numeric)

# calulate the correlations
r <- cor(df, use="complete.obs")
round(r,2)

library(ggplot2)
library(ggcorrplot)

# visualize the correlations
ggcorrplot(r, 
           hc.order = TRUE, 
           type = "lower",
           lab = TRUE)

Q5 List all four variables that have negative correlation with the number of trail users (volume).

The variables that have negative correlation are -0.04, -0.25, -0.37, and -0.23.

Q8 Hide the messages, the code and its results on the webpage.

Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.