开发者

Calling rchisq with vector parameters

开发者 https://www.devze.com 2022-12-24 11:12 出处:网络
What happens when I call rchisq(100,1:100,1:100): does R generate 100 numbers with d开发者_如何学Cf=1,ncp=1?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号