# Rejection Sampling for a Beta
x = seq(0,1,0.01)
f = dbeta(x,1,1.3)
plot(x,f,type='l',col=2,lwd=2,cex.lab=1.5,cex.axis=1.5)
Y = runif(100)
Z = runif(100,0,max(f)
Accept = Z < dbeta(Y,1,1.3)
points(Y,Z,col=2*(Accept+1)
abline(h = 0)
# Generating things pr

# Permutation Test - looking at the chick weight data
data(chickwts)
X = chickwts[ chickwts$feed='linseed' | chickwts$feed='soybean',]
x = X[X$feed='linseed',1]
y = X[X$feed='soybean',1]
boxplot(x,y)
t.test(x,y)
# Tunction to calculate the test statistic

data(faithful)
attach(faithful)
# First of all, Kernel Density Estimate
Kernel.Density2 = function(x,X,sigma)cfw_
# x = evaluation point for the density
# X = data set of random numbers to generate the density
# sigma = standard deviation of normal kerne

# Multivariate Optimization
# We'll look at mixture model parameters for a Gaussian mixture model approximation
# to the old faithfull data.
data(faithful)
hist(faithful$eruptions,30,cex.lab=1.5,cex.axis=1.5)
X = faithful$eruptions
fn = function(m1,m2,X)

KK
1
Note: Code is only provided in R for this homework. Solutions for Q1 and Q2 have been
provided by me, Q3 and Q4 by Giles.
Solution for Question 1 is on page 2.
Grading rubric for Question 1 is on page 8.
Solution for Question 2 is on page 9.
Grad

# Random Number Generation
# Congruential Generators
X = rep(0,10000)
X[1] = 3
A = 1664525
B = 1013904223
m = 2^(32)
for(i in 2:10000)cfw_ X[i] = (A*X[i-1]+B)%m
U = X/m
hist(U,cex.lab=1.5,cex.axis=1.5,col=4)
plot(U[2:10000],U[1:9999],col=4,cex.lab=1.5,ce

# Example of using compiled functions in R
A = matrix(rnorm(200*200),200,200)
B = matrix(rnorm(200*200),200,200)
# In R's matrix operations
system.time(cfw_ C = A%*%B )
# Using only for loops
multiply = function(A,B)cfw_
C = matrix(0,nrow(A),ncol(B)
for

"Miss Congeniality"
"Independence Day"
"The Patriot"
"The Day After Tomorrow"
"Pirates of the Caribbean"
"Pretty Woman"
"Forrest Gump"
"The Green Mile"
"Con Air"
"Twister"
"Sweet Home Alabama"
"Pearl Harbor"
"Armageddon"
"The Rock"
"What Women Want"

KK
1
Note: Code is provided in R for this homework. Ze Jin has provided code for Q1, and Giles
has provided the solutions to Q4.
Solution for Question 1 is on page 2.
Grading rubric for Question 1 is on page 8.
Solution for Question 2 is on page 9.
Gr

NadarayaWatson = function(x,X,Y,sigma)cfw_
# x = point to evaluate our estimate.
# X = vector of observation X values
# Y = vector of observation Y values
# sigma = standard deviation of the normal kernel.
# Set up some arrays to hold results
weight

DartBoard = function(x,y)cfw_
# First change to polar co-ordinates
r = sqrt(x^2 + y^2) # Distance from the origin
theta = atan2(x,y) # Angle from y axis in clockwise direction
# (from -pi to pi)
# Now we work out what "slice" we're in. This depe

KK
1
Note: Code is provided in Matlab and R for this homework. Matlab code is heavily
commented while R isnt - but since code is ported over, you can look at the comments in
the Matlab code. Q5 is in R code only, since we will be using Rs runif.
Solution

KK
1
Note: Code is provided in both Matlab and R. Or rather, Matlab code has been ported to
R. The Matlab code is heavily commented, but the R code has relatively few comments.
General comments:
Please save your code in one le
and indent your code as well

BSCB 6520: Statistical Computing
Homework 4
Due: Friday, December 5
All computer code should be produced in R or Matlab and e-mailed to gjh27@cornell.edu (one le
for the entire homework). Responses to other problems may be included in this le (in pseudo-t

BSCB 6520: Statistical Computing
Homework 3
Due: Friday, November 7
All computer code should be produced in R or Matlab and e-mailed to gjh27@cornell.edu (one le
for the entire homework). Responses to other problems may be included in this le (in pseudo-t

BSCB 6520: Statistical Computing
Homework 2
Due: Wednesday, October 15
All computer code should be produced in R or Matlab and e-mailed to gjh27@cornell.edu (one le
for the entire homework). Responses to other problems may be included in this le (in pseud

BSCB 6520: Statistical Computing
Homework 1
Due: Monday, September 21
All computer code should be produced in R or Matlab and e-mailed to gjh27@cornell.edu (one le
for the entire homework). Responses to other problems may be included in this le (in pseudo

The Bootstrap
Rizzo, Chapter 7
BTRY 3520
1 / 34
Generating A Sample Distribution
We have seen how to simulate in order to conduct tests in R.
We can do the same thing for other measures of uncertainty.
Eg: condence intervals:
Simulate according to the mod

BTRY/STSCI 6520: Statistical Computing
MWF 1:25-2:15 Upson 205
Instructor: Giles Hooker, (gjh27@cornell.edu); 1186 Comstock Hall
Office Hours: 2:15 4:15 Wednesdays
Co-requisites: ORIE 6700/STSCI 6730 or equivalents and at least one course in
probability.