STA/OPR 9750 - Week 3 Update

Michael Weylandt

STA/OPR 9750 Mini-Project #00

  • MP#00 submitted
    • A few of you didn’t submit; I’ll follow up directly for VoE
  • MP#00 peer feedback assignments released (check GitHub)
    • Give some feedback to your peers
    • Get ideas for improving your own site

STA/OPR 9750 Mini-Project #01

  • MP#01 released
  • Start early
    • Not too hard if everything is working (post-MP#00)
    • Tech support takes time

Graduate Teaching Assistant (GTA)

  • Charles Ramirez
  • Twice Weekly Office Hours (Zoom)
    • Tuesdays 4-5pm
    • Fridays 12-1pm
  • Will also help coordinate peer feedback (GitHub), Piazza responses, etc.
  • Excellent resource for course project advice!

Piazza Participation

  • Average time to response <9 hours
  • 209 posts

Thanks to those of you who are helping classmates!

Course Project

  • 1 team already registered with me!
  • Piazza discussions helping to coordinate other teams

Upcoming Week

Next Wednesday at 11:45pm:

  • Next Pre-Assignment
  • MP#00 Peer Feedback due

Pre-Assignment #03 FAQs

FAQ: Vector Index Printout Rules

Default vector printing:

1:10
 [1]  1  2  3  4  5  6  7  8  9 10

Each line gets a new index:

sqrt(1:10)
 [1] 1.000000 1.414214 1.732051 2.000000 2.236068 2.449490 2.645751 2.828427
 [9] 3.000000 3.162278

More complex objects have alternate print styles:

matrix(1:9, nrow=3, ncol=3)
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9

Print width is controlled by getOption("width").

FAQ: Recycling Rules

Alignment by default:

x <- 1:3
y <- 4:6
x + y
[1] 5 7 9

Recycling by default:

x <- 1
y <- 4:6
x + y
[1] 5 6 7

Recycle warning when vectors don’t fit together cleanly:

x <- 1:2
y <- 4:6
x + y
Warning in x + y: longer object length is not a multiple of shorter object
length
[1] 5 7 7

FAQ: Recycling Warning

x <- 1:2
y <- 4:6
x + y
Warning in x + y: longer object length is not a multiple of shorter object
length
[1] 5 7 7

Not a problem per se, but often a sign that something has gone wrong.

  • scalar + vector is usually safe
  • 2 vectors of same size is usually safe
  • vectors of different size is usually a programming mistake

FAQ: Warnings vs Errors

  • Warnings: heuristics pointing at typical problem
    • Code still executed without a problem
    • Try to fix these unless you’re certain it’s not a problem
  • Errors: code failed to execute
    • You have to fix these to run your code

FAQ: Changing built-in functions

Most built-in functions can’t / shouldn’t be changed.

Some allow alternate behavior via additional arguments:

log(10) # Default is natural (base e) logarithm
[1] 2.302585
log(10, base=10)
[1] 1

If you want different behavior, write your own function:

cosd <- function(x){
    ## Cosine in degrees
    cos(x * pi / 180)
}
cosd(90)
[1] 6.123234e-17

Always try ?name to see documentation.

FAQ: Git Workflow

Three key commands:

  • git add: add some changes to a ‘box’
  • git commit: seal the ‘box’
  • git push: send the ‘box’ to GitHub

Git pane in RStudio shows uncommited changes, not files.

If a file ‘vanishes’ after a commit, that’s good!