What happens when I call rchisq(100,1:100,1:100)
:
- does R generate 100 numbers with d开发者_如何学Cf=1,ncp=1?
- or does it generate 100 numbers each with df=k,ncp=k for k=1...100?
What I want to know is whether df and ncp can be vectors or not. It is not clear in the documentation (when compared with rnorm). I suspect that they can also be vectors and recycling happens if the lengths differ(?)
Just test it by using set.seed()
:
R> set.seed(42); rchisq(2, 1:2, 1:2) # base case
[1] 8.676 1.653
R> set.seed(42); rchisq(1, 1, 1); rchisq(1, 2, 2) # matches
[1] 8.676
[1] 1.653
R> set.seed(42); rchisq(1, 1, 1); rchisq(1, 1, 1) # does not match
[1] 8.676
[1] 0.5874
so it looks like you get N draws using degrees of freedom and non-centrality from the corresponding value in the supplied vector.
Viewed another way, recycling as actually the rules as scalar values for df
and ncp
get recycled to vector length which makes some sense.
精彩评论