Lecture 6:
Load data into R.
Export data from R to a file.
Data structure: character strings/factor/array/data frame/list.
1
Data type: character strings
We have seen objects of numeric mode and logical mode (TRUE/FALSE).
A string of characters is sai
Generating continuous random variables
Outline
1. Inverse CDF method.
2. Rejection method.
1
Inverse CDF method
Suppose that we are given U Unif(0, 1) and want to simulate a continuous rv
1
X with cdf FX . Put Y = FX
(U ) then we have
1
FY (y) = P (Y y) =
Lecture 14
Hypothesis Testing using R
STAT4004
Instructor: Hongxiao Zhu
The Big picture
Use a random sample to learn
something about a larger population.
2
3
Different aspects of learning about a
population
Point Estimation (estimate the population param
Lecture 15
Regression with R
STAT4004
Instructor: Hongxiao Zhu
1
2
3
4
Least Squares Method contd
Suppose there are n data points cfw_(xi, yi), i = 1, ., n.
To find the best linear fit yi = a + b xi, we minimize sum of squared residuals:
Fitted values:
Lecture 10
Descriptive Statistics and Plots,
Empirical pdf and cdf
STAT4004
Instructor: Hongxiao Zhu
Basic terms
Population - an aggregate of subjects (creatures, things, cases and so on). For a given study, a
target population has to be specified: on wh
Generating continuous random variables
Outline
1. More on rejection method
2. special case 1: generating r.v.s from mixture distribution
3. special case 2: convolution method
4. special case 3: make use of relations between random variables.
5. special ca
Lecture
Root-finding and Optimization
STAT4004
Instructor: Hongxiao Zhu
1
The root-finding problem
2
Newton-Raphson Method of Root-finding
3
Animation
The function is shown in blue and the tangent line is in red. We see that xn+1 is a
better approximation
Outline
1. Overview about where we are.
2. Monte Carlo methods.
3. Monte Carlo Integration: motivation
4. Monte Carlo Integration.
5. Importance sampling.
1
Where are we?
2
What is Monte Carlo?
Monte Carlo is an administrative
area of the principality of
Permutation Test
Review of hypothesis testing.
Why permutation test?
What is permutation?
Steps of permutation test.
Example.
Exercise.
1
Example 1. We want to determine whether a new directed reading activities
improved the reading ability (measure
1
Outline: Random numbers
1. Generating random numbers: motivation.
2. Generating U nif (0, 1): congruential generator.
3. Seeding.
4. Generating discrete random variables.
2
What are random numbers?
Most of us already have an intuitive notion of what ra
Coding Examples
STAT4004
Hongxiao Zhu
Coding Example 1: Conways Game of Life
The Game of Life is a cellular-automaton, zero player game,
developed by John Conway in 1970. The game is played on an infinite
grid of square cells, and its evolution is only d
Outline
1. Point estimation methods: maximum likelihood.
2. Confidence intervals.
1
Point Estimation
Point estimation involves the use of sample data to calculate a single value
(known as a statistic) which is to serve as a best guess" or best estimate" o
Lecture 5: for and while.
Preallocation of memory.
Looping with for and program flow.
Looping with while.
Load data into R.
Export data from R to a file.
1
The for loop:
for (x in vector) cfw_
expression_1
.
Here x is a simple variable and vector is
Lecture 7:
Data structure: list.
Programming with functions
1
Examples:
1. Transform the data structure of ufc from data frame to list, using the
species as the list component.
2
Programming with functions
A function has the form
name <- function(argume
Lecture 4: the if statement and others
STAT4004
Instructor: Hongxiao Zhu
Outline
If statement
source()
apply()
Create 3D, or 4D arrays.
2
Programming using if
The if statement has the form
Braces cfw_ are used to group together one or more expressi
Today: Graphics
More on R functions.
Scatter plots, graphic parameters, superimposed plots, math symbol, pdf
output.
Setting graphic parameters, superimposed plots, math symbol, pdf output,
grouped graphs using lattice package, 3D plot.
1
Example
1. Pl
Outline
1. Law of Large Numbers (weak vs. strong).
2. Central Limit Theorem
3. Point estimation methods: method of moments.
1
Population vs. sample mean and variance
Reminder: a random sample cfw_X1 , . . . , Xn is a sequence of i.i.d. random
variables.
Outline
1. Central Limit Theorem
2. Point estimation methods: method of moments.
1
Review
Law of Large Numbers (LLN): When performing the same experiment a large
number of times, the average of the results obtained from a large number of
trials should be
Bootstrap contd
Review bootstrap method.
Why does it work?
Bootstrap estimation of the bias.
Bootstrap for hypothesis testing.
Difference between theoretical method, sampling method and bootstrap.
Pros and cons of bootstrap.
1
Recall: the Bootstrap