Practice Exam

Week15
Exam
Week15
Author

Your Name

Published

2024-05-08

You can download all of the files needed for this exam here.

Instructions

  • This exam is due at 3pm on May 16, 2023 (the end of the final exam period for this class). Your exam MUST BE PUSHED TO GITHUB CLASSROOM by 3pm. Please double-check your github repository to ensure that the file that is on github is the file you want me to grade.

  • For each of these problems, you may choose to solve the problem in either R or python.
    The chunks I’ve provided are R chunks, but you are free to change the code type to python; I just want to ensure that your answers are where I expect them to be.

  • The exam is worth a total of 40 points. There are 4 bonus points available.

Rules

  • You may use the textbook, your notes, and google on this exam, but you may not post this exam and ask for help on any site.
    It is ok to google, for instance, how to convert a string to a list of characters, but it is not ok to google how to solve the entire question. Please ask if you are concerned about any possible edge cases.

  • You may NOT confer with other people or AI entities - including posting on StackOverflow, Reddit, etc.

  • You must be able to explain how any code you submit on this exam works.

  • You may ask clarifying questions of Dr. Vanderplas by email/zoom or in person

  • (5 points) Your submitted qmd file must compile without errors .
    Use error=TRUE in a chunk if it is supposed to return an error (for instance, if you are demonstrating error handling).

Scrabble!

Here are the point values for each letter in Scrabble.

  • 0 Points - Blank tile.
  • 1 Point - A, E, I, L, N, O, R, S, T and U.
  • 2 Points - D and G.
  • 3 Points - B, C, M and P.
  • 4 Points - F, H, V, W and Y.
  • 5 Points - K.
  • 8 Points - J and X.
  • 10 Points - Q and Z.

Part 1: Read in and Clean the Data

(5 points + 2 bonus)

  1. (2 points) Read in the file scrabble_points.csv and store it in a variable named points.
  1. (3 points) What steps do you need to take to get this data into tidy form? Describe the operations, even if you do not know how to perform them yet.
  • … add more as necessary
  1. (2 bonus points) Write code to get your data into tidy form, if you can.
    Hint: you may find the function unnest() (R) or df.explode() (Python) useful here.

Part 2: Functions

(12 points + 2 bonus)

For this part, you may find it useful to use the provided file clean_points.csv, which contains the same information as scrabble_points.csv, but in tidy form.

  1. (4 points) Write a function named scrabble_score(x) which will take a word as an argument and determine the point value of that word. Assume that the blank tile is indicated by _.
scrabble_score("YOU") # Should return 6 (4 + 1 + 1)
## Error in scrabble_score("YOU"): could not find function "scrabble_score"
scrabble_score("R_CK") # Should return 9 (1 + 0 + 3 + 5)
## Error in scrabble_score("R_CK"): could not find function "scrabble_score"
  1. (2 points) Modify the function you wrote above so that it checks that the input is a string. That is, if someone calls scrabble_score(3), your function should provide an appropriate error.
scrabble_score(3)
## Error in scrabble_score(3): could not find function "scrabble_score"
  1. (2 points) Modify your function so that it accepts lower-case and upper-case input and treats both the same.
scrabble_score("AWESOME") == scrabble_score("awEsOme")
## Error in scrabble_score("AWESOME"): could not find function "scrabble_score"
  1. (4 points) Modify your function so that it:

    • provides an appropriate warning if the provided string contains a character which is not valid
    • removes any invalid characters from the string before calculating the score
scrabble_score("GOOD LUCK!")
## Error in scrabble_score("GOOD LUCK!"): could not find function "scrabble_score"
  1. (2 bonus) Make your function vectorized, so that you can handle either single characters or a vector of character input.
scrabble_score(c("You", "can", "do", "this"))
## Error in scrabble_score(c("You", "can", "do", "this")): could not find function "scrabble_score"

Part 3: Scoring

(18 points)

  1. (3 points) Create a data frame named scrabble with a column named word containing the words in the file words.txt.
  1. (6 points) Add a column, score, to scrabble containing the word score and add another column, length, with the word length.
  1. (3 points) Plot word length and word score in an appropriate plot (geom_jitter may be helpful). Make sure your plot has an appropriate title and axis labels. Include any annotations (trend lines, etc.) that you think are helpful for emphasizing important features of the data. If you had trouble with the previous parts, you may use length_score_graph.csv to complete this part.
  1. (3 points) Describe the plot’s main features in 2-3 sentences.

  2. (3 points) What challenges would you face if you plot the score of all 279,498 valid scrabble words in Collins Scrabble Words (2019).txt? What modifications would you consider making to your plot?
    You do not have to actually plot this additional data, but you may want to try it to see what the problems are.