---
title: "STT 301 Homework Assignment 1"
author: "Shawn Santo"
date: "September 10, 2018"
output:
html_document: default
---
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(comment = NA)
```
***********************
### Homework Assignment 1 is due Wednesday, September 19 at 12:40pm EST.
***********************
### Instructions
You must complete this individual homework assignment using R Markdown.
You may modify this file. Submit the R Markdown file, which should have
a `.Rmd` extension, and the resulting HTML output file, which should
have an `.html` extension, via the dropbox on D2L.
Some of the questions are open-ended, and there is not a correct or incorrect
answer. Written responses to questions should be incisive.
### Rubric
- **Total**: 10 points.
- **Correctness**: Point values for the question and their respective parts
are listed. Partial credit is available.
- **Knitting**: Deduction of 0.5 points if the Rmd file does not knit for
any reason.
- **Style**: Use a third-level header to off-set each question in your
solutions - as is done below. For questions with multiple parts, use
fourth-level headers to off-set the parts in your solutions - as is done
below. Coding style is very important. You will receive a deduction of up
to 1.0 point if you do not adhere to good coding style. What I am looking for
in terms of style includes:
- appropriate variable use and naming
- appropriate function use
- good code commenting
- consistent code syntax style
- **Late Submission**: Late homework will not be accepted.
*Please do not include the above Rubric, Instructions, and homework deadline*
*sections in your solutions.*
***********************
### Question 1 (3 points)
This question focuses on some basic manipulations of vectors in R.
#### Part a (1 point)
Create four vectors in R: one called `nums` which contains the integers
from 5 through 14; one called `charnums` which contains character representations
of the numbers 1 through 4, namely, "1", "2", "3", "4"; one called
`mixed` which contains the same values as in `charnums`, but which also
contains the letters "a" and "b"; and one called `bool` which contains the
logical values TRUE, TRUE, TRUE, FALSE, FALSE, TRUE.
#### Part b (1 point)
i. Convert `nums` to character.
ii. Convert `charnums` to numeric.
iii. Investigate what happens when you convert `mixed` to numeric.
iv. Investigate what happens when you covert `bool` to character and then
when you convert the character result of `bool` to numeric.
Comment on each of these conversions below the `R` chunk.
#### Part c (1 point)
i. Extract the first element of `bool`.
ii. Extract the last element of `nums.` You should give
code which would work regardless of the number of elements in `nums`.
iii. Extract all but the first element of `nums.`
iv. Extract all but the first two and last two elements of `nums.`
Again, give code that would work regardless of how many elements
`nums` contains.
***********************
### Question 2 (4 points)
For this question you will work with data from the 2016-2017 NBA season.
The `R` chunk below gives the code to read in the data. Use the `nba` data frame
for the questions that follow. If you are unfamiliar with basketball terminology,
most of the definitions for the variables can be found at [Basketball Reference](https://www.basketball-reference.com/about/glossary.html).
The first time you knit the .Rmd file it will be slow. The chunk option
`cache=TRUE` will speed up the knit time after the initial knit.
```{r cache=TRUE}
# read in the data
nba_raw <- read.csv("http://users.stat.ufl.edu/~winner/data/nba_player_201617.csv",
stringsAsFactors = FALSE)
# remove the last column
nba <- nba_raw[, -31]
```
#### Part a (1 point)
Create a data frame containing all the variables
for a player of your choice. Save the data frame using the
player's last name. You may want to use the `subset` function.
#### Part b (2 points)
Compute the mean, standard deviation, and median for any three variables
corresponding to the player you selected in the previous part. To extract a
single variable you can use `[ , ]` or `$`. For example, if my data frame was
`westbrook`, `westbrook$PTS` would provide me the points vector from the
`westbrook` data frame.
#### Part c (1 point)
Compute the correlation between `Minutes` and `PTS` for the player you selected,
and plot the two variables. `Minutes` should be on the x-axis, and `PTS`
should be on the y-axis. If you want to tidy your plot a bit include
`xlab = "Minutes", ylab = "Points"` inside the plot function. Look at the help
if you want to see how to change colors or points.
***********************
### Question 3 (3 points)
For this question you will work with the `nba` data frame created in question 2.
Select two players. For each player, compute their field goal percentage and
effective field goal percentage for all their games played. Use at least two
descriptive statistics to determine which player had the better field
goal percentage, and which player had the better effective field goal
percentage for the 2016-2017 NBA season. Your answer should include
an explanation.
Field Goal Percentage; the formula is `FG / FGA`.
Effective Field Goal Percentage; the formula is `(FG + 0.5 * X3P) / FGA`. This
statistic adjusts for the fact that a 3-point field goal is worth one more
point than a 2-point field goal. For example, suppose Player A goes 4 for 10
with 2 threes, while Player B goes 5 for 10 with 0 threes. Each player would
have 10 points from field goals, and each would have the same effective field
goal percentage (50%).
***********************
### Student Feedback
This part is optional. It will be available on all assignments.
Feel free to answer on all, some, or none.
1. How is the course going for you in terms of pace and/or difficulty level?
2. Do you have any concerns or suggestions?
3. Please provide any other comments you may have.
***********************
Frequently Asked Questions
Is it free to get my assignment evaluated?
Yes. No hidden fees. You pay for the solution only, and all the explanations about how to run it are included in the price. It takes up to 24 hours to get a quote from an expert. In some cases, we can help you faster if an expert is available, but you should always order in advance to avoid the risks. You can place a new order here.
How much does it cost?
The cost depends on many factors: how far away the deadline is, how hard/big the task is, if it is code only or a report, etc. We try to give rough estimates here, but it is just for orientation (in USD):
Regular homework
$20 - $150
Advanced homework
$100 - $300
Group project or a report
$200 - $500
Mid-term or final project
$200 - $800
Live exam help
$100 - $300
Full thesis
$1000 - $3000
How do I pay?
Credit card or PayPal. You don't need to create/have a Payal account in order to pay by a credit card. Paypal offers you "buyer's protection" in case of any issues.
Why do I need to pay in advance?
We have no way to request money after we send you the solution. PayPal works as a middleman, which protects you in case of any disputes, so you should feel safe paying using PayPal.
Do you do essays?
No, unless it is a data analysis essay or report. This is because essays are very personal and it is easy to see when they are written by another person. This is not the case with math and programming.
Why there are no discounts?
It is because we don't want to lie - in such services no discount can be set in advance because we set the price knowing that there is a discount. For example, if we wanted to ask for $100, we could tell that the price is $200 and because you are special, we can do a 50% discount. It is the way all scam websites operate. We set honest prices instead, so there is no need for fake discounts.
Do you do live tutoring?
No, it is simply not how we operate. How often do you meet a great programmer who is also a great speaker? Rarely. It is why we encourage our experts to write down explanations instead of having a live call. It is often enough to get you started - analyzing and running the solutions is a big part of learning.
What happens if I am not satisfied with the solution?
Another expert will review the task, and if your claim is reasonable - we refund the payment and often block the freelancer from our platform. Because we are so harsh with our experts - the ones working with us are very trustworthy to deliver high-quality assignment solutions on time.