Please complete before the next class.

Make sure that you’ve completed all previous HW first.

R

See the previous HW if you haven’t got RStudio working on your computer yet.

If you missed class or need a refresher, this video duplicates the notes below and material we covered in class.

Read and review your notes and my notes over the basics of computing with R. Answer the review questions throughout the document. Write an R script that contains the code and answers as comments. (See the misc. exercise below.) I didn’t quite finish going through these notes in class, so we’ll finish them next time. But feel free to use the notes and video above to “work ahead.” These basics are a REALY important foundation.

• This is a tedious assignment–you’ll need to work carefully. I suggest spreading the exercise over several different sessions to give you time to digest the ideas. Don’t rush it. These ideas are not particularly difficult, but they require you to work slowly and carefully.
• I try to write exam questions so that students who can do the review exercises will answer correctly and quickly (and that others will answer incorrectly and/or slowly).
• When you can’t get your code to work, it’s usually just a missing parenthesis, missing quotation mark, or something like that. It’s not that you’re making a huge mistake. Huamns can sitll mkae snese wehn tehre are tpyos, but not computers! Check your code for typos carefully. Run your script one line at a time, from top to bottom, to find mistakes. As examples, most mistakes are like the following:
b <- c("Male", "Female)  # missing the second " after "Female"
exp(23  # forgot to close a parentheses
log(10 base = 2)  # missing comma between arguments

a <- c(1, 2, 3)
mean(A)  # R is case-sensitive--there's an object "a", but no object "A"
mena(a)  # misspelled function name
Mean(a)  # R is case-senstive

Here’s a debug procedure if you run into errors.

1. Clear your workspace by running the command rm(list = ls()) (or clicking the broom in the “Environment” tab in the top-right panel). This deletes all the previous objects you created, but you can easily re-create them by running your script.
2. Start with the first line on your script and run each line. Run each line one-at-a-time by pressing Cmd + return (or control + enter on Windows; or clicking the “Run” button).
3. When you encounter the line that generates the error, stop. Check that line carefully for typos. It’s almost always a small, “obvious” mistake.

Lastly, a comment about seeking advice from the web: In general, being able to find solutions on the internet is a valuable skill. But you must realize that R programming is complex. There are many approaches to the same problems. The solution suggested by the internet might not mesh with my overall approach. So as best you are able, I encourage you to rely on my notes. I’ve developed them over the years and continue to make changes (improvements, hopefully). They should give you everything you need for the course. If you are stuck, I encourage you to ask me for help (). Classmates usually have helpful insights, as well.

Misc. Exercise (1 pt.)

Write an R script that completes the exercises from my notes. Any written responses should be in the form of a comment (i.e., preceded by a #). It’s really important that this script not generate any errors. To check, please follow the three steps above and make sure that the code runs top-to-bottom without generating an error. If your generates an error, then it will not compile using the steps below.

Once you are satisfied with work, click the tiny notebook icon (to the left of the Run button). When prompted, select PDF (PDF tends to work better, in my experience) or MS Word. You may be prompted to download the document–do it! If not, then select the Files tab in the lower-right, check the box for the document you want to download (it should be analysis.docx or analysis.pdf), and click More > Export…, and follow the instructions Submit this .docx or .pdf file to Canvas. Do not submit the .R script itself.

Carlisle Rainey