Introduction to Sweave
and (maybe) odfWeave
Sarah R. Haile
University of Zurich
Institute for Social and Preventive Medicine
Biostatistics Unit
February 5, 2008
Overview
What is Sweave?
What about odfWeave?
A
Sweave = LTEX+ R
Why would we want to do that?
S6880 #6
Random Number Generation #2: Testing RNGs
Theoretical Tests
no realizations of the generator needed, decide whether the
period is large enough. Use spectral test. It requires the
assumption that the generator is of full period. The method
compare
S6880 #5
Random Number Generation #1: Generate Uniform
Random Number
General Formula
xi (xi 1 + c ) ( mod m), i = 1, 2, 3,
where xi , , c , m are integers, 0 xi < m. Start out at x0
(random seed).
xi
Then ui =
: U [0, 1)
m
It is called mixed-congruential
S6880 #4
Numerical Computation
Machine-Representable Numbers
Suppose base is (usually 2) then
di i e , where
r =
i =1
d1 = 0, 0 di 1, i , and m e M (m and M are (nite)
integers). Note: not all r R are considered.
Approximation Equation
Machine representab
Matrix Algebra in R
William Revelle
Northwestern University
January 24, 2007
Prepared as part of a course on Latent Variable Modeling, Winter, 2007
and as a supplement to the Guide to R for psychologists.
email comments to: [email protected]
A Matr
Stat1600
Solution to Midterm Take-Home Exam
Problem #16 Give explicit equations for the p.d.f.s of all components in the Marsaglias normal generator when a = 0.5, r = 4. In addition, specify pi s for these components.
Denote F the c.d.f. of the half norma
1
MATLAB R / R Reference
July 14, 2011
David Hiebeler
Dept. of Mathematics and Statistics
University of Maine
Orono, ME 04469-5752
http:/www.math.umaine.edu/~hiebeler
I wrote the rst version of this reference during Spring 2007, as I learned R while teach
Introduction
Examples
Packages
A
The Joys of LTEX
A 45 minute lecture, with examples, introducing the worlds
standard typesetting language.
Vadim Ponomarenko
Department of Mathematics and Statistics
San Diego State University
June 22, 2009
http:/www-rohan
S6880 #7
Generate Non-uniform Random Number #1
Inverse CDF
F (X ) U (0, 1) if X is continuous. That is, for continuous r.v. X ,
X = F 1 (U ). In general,
dene F 1 (u ) = mincfw_x : F (x ) u ,
then
X F 1 (U ) for U U (0, 1).
Exponential
X E () where = E (X
S6880 #8
Generate Non-uniform Random Number #2
Marsaglias Method for Generating Normal r.v.s
rectangle-wedge-tail
First note that x N (0, 1) can be
generated by generating x from a half
normal and assigning a random sign
to it. That is, need only to gener
S6880 #16
Introduction to Resampling Procedures
Jackknife and Bootstrap
Introduction
For X F , X1 , . . . , Xn sampled from X . Want to estimate , a
parameter depending on F . = (F ). Examples:
(F ) = mean =
xdF (x ),
(F ) = variance =
x 2 dF (x ) [ xdF (
S6880 #14
Variance Reduction Methods #2: Buffons Needle
Experiment
Buffons Needle Experiment
Original Form
The goal of the experiment is to determine the value of
empirically.
The Buffons needle experiment, in its original form, is to drop a
needle of le
S6880 #13
Variance Reduction Methods
General Techniques
Reduction of simulation cost variance reduction.
General Techniques
1. Importance Sampling
2. Control and antithetic variates
3. Conditioning
4. Use of special features of a problem
A note about hit-
S6880 #11
Sampling from Marginal Densities
Possibility of Direct Generation
Problem: Given a random vector X = (X1 , , Xk )t .
Want: to generate a random variate from its i th
component Xi .
If: components are independent or are normal, then
its straightf
S6880 #12
Monte Carlo (Techniques for) Integration
What is Monte Carlo Method
Use a stochastic model as a mean to study a deterministic
system. Example includes Monte Carlo integretation.
Monte Carlo Integration, an Example
1
1 x 2 dx
A deterministic prob
S6880 #11b
Sampling from Marginal Densities, An Example
An Example
Outline
1
An Example
An ExampleBinomial-Beta-Poisson Model
Hatching Insect Eggs Example in Full Form
(WMU)
S6880 #11b
S6880, Class Notes #11b
2/7
An Example
Binomial-Beta-Poisson Model
Hat
S6880 #10
Sampling Methods
Sampling with Replacement
Want: Select a sample of size n with replacement from
cfw_x1 , x2 , , xN .
Method: Generate discrete uniform from the indices
cfw_1, 2, , N and index these indices.
Algorithm: Generate U1 , , Un U (0,
S6880 #9
Generating Order Statistics
Direct Generation and Sorting
X F (x ), cost = sampling + sorting
Example sorting algorithm: quick sort, need O (n log n)
comparisons.
Inversion Method
Generate U1 , , Un U (0, 1)
Sort U(1) , , U(n)
Inverse X(1) = F 1
RN
Random Numbers
Copyright (C) June 1993, Computational Science Education Project
Remarks
Keywords: Random, pseudorandom, linear congruential, lagged
Fibonacci
1. List of prerequisites:
some exposure to sequences and series, some ability to work in base
Introduction
Examples
Packages
A
The Joys of LTEX
A 45 minute lecture, with examples, introducing the worlds
standard typesetting language.
Vadim Ponomarenko
Department of Mathematics and Statistics
San Diego State University
June 18,2013
http:/www-rohan.
i
i
book 2009/6/8 14:41 page 178 #198
i
178
i
CHAPTER 5. GRAPHICS
A series of powerful add-on packages to create sophisticated graphics are available within
R. These include the grid package [56], the lattice library [74], the ggplot2 library and
the ROCR
1
Problem
Assume that you can generate beta distribution (using R function rbeta), implement Ahrens
and Dieters algorithm for generating binomial random variate by writing an R function.
Test on various values of K and make a recommendation with respect t
Efficient Generation of Logarithmically Distributed Pseudo-Random Variables
Author(s): A. W. Kemp
Source: Journal of the Royal Statistical Society. Series C (Applied Statistics), Vol. 30, No. 3
(1981), pp. 249-253
Published by: Wiley for the Royal Statist
KYBERNETIKA VOLUME 43 (2007), NUMBER 1, PAGES 97 102
A NEW CHARACTERIZATION
OF GEOMETRIC DISTRIBUTION
Sudhansu S. Maiti and Atanu Biswas
A characterization of geometric distribution is given, which is based on the ratio of the
real and imaginary part of t
Beamer 101
Introduction to Beamer
Beamer is a LaTeX class for creating slides for presentations
Steven G. Wicker
Winston Salem, NC
[email protected]
Updated Jan. 25, 2010
SG Wicker
Beamer 101
Beamer 101
How to Get Beamer
You may wish to update to the lates
A Handbook of Statistical Analyses
Using R
Brian S. Everitt and Torsten Hothorn
CHAPTER 6
Logistic Regression and Generalised
Linear Models: Blood Screening,
Womens Role in Society,
and Colonic Polyps
6.1 Introduction
6.2 Logistic Regression and Generalis
Chapter 3
Writing functions in R
3.1
3.1.1
Key ideas
Good programming practice
A program is a set of instructions for a computer to follow. Putting a set of instructions together
in a program means that we do not have to rewrite them every time we want to