- Details
- Parent Category: Programming Assignments' Solutions

# We Helped With This Statistics with R Programming Homework: Have A Similar One?

Category | Programming |
---|---|

Subject | R | R Studio |

Difficulty | College |

Status | Solved |

More Info | Statistic Help Online |

## Assignment Code

```
---
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.
***********************
```