R studio and chi-squared distribution
R Questions As with discrete distributions, there are continuous distributions that arise all the time and answer “the common questions of the human experience”. One example is known as the chi-squared distribution. This is actually a whole family of curves, and you specify which curve you want by giving a number known as the “degrees of freedom” (written as df, or k). For example, the graph of the density function for the chi-squared distribution with 12 degrees of freedom is shown below:
The density function for this graph is horrendous (here, k is the degrees of freedom, and the gamma function is a generalization of the factorial symbol to non-integer values!!!):
If we want to find the expected value and standard deviation of this distribution, we will have to do some very difficult integrals. Instead, we will simulate 10,000 values from the distribution and find the mean and standard deviation of those 10,000 values. To do this, read about the rchisq function in R. (Note: the function rchisq is part of a quartet of functions that exist for any distribution. The other quartet members are: dchisq, pchisq, and qchisq. Together, they make up the “d-p-q-r” quartet and allow you to do almost anything you would want with a distribution. The “r” stands for random values, and is what we want to use.)
302520151050
0.09
0.08
0.07
0.06
0.05
0.04
0.03
0.02
0.01
0.00
X
D e n
s it
y
Distribution Plot Chi-Square, df=12
R1. Generate 10,000 random values from the chi-squared distribution with 12 degrees of freedom. What are the mean and standard deviation? [code, answer] R2. Were you surprised by your answers to R1? Perhaps the formulas for the mean and standard deviation of the chi-squared curve with k degrees of freedom are nice and beautiful. Experiment with different values for k, and find formulas (based on the value k) for the mean and standard deviation of the chi-squared distribution with k degrees of freedom. If you are having trouble with the formula for the standard deviation, try to find a formula for the variance first. [code, formulas] R3. Using some approach in R, estimate the probability that the chi-squared distribution with 5 degrees of freedom gives a value greater than 10. [code, estimate of probability]