Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
STAT2009 2013/14 Term 1
Introduction to Programming Language for Statistics
Lecturer: Dr. P.L. Leung
Tutors: Hui Tsz Shing
Office: Lady Shaw 115
Office: LSB G32
Time / Venue: M6 /LT2; H89 / LT5
This course introduces the basic knowledge of using the stat
Introduction to Programming Language for Statistics
STAT 2009

Fall 2015
~ 1
~
X&;fiPlT:1f ~ 1H~ fp
Copyright Reserved
*
~
*
Ji ( # 5 Ji ) Page 1 of 5
The Chinese University of Hong Kong
Course Examinations 201213
Course Code & Title :#
.~1iJtlt.~ ~:
Time allowed 8~ M:
Student LD. No.
2

iflift
~til:.
term
STAT2009 I
Introduction to Programming Language for Statistics
STAT 2009

Fall 2015
Jf; 1 Jcfw_ ( # 4 Jcfw_ ) Page 1 of 4
J!.&Ai PIT :t + HflwJ fp
Copyright Reserved
l'
~
tf
.5c
;k
~
The Chinese University of Hong Kong
Course Examinations 201112
Course Code & Title *4 El
Time allowed
Student I.D. No.
.!'~t.&.~ ~#:
B~ M:
*!t.~t:
2
if
Introduction to Programming Language for Statistics
STAT 2009

Fall 2015
~
1 Jl ( # 4 Jl ) Page 1 of 4
x&';fjFfj"~ /j:~ili~P
Copyright Reserved
~
~
tf
x. A
~
The Chinese University of Hong Kong
Course Examinations 201314 if'Ji# EI ;i/ft~
Course Code & Title *4 El
.~.&.t
cfw_it: STAT2009 Introduction to programming languag
Introduction to Programming Language for Statistics
STAT 2009

Fall 2016
STAT2009
2016/17
1st term
Assignment 2
Q1.
The file flag.csv contains color of flag and some background information of 191 countries.
Column Name:
Attribute Information
1.
Country Name of the country concerned
2.
Landmass 1=N.America, 2=S.America, 3=Europ
Introduction to Programming Language for Statistics
STAT 2009

Fall 2016
Chapter 3
Statistical Graphics
R can produce professional statistical graphics easily. It has extensive graphical
procedures with many options. Note that some options in Rs graphics are very
complicate and involved. Here we only discuss some simple and co
Introduction to Programming Language for Statistics
STAT 2009

Fall 2016
STA 2009
Assignment 1
1st term 2016/17
A stick is of 1 meter long. Two points are randomly chosen to cut the stick into three pieces. We are
going to perform a simulation to estimate the probability that a triangle can be formed by these three
sticks. Not
Introduction to Programming Language for Statistics
STAT 2009

Fall 2016
Chapter 1
A Brief Introduction to R
1.1 A Brief History of R and SPLUS
The development of computer has great impact on every aspects of our daily life. In
statistics, computer has great impact on the statistical methodology as well. Many
newly developed
Introduction to Programming Language for Statistics
STAT 2009

Fall 2016
Midterm Review
=
Question 1 [40%]
(a) Write R codes to simulate the random walk: xi+1=xi+ri for t=0,1,100,
where x0=100, ri are i.i.d with and Prcfw_rt=10=0.6 and Prcfw_rt=10=0.4 save
them in wx.
x<sample(c(10,10),size=101,prob=c(0.6,0.4),replace=T)
x
Introduction to Programming Language for Statistics
STAT 2009

Fall 2016
Chapter 4
Programming in R
In previous chapters, we have introduced many useful builtin functions in R. In
addition, we can write our own user defined function. The ability of writing user
defined function is very important for researcher. Actually, R ca
Introduction to Programming Language for Statistics
STAT 2009

Spring 2014
A summary of the special distributions discussed:
For discrete distributions, we have learnt Binomial distribution, Hypergeometric
distribution, Poisson distribution, Geometric distribution, Negative Binomial distribution.
For continuous distributions, we
Introduction to Programming Language for Statistics
STAT 2009

Spring 2014
STAT 2004 SAS for Data Management
Laboratory Exercise 1 answers (Introduction to SAS)
2, Correct program:
DATA ACCOUNT2; /*The following program store the savings of 4 persons*/
INPUT term cd passbook;
CARDS;
1000 12000 350
500
.
1000
.
.
500
1400 5000
.
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
Midterm test: Oct 24, 3:45 pm to 5:00 pm at LSB LT5
Please bring a scientific calculator to the midterm test
Useful R syntax given in the midterm question paper
Name
+  * / %
^ &  !
ceiling(x)
floor(x)
trunc(x)
round(x)
sqrt(x), abs(x)
sort(x)
sum(x)
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
Chapter 1
A Brief Introduction to R
1.1 A Brief History of R and SPLUS
The development of computer has great impact on every aspects of our daily life. In
statistics, computer has great impact on the statistical methodology as well. Many
newly developed
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
Chapter 2
Simulation and Interactive Data Analysis
One of the major applications of computer in Statistics is simulation. Simulation
becomes an inevitable tool in statistics nowadays. It can be used in testing and
assessing our statistical methodologies.
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
Chapter 4
Matrix Theory
Matrix is important in Mathematics as well as in Statistics. We have seen that data can
be represented by a matrix with row as observation and column as variable. It is a
necessary tool for multivariate statistical analysis which s
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
Chapter 3
Statistical Graphics
R can produce professional statistical graphics easily. It has extensive graphical
procedures with many options. Note that some options in Rs graphics are very
complicate and involved. Here we only discuss some simple and co
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
Chapter 5
Programming in R
In previous chapters, we have introduced many useful builtin functions in R. In
addition, we can write our own user defined function. The ability of writing user
defined function is very important for researcher. Actually, R ca
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
Chapter 6
Database Manipulation
We have demonstrated how to select a subset from a data set according to some
specific criteria in previous chapters. In this chapter, a more formal and systematic
introduction of database manipulation is given. In business
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
Chapter 7
Advanced Graphics and Numerical Methods
We have seen graphs and functions plotted using R. Actually there are many more
statistical graphs such as pie charts, bar charts, dot plots and function plotting in R.
We will discuss how to produce these
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
STA 4006: Categorical Data Analysis
Exercise 5
Academic year 07/08, first term, Chapter 5
1. Refer to the model, logit() = + 1 c1 + 2 c2 + 3 c3 + 4 x, in Horseshoe Crab example
(please download the data set on WebCT).
(a) Fit the model using x = weight. I
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
STA 4006: Categorical Data Analysis
Exercise 4
Academic year 07/08, first term, Chapter 4
1.
a. Describe the purpose of the link function of a GLM.
b. Define the logit link, and explain why it is often used with binomial data.
c. Define the log link, and
Introduction to Programming Language for Statistics
STAT 2009

Fall 2014
STA 4006: Categorical Data Analysis
Exercise 6
Academic year 07/08, first term, Chapter 6
1. The following table refers to automobile accident records in Florida in 1988.
Safety Equipment Whether
Injury
in Use
Ejected
Nonfatal
Fatal
Seat belt
Yes
No
1,105
Introduction to Programming Language for Statistics
STAT 2009

Spring 2014
~
1 Jf ( #
t
Jf ) Page 1 of It
X&Att PIT 1f ;f: 1~ ~fI fp
Copyright Reserved
W~tfXA*
The Chinese University of Hong Kong
1st term
Course Examinations 201415 if/i;n El :4fti\
Course Code & Title # El
.~'5t&.t cfw_~:
Timeallowed s;fM:
Student LD. No.
2
(J