CSC 121 - Computer Science for Statistics (Jan-Apr 2017)

Small assignment 1 is now posted below.

CSC121 is an introduction to programming aimed at students studying to be statisticians, or who otherwise expect to use statistics extensively in their work. It uses the R language, which is widely used for statistical research and applications. It is meant to be accessible to students with no programming experience. Although it is motivated by statistical applications, no specific knowledge of statistics is required to take this course.

Other options for introductory programming are CSC120, which is meant for general science students, and CSC108, which is meant for students planning on taking further computer science courses, starting with CSC148. Both of these other courses use the Python language. It is possible to take CSC148 and later CS courses after taking CSC121, without taking CSC108, but to do so you will have to pick up some material on your own, so it's better to take CSC108 if you know now that you will be taking later CS courses. You should consult the CS department for advice if you take CSC121 and then discover that you want to take more CS courses.

Instructor: Radford Neal, Office: SS6026A / PT390, Email:

Office hours: Wednesdays 10:30-11:30, in SS6026A.

Lectures and Tutorials/Labs:

Lectures: Tuesdays and Fridays, 1:10-2:00pm, MB128.
Tutorials/Labs: Wednesdays, 1:10-3:00, BA3185 (and nearby rooms).

Labs will start January 11. The lab the first week will be to make sure you know how to log into the computers, start up R using Rstudio, and do simple things in R. If you have a laptop computer, you should bring it, so you can also learn how to install R and Rstudio on it. Later labs will involve non-credit excercises, which will prepare you for assignments, the mid-term test, and the final exam.


15% - Three small assignments (5% each), due at start of lectures on January 31, February 14, and February 28.
20% - Two large assignments (10% each), due at start of lectures on March 17 and April 4.
18% - Mid-term test (50 minutes), written during lecture time on March 3.
47% - Final exam (scheduled by the Faculty).

You must get at least 40% on the final exam to pass the course. If you don't, your final grade will be less than 50 regardless of your other grades in this course.

Assignments will be done by students individually.

Assignments may be handed in late by the date and time specified on the handout with a 20% penalty. Later assignments will not be accepted.

Students with a valid medical or other excuse will of course not be penalized for late assignments, or for missing the mid-term test. You must, however, contact the instructor (eg, by email) as soon as possible (preferrably beforehand) if you are not able to hand in an assignment or write the mid-term test. If you miss the final exam for a valid reason, you should petition the Faculty to write a deferred final exam.

Getting and Using R:

You will use R via Rstudio on the CS teaching computer system, on which you should automatically have an account if you are registered in this course. To start Rstudio, you need to open a terminal window, and then type "rstudio".

You can also install R and Rstudio (for free) on your own laptop or desktop computer. You can download R from, and Rstudio from

The lab in the first week (January 11, 1:10-3:00pm) will help you get started on these things.

Documentation on R:

There is no textbook for this course (lecture slides are below). However, here are links to some on-line documentation on R:

Introduction to R (R Core Team).
R Language Definition (R Core Team).
Introduction to some aspects of R (Chi Yau).
Advanced R (Hadley Wickham).

Lecture Slides:

Slides for the lectures will be posted here as they become available.

Week 1: Introduction, numeric and character data, arithmetic, mathematical functions, string functions (paste and substring), variables and assignment, vectors, c, length, vector arithmetic and subscripting, plotting vectors. The iris demo program is here.

Week 2: R scripts done with source, functions scan, mean, sd, abline, defining functions, multiple steps with curly brackets, input and output with readLines and cat.

Week 3: Using if, for, and while, logical data and comparison operations, sequences with :.

Week 4: Lists, more to come later.

Lab Exercises:

January 11: Logging in to the CS teaching computers, and then starting up R. Installing R and RStudio on your laptop (if you bring one). Simple operations in R.
January 18: handout.


Small Assignment 1: handout, tests (you must add your own tests to these).

Web pages for previous versions of this course:

This course was previously taught as a special section of CSC120. Here are the web pages for past versions.

Spring 2016
Spring 2015