Statistics 740 - Statistical Computing
- accov1 and
accov2 (1/12/04) - R code to calculate the average conditional covariance for 0-1
data. You can either cut and paste it into R or use
to load the two functions and the data set in. accov2(a1291) will
run the efficient version.
- accov.for (1/14/04) -
Fortran code to calculate average conditional covariance for 0-1 data. Save it
in the c:\MinGW\Programs directory. Choose Run under the Start menu
in windows, and type in command or cmd. This will bring up a dos window.
and then cd \MinGW\Programs. You can then compile the program using
g77 accov.for -o accov.exe
and run it simply by typing
This is the a1291 data set you can use to check the above code on.
To use with fortran, save it in the Programs subdirectory of the
MinGW directory on the C drive. The code
to read it into R is in between accov1 and accov2 in that file.
chartoint.for (Hmwk 1) -
This file contains a program demonstrating the chartoint subroutine.
This subroutine is designed to prompt the user for an integer in a certain
(positive) range, and to keep re-asking if they don't enter an appropriate
These are the three computer arithmetic example programs from in class.
The first program count demonstrates that integers wrap around when
the maximum or minimum possible value is met. This example is for
INTEGER*1 variables. count2 and count3 demonstrate
that the order floating point numbers are added can make a difference when the
magnitudes differ greatly. Note that in count2 we need to add
the decimal place after the 1 in (1/i) so that it doesn't
do integer division. Note that if I wanted to just have the computer give
a certain sum or product I could remove the loop entirely and just use
notation like sum=24*15+115 and write(*,*) sum.
randu (2/4/04) -
An incautious implementation of the inadequate randu random number generator
for R, along with the code to help demonstrate one of its inadequacies.
newrt (2/6/04) -
Generates a single random number from a t-distribution using
the accept-reject method and g(x)=1/4*min(1,1/x^2).
Fleishman's Power Method (2/9/04) -
Contains the code for generating pseudo-random variables with
specified first four moments as per:
Fleishman, A.I. (1978). A method
for simulating non-normal distributions. Psychometrika, 43,
The function sandk will calculate the first four moments for
the entered data set. The function rfleish will generate the
random variables. The other two functions are called by rfleish.
Try: x<-rfleish(200000,1,1.5,2,18) and sandk(x) .
h2.for (Hmwk 2) - Some code to demonstrate calling a function and writing out to a file.
You can use the read.table command to read the output file into R,
rbootmedci (2/16/04) -
Contains code for performing a naive bootstrap confidence interval for the
stbmedci (2/20/04) -
Contains the code for calculating the basic bootstrap confidence interval for
the median and for performing the studentized bootstrap confidence interval
(with the naive variance estimate).
h3.txt (Hmwk 3 Solutions) - Contains R code for counting the number of rejections in the accept
reject method for generating t random variables. Also contains R code for
simulating multivariate normals given the correlation matrix instead of the
bcaboots (2/23/04) -
Contains the code (with some extra comments) for calculating the accelerated bias-corrected bootstrap confidence interval for the median and performing a brief simulation study.
regresboot and regptsboot (2/25/04) -
Contains the code for estimating confidence intervals for the slope in simple
linear regression using either resampling from the residuals or resampling
from the data points. The percentile method is used.
jack.txt (2/27/04) -
A small piece of code to demonstrate why the jackknife distribution needs to
be multiplied by sqrt(n-1).
bisect and Newton (3/5/04) -
Functions to perform the univariate bisection method and Newton's method for
finding roots of equations. Accompanied with the extra code needed
to find the mle of the
shape parameter for the gamma distribution.
Algorithm (3/24/04) -
An implementation of the Nelder-Mead optimization algorithm with no safe-guards.
It will plot the successive triangles for a two-dimensional problem.
R's built in optimization (3/26/04) -
An example of using R's built in functions for optimization and constrained
optimization (optim and constrOptim).
EM widows (4/2/04) -
Examining Thisted's data concerning the number of children widows have by
finding both the MLE for the observed data distribution and by using the
Metropolis-Hastings Example (4/23/04) -
Using Metropolis-Hastings to examine the posterior of a Cauchy location
parameter using a normal prior.
Gibbs Sampler Example (4/28/04) -
Using a Gibbs sampler to simulate data from a bivariate normal distribution
with mean vector (0,0), standard deviation vector (1,1), and correlation 0.9.
Integration Code for Final (Final) -
Numerical integration to find P(X1 < a,X2 < b) for a bivariate normal
distribution with mean vector (0,0), standard deviation vector (1,1), and
correlation rho. intfun uses a two dimensional version of the
midpoint method with a sqnp by sqnp grid of points. intfun2
uses the adapt library to estimate the same value.