Reputation: 23
I would like to generate data following chi-square distribution with N=30 population. However I don't know if it is correct:
dchisq(1, df = 1:30)
# [1] 2.419707e-01 3.032653e-01 2.419707e-01 1.516327e-01 8.065691e-02
# [6] 3.790817e-02 1.613138e-02 6.318028e-03 2.304483e-03 7.897535e-04
# [11] 2.560537e-04 7.897535e-05 2.327761e-05 6.581279e-06 1.790585e-06
# [16] 4.700913e-07 1.193723e-07 2.938071e-08 7.021903e-09 1.632262e-09
# [21] 3.695738e-10 8.161308e-11 1.759875e-11 3.709686e-12 7.651632e-13
# [26] 1.545702e-13 3.060653e-14 5.945009e-15 1.133575e-15 2.123217e-16
Upvotes: 1
Views: 5762
Reputation: 123
If you would like to generate 30 random Chi-Squared variables, you need to use the rchisq()
function.
rchisq(n, df, ncp = 0)
So you would replace n
with 30 and the df
with the number of degrees of freedom you require. You can read more here.
Upvotes: 8