Chi-squared Goodness of Fit Test (R Required)
See attach file and use R to establish graphs and reports; Code needed
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
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 generatio
n 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
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