Directions

Please document your answers to all homework questions using R Markdown, submitting your compiled output on Gradescope.

Assignment Due 11/20 at 11:59pm

\(~\)

Question #1

Unsupervised learning approaches, including as PCA, are frequently used in the analysis of genomic data, which often contain thousands of genetic variables.

The dataset NCI60 in the ISLR package contains 6830 gene expression measurements (variables) for 64 cancer cell lines (observations). Each cell line has known cancer type; however, the goal of this analysis to explore the extent to which gene expression data can be used to characterize and identify different types of cancer.

library(ISLR)
data("NCI60")
nciData <- NCI60$data
labels <- NCI60$labs

Part A: Perform PCA on the gene expression data (be sure to standardize) storing your results in an object named nci_pca. Report the amount of variation explained by the first three principal components.

Part B: Construct a data frame containing scores for the first three principal components and add the “labels” vector as an additional column. Next, filter this data frame to include only the “PROSTATE”, “OVARIAN”, “COLON”, and “MELANOMA” cancer types.

Part C: Using the filtered data, create a 3-D scatter plot (plotly package) that displays each sample’s scores in \(PC_1\), \(PC_2\), and \(PC_3\) and is colored by cancer type. Note: For this particular sub-part (and only this sub-part), I do not care what outside resources you use to construct the graph.

Your PDF will probably not knit with the plotly code present. Instead, save a picture of the 3d scatterplot after knitting it to html, or screenshot it, save that to your 230 folder location, and use the following, see me if you have issues with it:

knitr::include_graphics("plot3d.png")
# change to match what you save it as, and file type

\(~\)

Question #2

The “wines” data set records the results of a chemical analysis on wine samples produced by three different cultivators in the same region of Italy.

wines <- read.csv("https://NFriedrichsen.github.io/data/wines.csv")

The goal of this application is to identify and assess differences across wines and cultivators.

Part A: Use functions in the corrplot package to visualize a correlation matrix of these data. Then, briefly justify principal component analysis as a reasonable approach to analyzing these data.

Part B: Perform PCA on the wines data (be sure to standardize and remove the “Origin” variable) storing your results in an object named wines_pca. Use the methods we covered in the PCA lab to make an argument for how many PC’s to use.

Part C: Calculate and report the amount of variation explained by each of the components you chose to retain in Part B.

Part D: Create a graph that displays the top contributors to \(PC_1\). Using this graph, determine a label for describing this component (Hint: phenols are a group of phytochemicals that account for antioxident activity, flavonoids are the largest group of phenolic compounds, and proanthocyanins are a polyphenol).

Part E: Create a graph that displays the top contributors to \(PC_2\). Briefly describe how this component appears to capture wine characteristics that are different from those that most strongly contribute to \(PC_1\).

Part F: Create a biplot displaying scores and variable loadings for the first two principal components. Use the col.ind argument to color the individual observations according to the 3 different values of the “Origin” variable in the original data set. You might also use the argument label = FALSE to suppress labeling. Then, using the biplot, briefly interpret the differences you see across these three cultivators.

Part G: Use group_by and summarize to find the average scores in \(PC_1\), \(PC_2\), and \(PC_3\) for each of the three cultivators. Briefly comment on how this information relates to the biplot you created in Part F.

\(~\)

\(~\)