Statistics project

profilecsht
ALY6050_Project1Document_4columnrubric2.pdf

Chi-squared Goodness of Fit Test Project

Overview and Rationale

This assignment is designed to provide you with hands-on experience in generating random values and performing statistical analysis on those values.

Course Outcomes

This assignment is directly linked to the following key learning outcomes from the course syllabus:

• Use descriptive, Heuristic and prescriptive analysis to drive business strategies and actions

Assignment Summary

Follow the instructions in this project document to generate a number of different random values using random number generation algorithm in Excel, the Inverse Transform. Then apply the Chi-squared Goodness of Fit test to verify whether their generated values belong to a particular probability distribution. Finally, complete a report summarizing the results in your Excel workbook. Submit both the report and the Excel workbook.

The Excel workbook contains all statistical work. The report should explain the experiments and their respective conclusions, and additional information as indicated in each problem. Be sure to include all your findings along with important statistical issues.

Format & Guidelines

The report should follow the following format:

(i) Introduction

(ii) Analysis

(iii) Conclusion

And be 1000 - 1200 words in length and presented in the APA format

Project Instructions:

The project consists of 4 problems and a summary set of questions. For each problem, tom hints and theoretical background is provided.

Complete each section in a separate worksheet of the same workbook (Excel file). Name your Excel workbook as follows:

ALY6050-Module 1 Project – Your Last Name – First Initial.xlsx

In the following set of problems, r is the standard uniform random value (a continuous random value between 0 and 1).

Problem 1

Generate 1000 random values r. For each r generated, calculate the random value 𝑿𝑿 by: 𝒙𝒙 = −𝑳𝑳𝑳𝑳(𝒓𝒓), where “Ln“ is the natural logarithm function.

Investigate the probability distribution of X by doing the following:

1. Create a relative frequency histogram of X.

2. Select a probability distribution that, in your judgement, is the best fit for X.

3. Support your assertion above by creating a probability plot for X.

4. Support your assertion above by performing a Chi-squared test of best fit with a 0.05 level of significance.

5. In the word document, describe your methodologies and conclusions.

6. In the word document, explain what you have learned from this experiment.

Hints and Theoretical Background

A popular method for generating random values according to a certain probability distribution is to use the inverse transform method. In this method, the cumulative function of the distribution (F(x)) is used for such a random number generation. More specifically, a standard uniform random value r is generated first. Most software environments are capable of generating such a value. In Excel and R, functions “=RAND()” and “runif()” generate such a value respectively. After r has been created, it

then replaces F(x) in the expression of the cumulative function and the resulting equation is solved for the variable x.

For example, suppose we wish to generate a random value according to the exponential distribution with a certain mean (say μ). The cumulative function for the exponential distribution is:

𝑭𝑭(𝒙𝒙) = 𝟏𝟏 − 𝒆𝒆− 𝟏𝟏 𝝁𝝁 𝒙𝒙

(The quantity 1/μ in the above description is called the rate of the exponential random variable and is denoted by λ.)

Therefore, to generate a random value x that belongs to the exponential distribution with a mean of μ. We first generate a standard uniform value r, then replace F(x) by r in the above expression, and solve the resulting equation for the variable x:

𝒓𝒓 = 𝟏𝟏 − 𝒆𝒆− 𝟏𝟏 𝝁𝝁 𝒙𝒙

𝒆𝒆− 𝟏𝟏 𝝁𝝁 𝒙𝒙 = 𝟏𝟏 − 𝒓𝒓

− 𝟏𝟏 𝝁𝝁

𝒙𝒙 = 𝑳𝑳𝑳𝑳(𝟏𝟏 − 𝒓𝒓)

𝒙𝒙 = −𝝁𝝁 𝑳𝑳𝑳𝑳(𝟏𝟏 − 𝒓𝒓)

The formula above means that if R is a standard uniform random variable, then the random variable X obtained by the expression 𝑿𝑿 = −𝝁𝝁 𝑳𝑳𝑳𝑳(𝟏𝟏 − 𝑹𝑹) will belong to the exponential distribution with an average which is equal to the value of μ. This formula can be simplified as:

𝑿𝑿 = −𝝁𝝁 𝑳𝑳𝑳𝑳(𝑹𝑹)

(Note that If R is a standard uniform random variable, then (1 − 𝑹𝑹) is also standard uniform.)

A special case of the above formula is when 𝝁𝝁 = 𝟏𝟏. This means that a random variable x generated by the formula 𝑿𝑿 = −𝑳𝑳𝑳𝑳(𝑹𝑹)is an exponential random variable with an average of 1 (or, rate=1).

Problem 2

Generate three sets of standard uniform random values, 𝒓𝒓𝟏𝟏, 𝒓𝒓𝟐𝟐and 𝒓𝒓𝟑𝟑, each consisting of 10,000 values. Next, calculate the random value x according to the following formula:

𝒙𝒙 = −𝑳𝑳𝑳𝑳(𝒓𝒓𝟏𝟏𝒓𝒓𝟐𝟐𝒓𝒓𝟑𝟑).

Investigate the probability distribution of X by doing the following:

1. Create a relative frequency histogram of X.

2. Select a probability distribution that, in your judgement, is the best fit for X.

3. Support your assertion above by creating a probability plot for X.

4. Support your assertion above by performing a Chi-squared test of best fit with a 0.05 level of significance.

5. In the word document, describe your methodologies and conclusions.

6. In the word document, explain what you have learned from this experiment.

Hints and Theoretical Background:

This problem is related to a theorem in the probability theory. The theorem states that:

If 𝑿𝑿𝟏𝟏, 𝑿𝑿𝟐𝟐, … , 𝑿𝑿𝑳𝑳are n identical and independent exponential random variables each with a mean of μ, then the random variable obtained by their sum, that is 𝑿𝑿𝟏𝟏 + 𝑿𝑿𝟐𝟐 + … + 𝑿𝑿𝑳𝑳, will have a 𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮(𝑳𝑳,𝝁𝝁) probability distribution, where n is the shape parameter of the Gamma distribution and 𝝁𝝁 = 𝟏𝟏

𝒓𝒓𝑮𝑮𝒓𝒓𝒆𝒆 .

From the Hints and Theoretical Background of Problem 1, we know that if R is a standard uniform random variable, then 𝑿𝑿 = −𝑳𝑳𝑳𝑳(𝑹𝑹) is an exponential random variable with an average of 1. Therefore, if 𝑹𝑹𝟏𝟏 , 𝑹𝑹𝟐𝟐, and 𝑹𝑹𝟑𝟑 are three independent standard uniform random variables, then 𝑿𝑿𝟏𝟏 = −𝑳𝑳𝑳𝑳(𝑹𝑹𝟏𝟏)) , 𝑿𝑿𝟐𝟐 = −𝑳𝑳𝑳𝑳(𝑹𝑹𝟐𝟐), and 𝑿𝑿𝟑𝟑 = −𝑳𝑳𝑳𝑳(𝑹𝑹𝟑𝟑)are three independent and identical (each with a mean of 1) exponential random variables. Thus, according to the theorem above, the random variable formed by their sum, that is �−𝑳𝑳𝑳𝑳(𝑹𝑹𝟏𝟏)� + �−𝑳𝑳𝑳𝑳(𝑹𝑹𝟐𝟐)� + (−𝑳𝑳𝑳𝑳(𝑹𝑹𝟑𝟑)), will belong to the 𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮(𝟑𝟑,𝟏𝟏)probability distribution.

However algebraically,

�−𝑳𝑳𝑳𝑳(𝑹𝑹𝟏𝟏)� + �−𝑳𝑳𝑳𝑳(𝑹𝑹𝟐𝟐)� + �−𝑳𝑳𝑳𝑳(𝑹𝑹𝟑𝟑)� = −�𝑳𝑳𝑳𝑳(𝑹𝑹𝟏𝟏) + 𝑳𝑳𝑳𝑳(𝑹𝑹𝟐𝟐) + 𝑳𝑳𝑳𝑳(𝑹𝑹𝟑𝟑)� = −𝑳𝑳𝑳𝑳( 𝑹𝑹𝟏𝟏𝑹𝑹𝟐𝟐𝑹𝑹𝟑𝟑).

Therefore, if 𝑹𝑹𝟏𝟏 , 𝑹𝑹𝟐𝟐, and 𝑹𝑹𝟑𝟑 are three independent standard uniform random variables between zero and 1, then the random variable X formed by the formula 𝑿𝑿 = −𝑳𝑳𝑳𝑳( 𝑹𝑹𝟏𝟏𝑹𝑹𝟐𝟐𝑹𝑹𝟑𝟑) will belong to the 𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮(𝟑𝟑,𝟏𝟏) probability distribution.

Problem 3

Generate a set of 1000 pairs of standard uniform random values 𝒓𝒓𝟏𝟏and 𝒓𝒓𝟐𝟐. Then perform the following algorithm for each of these 1000 pairs: Let the output of this algorithm be denoted by Y.

Step 1: Generate random values 𝑿𝑿𝟏𝟏 = −𝑳𝑳𝑳𝑳(𝒓𝒓𝟏𝟏) and 𝑿𝑿𝟐𝟐 = −𝑳𝑳𝑳𝑳(𝒓𝒓𝟐𝟐)

Step 2: Calculate 𝒌𝒌 = (𝒙𝒙𝟏𝟏−𝟏𝟏) 𝟐𝟐

𝟐𝟐 . If 𝒙𝒙𝟐𝟐 ≥ 𝒌𝒌, then generate a random number 𝒓𝒓. If 𝒓𝒓 > 𝟎𝟎.𝟓𝟓

accept 𝒙𝒙𝟏𝟏as 𝒀𝒀(that is, let 𝒀𝒀 = 𝒙𝒙𝟏𝟏); otherwise if 𝒓𝒓 ≤ 𝟎𝟎.𝟓𝟓, else accept −𝒙𝒙𝟏𝟏 as 𝒀𝒀 (that is, let 𝒀𝒀 = −𝒙𝒙𝟏𝟏).

If 𝒙𝒙𝟐𝟐 < 𝒌𝒌, no result is obtained, and the algorithm returns to step 1. This means that the algorithm skips the pair 𝒓𝒓𝟏𝟏 and 𝒓𝒓𝟐𝟐 for which 𝒙𝒙𝟐𝟐 < 𝑲𝑲 without generating any result and moves to the next pair 𝒓𝒓𝟏𝟏 and𝒓𝒓𝟐𝟐.

After repeating the above algorithm 1000 times, a number N of the Y values will be generated. Obviously 𝑵𝑵 ≤ 𝟏𝟏𝟎𝟎,𝟎𝟎𝟎𝟎𝟎𝟎 since there will be instances when a pair 𝒓𝒓𝟏𝟏 and 𝒓𝒓𝟐𝟐 would not generate any result, and consequently that pair would be wasted.

Investigate the probability distribution of 𝒀𝒀 by doing the following:

1. Create a relative frequency histogram of 𝒀𝒀.

2. Select a probability distribution that, in your judgement, is the best fit for 𝒀𝒀.

3. Support your assertion above by creating a probability plot for 𝒀𝒀.

4. Support your assertion above by performing a Chi-squared test of best fit with a 0.05 level of significance.

5. In the word document, describe your methodologies and conclusions.

6. In the word document, explain what you have learned from this experiment.

Hints and Theoretical Background

Other than the inverse transform method used for generating random values that are according to a certain particular probability distribution, a second applied method for generating random values is the Rejection algorithm. The details of this algorithm are explained below:

Suppose we wish to generate random values x that is according to a certain probability distribution with 𝒇𝒇(𝒙𝒙)as its probability density function (pdf). Also suppose that the following two conditions are satisfied

(i) we are able to generate random values y that belong to a probability distribution whose probability density function is 𝒈𝒈(𝒚𝒚),

(ii) there exists a positive constant C such that 𝒇𝒇(𝒚𝒚) 𝒈𝒈(𝒚𝒚)

≤ 𝑪𝑪 for all y values (this means

that the ratio (𝒇𝒇(𝒚𝒚) 𝒈𝒈(𝒚𝒚)

) is always bounded and does not grow indefinitely. This

condition is almost always satisfied for any two probability density functions 𝒇𝒇(𝒙𝒙) and 𝒈𝒈(𝒚𝒚)).

The rejection algorithm can now be implemented as follows:

Step 1: Generate a random value y that belongs to the probability distribution with 𝒈𝒈(𝒚𝒚) as its pdf and generate a standard uniform random value r.

Step 2: Evaluate 𝒌𝒌 = 𝒇𝒇(𝒚𝒚) 𝑪𝑪 𝒈𝒈(𝒚𝒚)

. If 𝒓𝒓 ≤ 𝒌𝒌, then accept y as the random variable x (that is, let 𝒙𝒙 =

𝒚𝒚); otherwise return to Step1 and try another pair of (𝒚𝒚 , 𝒓𝒓) values.

A few remarks about the Rejection algorithm is worth noting:

1. The probability that the generated y value will be accepted as x, is: 𝒇𝒇(𝒚𝒚) 𝑪𝑪 𝒈𝒈(𝒚𝒚)

. This is the

reason why the algorithm uses a standard uniform value r and accepts y as x if 𝒓𝒓 ≤ 𝒇𝒇(𝒚𝒚) 𝑪𝑪 𝒈𝒈(𝒚𝒚)

.

2. Each iteration of the algorithm will independently result in an accepted value with a probability equal to: 𝑷𝑷�𝒓𝒓 ≤ 𝒇𝒇(𝒚𝒚)

𝑪𝑪 𝒈𝒈(𝒚𝒚) � = 𝟏𝟏

𝑪𝑪 . Therefore, the number of iterations needed

to generate one accepted y value follows a geometric probability distribution with mean C.

Relevancy of Problem 3 to the Rejection Algorithms:

In problem 3, the random variable y , selected from an exponential probability distribution with rate =1 and a pdf of 𝒈𝒈(𝒚𝒚) = 𝒆𝒆−𝒚𝒚, is used to first generate the absolute

value of a standard normal random variable x (|𝒙𝒙|has the pdf: 𝒇𝒇(𝒙𝒙) = 𝟐𝟐 √𝟐𝟐𝟐𝟐

𝒆𝒆− 𝒙𝒙𝟐𝟐

𝟐𝟐 ), and

then assign positive or negative signs to this value (through a standard uniform variable r) in order to obtain a standard normal random value. It can be shown algebraically that 𝒇𝒇(𝒚𝒚) 𝒈𝒈(𝒚𝒚)

= �𝟐𝟐𝒆𝒆 𝟐𝟐

𝒆𝒆 − (𝒚𝒚−𝟏𝟏)𝟐𝟐

𝟐𝟐 ≤ �𝟐𝟐𝒆𝒆 𝟐𝟐

for all y values (note that 𝒆𝒆 −(𝒚𝒚−𝟏𝟏)𝟐𝟐

𝟐𝟐 ≤ 𝟏𝟏 for all y values). Therefore,

the constant C in the assumptions of the algorithm can be chosen to be: 𝑪𝑪 = �𝟐𝟐𝒆𝒆 𝟐𝟐 ≈

𝟏𝟏.𝟑𝟑𝟏𝟏𝟓𝟓. Therefore, 𝒇𝒇(𝒚𝒚) 𝑪𝑪 𝒈𝒈(𝒚𝒚)

= 𝒆𝒆 − (𝒚𝒚−𝟏𝟏)𝟐𝟐

𝟐𝟐 . Hence the following algorithm can be used to generate

the absolute value of a standard normal random variable:

Step 1: Generate random variables Y and R; with Y being exponential with 𝒓𝒓ate=1, and R being uniform on (𝟎𝟎,𝟏𝟏)

Step 2: If 𝑹𝑹 ≤ 𝒆𝒆 − (𝒚𝒚−𝟏𝟏)𝟐𝟐

𝟐𝟐 , then accept Y as the random variable X (that is, set 𝑿𝑿 = 𝒀𝒀); otherwise return to Step1 and try another pair of (𝒀𝒀 ,𝑹𝑹) values.

Note that in step 2 of the above algorithm, the condition 𝑹𝑹 ≤ 𝒆𝒆 − (𝒚𝒚−𝟏𝟏)𝟐𝟐

𝟐𝟐 is mathematically

equivalent to: −𝑳𝑳𝑳𝑳(𝑹𝑹) ≤ (𝒚𝒚−𝟏𝟏) 𝟐𝟐

𝟐𝟐 . However, we have already seen in the Hints and

Theoretical Backgrounds of the earlier problems that if R is standard uniform, then −𝑳𝑳𝑳𝑳(𝑹𝑹) is exponential with rate=1. Therefore, the algorithm for generating the absolute value of the standard normal random variable can be modified as follows:

Step 1: Generate independent exponential random variables 𝒀𝒀𝟏𝟏 and 𝒀𝒀𝟐𝟐; each with 𝒓𝒓ate=1.

Step 2: Evaluate 𝒌𝒌 = (𝒚𝒚𝟏𝟏−𝟏𝟏) 𝟐𝟐

𝟐𝟐 2. If 𝒌𝒌 ≤ 𝒀𝒀𝟐𝟐, then accept 𝒀𝒀𝟏𝟏 as the random variable X (that is,

set 𝑿𝑿 = 𝒀𝒀𝟏𝟏); otherwise return to Step1 and try another pair of (𝒀𝒀𝟏𝟏 , 𝒀𝒀𝟐𝟐) values.

In fact, it is the above version of the Rejection algorithm that is being implemented in Problem 3. However, in order to obtain a standard normal random value (instead of its absolute value), the step 2 of the above algorithm has been modified as follows:

Step 2: Evaluate 𝒌𝒌 = (𝒚𝒚𝟏𝟏−𝟏𝟏) 𝟐𝟐

𝟐𝟐 . If 𝒌𝒌 ≤ 𝒀𝒀𝟐𝟐, then generate a standard uniform variable R. If

𝑹𝑹 ≥ 𝟎𝟎.𝟓𝟓, set 𝑿𝑿 = 𝒀𝒀𝟏𝟏, otherwise set 𝑿𝑿 = −𝒀𝒀𝟏𝟏. If 𝒌𝒌 > 𝒀𝒀𝟐𝟐, return to step 1 and try another pair of (𝒀𝒀𝟏𝟏 , 𝒀𝒀𝟐𝟐) values.

Note: The standard normal random value generated by the Rejection algorithm can be used to generate any normal random value with a mean μ and a standard deviation σ. Once a standard normal variable Z has been generated, it suffices to evaluate 𝝁𝝁 + 𝝈𝝈𝝈𝝈 to generate the desired normal variable.

Problem 4

In the algorithm of problem #3 above, there are instances when the generated random values do not satisfy the condition 𝒙𝒙𝟐𝟐 ≥ 𝒌𝒌 In order to obtain an acceptable value for 𝒀𝒀. In such cases, the algorithm returns to step 1 and generates another two values to check for acceptance. Let 𝑴𝑴 be the number of iterations needed to generate 𝑵𝑵 of the accepted 𝒀𝒀 values (𝑴𝑴 ≥ 𝑵𝑵). Let 𝑾𝑾 = 𝑴𝑴

𝑵𝑵 .

(For example, suppose that the algorithm has produced 700 𝒀𝒀 values (𝑵𝑵 = 𝟕𝟕𝟎𝟎𝟎𝟎) after 1000 iterations (𝑴𝑴 = 𝟏𝟏𝟎𝟎𝟎𝟎𝟎𝟎). Then 𝑾𝑾 = 𝟏𝟏𝟎𝟎𝟎𝟎𝟎𝟎

𝟕𝟕𝟎𝟎𝟎𝟎 = 𝟏𝟏.𝟒𝟒𝟑𝟑. This means that it takes the algorithm

1.43 iterations to produce one output. In fact, 𝑾𝑾 itself is a random variable. Theoretically, 𝑬𝑬(𝑾𝑾) - the expected value (i.e., average) of 𝑾𝑾 – of an algorithm is a measure of efficiency of that algorithm.)

Investigate 𝑾𝑾 by the following sequence of exploratory data analytic methods:

1. Estimate the expected value and the standard deviation of 𝑾𝑾.

2. Select a probability distribution that, in your judgement, is the best fit for 𝑾𝑾.

3. Support your assertion above by performing a Chi-squared test of best fit with a 0.05 level of significance.

4. As the number of iterations 𝑴𝑴 becomes larger, the values 𝑾𝑾 will approach a certain limiting value. Investigate this limiting value of 𝑾𝑾 by completing the following table and plotting 𝑾𝑾 versus 𝑴𝑴. What value do you propose for the limiting value that 𝑾𝑾 approaches to?

M W

10

20

30

40

50

60

70

80

90

100

200

300

400

500

600

700

800

900

1000

5. In the word document, communicate to the reader your findings about 𝑾𝑾.

6. In the word document, explain what you have learned from this experiment.

Summary

In the word document, summarize and conceptualize your findings in parts 1 – 4 above by filling the blanks in the sentences below:

1. If 𝒓𝒓 is a standard uniform random variable, then −𝑳𝑳𝑳𝑳(𝒓𝒓) has the ___________________ probability distribution.

2. The sum of three independent and identically distributed _________________ random variables has the ________________________ probability distribution.

3. The output of the algorithm of problem 3 has a ______________________ probability distribution.

4. In step 2 of the algorithm of problem 3, random variables 𝑿𝑿𝟏𝟏 and 𝑿𝑿𝟐𝟐 , each of whose probability distribution is ________________________ are used to generate a random value 𝒀𝒀 that has the _______________________probability distribution.

5. The random value 𝑾𝑾 that was discussed in problem 4, has the

____________________________ probability distribution. The expected value of 𝑾𝑾 is: __________.

Rubric

Category Exceeds Standard Meets Standards Approaching

Standards Below Standards

Excel (or R): Problem Modeling & Set-up ALY6050-CO1

Completely and concisely modeled the problem in Excel (or R) for each method

Accurately modeled the problem in Excel (or R) for each method

Correctly modeled the problem in Excel (or R) for each method, but the model lacks detailed insight into the problem or the set-up is awkward.

Modeled the problem in Excel (or R) for each method, but there are some gaps in the problem modeling and setup

Excel (or R): Problem Solution & Accuracy ALY6050-CO1

Efficiently obtained correct and accurate solutions in Excel (or R) by using the appropriate analytic tools of the software

Obtained complete and accurate solutions in Excel (or R) by using the appropriate analytic tools of the software

Obtained correct solutions in Excel (or R) using the appropriate analytic tools of the software, but the application of the tool is awkward.

Obtained a solutions in Excel (or R) by using the appropriate analytic tools of the software, but the solution is not complete.

Word/Report: Problem Description & Introduction ALY6050-CO1

Provides a thorough and concise summary of the problem descriptions and introduced the problem using rich and significant ideas

Provides an accurate and succinct summary of the problem descriptions and problem introduction

Provides an accurate summary of the problem descriptions and problem introduction, but the description is too wordy or not succinct

Provided a summary of the problem descriptions and problem introduction, but it is inaccurate or incomplete

Word/Report: Description of Problem Analysis ALY6050-CO1

Provides a thorough and precise description of the analytic concepts and theories used in analyzing the problem

Accurately describes the analytic concepts and theories used in analyzing the problem

Describes the analytic concepts and theories used in analyzing the problem, but description lacks appropriate detail or precision

Describes the analytical concepts and theories used in analyzing the problem, but descriptions are incorrect or the analytical concepts and theories are incorrect

Word/Report: Description of Conclusions ALY6050-CO1

Provides conclusions and results obtained in the project using a high level of critical thinking and reasoning

Provides relevant conclusions and results obtained in the project that reflect critical thinking and reasoning

Provides conclusions and results obtained in the project, but not all conclusions or results are relevant to the problem or not all conclusions reflect good reasoning

Provides conclusions and results obtained in the project, but they are irrelevant and reflect a lack of critical thinking

Category Exceeds Standard Meets Standards Approaching

Standards Below Standards

Word/Report: Writing Mechanics, Title Page, & References

Completely free of errors in grammar, spelling, and punctuation; and completely correct usage of title page, citations, and references. The report contains a minimum of 1000 words

There are no noticeable errors in grammar, spelling, and punctuation; and completely correct usage of title page, citations, and references. The report contains a minimum of 1000 words

There are very few errors in grammar, spelling, and punctuation; and completely correct usage of title page, citations, and references. The report contains a minimum of 1000 words

There are more than five errors in grammar, spelling, and punctuation; or the usage of title page, citations, and references are incomplete; or the report contains less than 1000 words