---
title: "ADA2: Homework Ch 03 A Taste of Model Selection for Multiple Regression"
author: "Name Here"
date: "mm/dd/yyyy"
output:
pdf_document:
number_sections: yes
toc: yes
html_document:
toc: true
number_sections: true
code_folding: show
---
```{R, echo=FALSE}
# I set some GLOBAL R chunk options here.
# (to hide this message add "echo=FALSE" to the code chunk options)
knitr::opts_chunk$set(comment = NA, message = FALSE, warning = FALSE, width = 100)
knitr::opts_chunk$set(fig.align = "center", fig.height = 4, fig.width = 6)
knitr::opts_chunk$set(cache = TRUE, autodep=TRUE) #$
```
# Prostate-specific antigen (PSA)
A university medical center urology group
([Stamey, _et al._, 1989](http://www.ncbi.nlm.nih.gov/pubmed/2468795))
was interested in the association between a prostate-specific antigen (PSA) and
a number of prognostic clinical measurements in men with advanced prostate
cancer. Data were collected on 97 men who were about to undergo radical
prostectomies.
We will look at a subset of this dataset for this assignment;
later in the semester we'll be able to analyze the full complex dataset.
column | Variable name | Description
-|-|-
1 | Identification number | 1-97
2* | PSA level | Serum prostate-specific antigen level (mg/ml)
3* | Cancer volume | Estimate of prostate cancer volume (cc)
4* | Weight | Prostate weight (gm)
5* | Age | Age of patient (years)
6 | Benign prostatic | Amount of benign prostatic hyperplasia (cm2) hyperplasia
7 | Seminal vesicle invasion | Presence or absence of seminal vesicle invasion: 1 if yes; 0 if no
8 | Capsular penetration | Degree of capsular penetration (cm)
9 | Gleason score | Pathologically determined grade of disease (6,7,8), higher indicates worse prognosis
__Background:__
Until recently, PSA was commonly recommended as a screening mechanism for
detecting prostate cancer. To be an efficient screening tool it is important
that we understand how PSA levels relate to factors that may determine
prognosis and outcome. The PSA test measures the blood level of
prostate-specific antigen, an enzyme produced by the prostate. PSA levels under
4 ng/mL (nanograms per milliliter) are generally considered normal, while
levels over 4 ng/mL are considered abnormal (although in men over 65 levels up
to 6.5 ng/mL may be acceptable, depending upon each laboratorys reference
ranges). PSA levels between 4 and 10 ng/mL indicate a risk of prostate cancer
higher than normal, but the risk does not seem to rise within this six-point
range. When the PSA level is above 10 ng/mL, the association with cancer
becomes stronger. However, PSA is not a perfect test. Some men with prostate
cancer do not have an elevated PSA, and most men with an elevated PSA do not
have prostate cancer. PSA levels can change for many reasons other than cancer.
Two common causes of high PSA levels are enlargement of the prostate (benign
prostatic hypertrophy (BPH)) and infection in the prostate (prostatitis).
# Rubric
A goal here is to build a multiple regression model to predict PSA level
`PSA` from the cancer volume `V`, Prostate weight `Wt`, and Age `Age`.
A reasonable strategy would be to:
1. Examine the relationship between the response and the potential predictors.
2. Decide whether any of the variables should be transformed.
3. Perform a backward elimination using the desired response and predictors.
4. Given the selected model, examine the residuals and check for influential cases.
5. Repeat the process, if necessary.
6. Interpret the model and discuss any model limitations.
## __(1 p)__ Looking at the data
_Describe any patterns you see in the data.
Are the ranges for each variable reasonable?
Extreme/unusual observations?
Strong nonlinear trends with the response suggesting a transformation?_
```{R}
fn.data <- "http://statacumen.com/teach/ADA2/homework/ADA2_HW_03_psa.txt"
psa <- read.table(fn.data, header=TRUE)
# remove the variables we don't want to use for this assignment
psa <- subset(psa, select = names(psa)[-c(1, 6, 7, 8, 9)])
# simplify column names
names(psa)
colnames(psa) <- c("PSA", "V", "Wt", "Age")
str(psa)
summary(psa)
```
```{R, fig.height = 8, fig.width = 8}
library(ggplot2)
library(GGally)
#p <- ggpairs(psa)
# put scatterplots on top so y axis is vertical
p <- ggpairs(psa
#, upper = list(continuous = wrap("points", alpha = 0.2, size = 0.5))
, upper = list(continuous = "points")
, lower = list(continuous = "cor")
)
print(p)
```
```{R}
# correlation matrix and associated p-values testing "H0: rho == 0"
library(Hmisc)
rcorr(as.matrix(psa))
```
### Solution
[answer]
## __(2 p)__ Backward selection, diagnostics of reduced model
Fit an appropriate full model and perform backward selection using __BIC__.
Discuss the diagnostics in terms of influential observations or problematic structure in the residuals.
### Solution
[answer]
## __(3 p)__ Address model fit
If the model doesn't fit well (diagnostics tell you this, not $R^2$ or significance tests),
then address the lack of model fit.
Transformations and removing influential points are two strategies.
The decisions you make should be based on what you observed in the residual plots.
If there's an influential observation, remove it and see how that affects
the backward selection (whether the same predictors are retained),
the model fit (diagnostics),
and regression coefficient estimates (betas).
If there's a pattern in the residuals that can be addressed by a transformation,
guess at the appropriate transformation and try it.
Repeat until you are satisfied with the diagnostics meeting the model assumptions.
Below, briefly outline what you did (no need to show all the output)
by (1) identifying what you observed in the diagostics
and (2) the strategy you took to address that issue.
Finally, show the final model and the diagnostics for that.
Describe how the final model is different from the original;
in particular discuss whether variables retained are different from backward selection
and whether the sign and magnitude of the regression coefficients are much different.
```
# In plots, R uses the row label as the "Obs. number"
# Thus, you need to remove observations by their row name, rather than row number.
# (A row's name doesn't change when a lower row is removed.)
# Below is an example of how to do that.
# remove influential observations
psa.sub <- psa
psa.sub <- psa.sub[-which(rownames(psa.sub) %in% c( [Obs. number here] )),]
psa.sub <- psa.sub[-which(rownames(psa.sub) %in% c( [Obs. number here] )),]
```
### Solution
[answer]
## __(0 p)__ 3D plot
You may want to use the 3D visualization for your original final model and
after making some decisions based on diagnostics.
Are you convinced it's a reasonable summary of the general relationship?
```{R}
## visualize in 3D with surface
# library(rgl)
# library(car)
# scatter3d(y ~ x1 + x2, data = dat)
```
## __(1 p)__ Predictive ability of the final model
What proportion of variation in the response does the model explain over the mean of the response?
(This quantity indicates how precisely this model will predict new observations.)
### Solution
[answer]
## __(2 p)__ Interpret the final model
Write the equation for the final model and interpret each model coefficient.
### Solution
[answer]
## __(1 p)__ Inference to whom
To which population of people does this model make inference to?
Go back to the abstract of the original study (first sentence) to see which
population this sample of men was drawn from.
### Solution
[answer]