Search code examples
rfunctionchi-squared

How do you generate 50 observations of 10 chi^2 (that's \chi square") distributed variables with 50 degrees of freedom?


I am trying to generate 50 observations of 10 chi^2 distributed variables with 50 degrees of freedom. Then I have to create a new variable, which is the average of each of these 10 chi^2 distributed variables and create a histogram of this variable (this will be a sample of 10 observations). Any ideas?


Solution

  • rchisq(10, 50) will generate 10 random numbers with 50 degrees of freedom from a chi-squared distribution. We can do 50 replications of that, then take the mean of each. Or we can just create 50 * 10 observations, and split them up into sets of 10. After that just run hist for a histogram.

    obs <- matrix(rchisq(50 * 10, 50), nrow = 10)
    hist(colMeans(obs))
    

    enter image description here