%% Homework 4b Machine Problem (40 points)
%% Due Wednesday, April 17 before 9:00am
% Use [Live Editor > Save > Export to PDF] to prepare your submission for Gradescope.
% A team of researchers used DNA microarrays to measure gene expression in a large set of breast cancer cell lines (Kao, et. al, PLOS One 4(7): e6146. doi:10.1371/ journal.pone.0006146). In this exercise, you will use gene expression profiles from this study and Principal Components Analysis to identify genes whose expression distinguishes invasive (IDC) from regular (DC) ductal carcinoma.
% This assignment uses a slightly modified version of the dataset from Homework 3. Load the data with the following code.

load HW4b_data.mat

% training_lines is a matrix containing gene expression data for the IDC and DC cell lines. Each of the 8750 rows corresponds to a gene with variable expression across the cell lines. Each of the 21 columns represents a cell line.
% is_invasive is a 21-element vector signifying if the columns in training lines represent invasive (1) or regular (0) ductal carcinoma.
% gene_names is an array of names for the genes (rows) in the table training lines
% Using the pca function, find the principal components of the training data. Make sure your matrix is the correct orientation (observations as rows, variables as columns).

% place your code here

% How much variance is explained by the first two principal components?

% place your code here

% <place your answer here>
% Plot the samples using the first two principal components and color the points based on their IDC or DC status. The function gscatter accepts three arguments -- the horizontal coordinates, the vertical coordinates, and a vector indicating the coding for each point. Be sure to label both axes.

% place your code here

% Does either of the first two principal components separate the IDC from DC samples? (The separation does not need to be perfect.)
% <place your answer here>
% Plot the coefficients for each gene along the principal component that separated the IDC and DC samples. Be sure to label your axes.

% place your code here

% In this plot, do coefficients with high values correlate positively with IDC or DC samples?
% <place your answer here>
% Find the genes with the largest and smallest scores along this principal components. (Hint: The functions max and min return two arguments -- the max/min value and the argmax/argmin.)

% place your code here

% <place your answer here>
% Using gscatter, make a plot showing the IDC and DC samples like above. This time, instead of plotting against the principal components, plot the values of the maximum and minimum genes you found above. Be sure to label the axes with the appropriate gene names.

% place your code here

% Do you see good separation along either axis? Why or why not?
% <place your answer here>