• 沒有找到結果。

Statistical Computing

N/A
N/A
Protected

Academic year: 2022

Share "Statistical Computing"

Copied!
2
0
0

加載中.... (立即查看全文)

全文

(1)

Statistical Computing

Homework 1: RNG and Writing R functions Due Date: March 10th, 2004

1. Read p37 to 41 in R-intro.pdf about random number generator and various plots on examining the distribution of a set of data.

2. Read p45 to 48 in R-intro.pdf about “Grouping, loops and conditional execution”

and writing your own function.

3. Write a R program (or other programming language) to implement a uniform random number generator using a multiplicative congruential method with xi+1 = 17xi mod m and m = 213 − 1. Generate 500 numbers for the starting point x0 = 100. (help For the sequence ui = xi/m:

(a) Plot a histogram to display the results. (help(hist))

(b) Calculate the coefficient correlation of the pairs of successive number ui and ui+1. (help(cor)).

(c) Plot the pairs (ui, ui+1) on a 2D plot. (help(plot))

4. Write a program to find the period of a random number generator for a given seed. Use this program to find the period of the sequence generated by xi+1= 7xi

mod 13 and x0 = 19. Find the period if a is changed to 3.

5. Read p69-70 and 78-79 in R-intro.pdf about how to add a graph in terms of

“Low-level plotting commands” to existing plot which is produced by “High- level plotting commands.”

6. Write a program to sample k values from the probability mass function pi = i/55, i = 1, 2, . . . , 10. Plot the histogram of generated values for k = 50, 500 and 5000.

(One plot! Not three plots!)

7. Let a discrete random variable X has a probability mass function pj = P (X = j).

Define a new function

λn = P (X = n | X > n − 1) = pn 1 −Pn−1j=1pj.

The quantities λn, n ≥ 1 are called discrete hazard rates since if we think of X as the lifetime of some item then λn represents the probability that an item has reached the age n will die before n + 1. If we are given the mass function p, we can simulate X. Write a program to simulate X when only λns are given.

For the mass function pj = (0.9)j, first compute the hazard function λn for n = 1, 2, . . . , 100. Then, use these λn’s in your program to simulate 500 values of X. Plot a histogram of these simulated values.

8. Derive and implement a method to generate samples of a Weibull random vari- able whose probability distribution function is given by

F (x) = 1 − exp(−αxβ), 0 < x < ∞.

Run your program to simulate 1000 values of Weibull random variable with α = 1 and β = 0.5.

(2)

9. Write a program that uses the rejection method to sample a random variable having the distribution function:

F (x) =

Z 0

xyexp(−y)dy, 0 ≤ x ≤ 1.

10. Suppose it is easy to generate a random variable from any of the distributions Fi, i = 1, 2, . . . , k. How can we generate a random variable from the distribution:

F (x) =

k

Y

i=1

Fi(x).

Hint: If Xis are random variables with distributions Fis, respectively, then what random variable X has the distribution F ?

2

參考文獻

相關文件

Abstract: Statistical token is a random number generated from statistical token generator which is a non-uniform random number generator, when users use the statistical token as

• To enhance teachers’ knowledge and understanding about the learning and teaching of grammar in context through the use of various e-learning resources in the primary

- Settings used in films are rarely just backgrounds but are integral to creating atmosphere and building narrative within a film. The film maker may either select an already

 Genre – animal stories but even the stories have animals as main characters the contents are actually realistic..  Curious

• To understand how different texts are organised and expressed and apply this understanding to one’s learning and use of the language (KSf, KS3).. • To respond to

• To give expression to imaginative ideas through oral, written and performative means such as rewriting a play into a story or rewriting the ending of a story (ESc, KS3)..

The Seed project, REEL to REAL (R2R): Learning English and Developing 21st Century Skills through Film-making in Key Stage 2, aims to explore ways to use film-making as a means

which can be used (i) to test specific assumptions about the distribution of speed and accuracy in a population of test takers and (ii) to iteratively build a structural