楼主: 八神小弟
7309 9

[问答] 请问如何生成独立同分布的卡方分布或者指数分布数据 [推广有奖]

  • 3关注
  • 0粉丝

大专生

53%

还不是VIP/贵宾

-

威望
0
论坛币
2547 个
通用积分
12.0000
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
2934 点
帖子
35
精华
0
在线时间
61 小时
注册时间
2015-1-15
最后登录
2020-8-7

10论坛币
比如有x1,x2,x3,...x10总共10个随机变量均服从同一卡方分布并且相互独立,并且对每个随机变量取样30,请问如何生成满足这些条件的数据?(即最后的数据是一个30*10的样本数据矩阵)

最佳答案

suzhzh 查看完整内容

If you use R, then it is quite easy. Like x
关键词:卡方分布 指数分布 随机变量 样本数据 样本数 如何
抱怨没有用,只有不断
沙发
suzhzh 发表于 2016-7-5 19:37:46 |只看作者 |坛友微信交流群
If you use R, then it is quite easy. Like
x<-matrix(nrow=30, ncol=10, byrow=FALSE)#define the structure to store the data
for (i in 1:10){x[,i]=rchisq(30, 1,1)}#x from Chisquare (1)
x#is what you wanted

使用道具

藤椅
suzhzh 发表于 2016-7-6 18:41:42 |只看作者 |坛友微信交流群
If you use sas, then PROC IML works as below:
PROC IML;
   call randseed(1234);
   x=j(30, 10);*30 row, 10 columns;
   call randgen (x, "CHISQ", 5 );**Chi-squre with freedom as 5, center parameter as 0;
   print x;
quit;

        

使用道具

板凳
八神小弟 发表于 2016-7-6 19:44:40 |只看作者 |坛友微信交流群
suzhzh 发表于 2016-7-6 18:14
If you use R, then it is quite easy. Like
x
谢谢你的回复,看了之后我有如下问题:
(1)程序for (i in 1:30){x[,1]=rchisq(30, 1,1)}中for (i in 1:30)对于x好像没有起到循环作用
(2)这样生成的数据能满足两两独立吗?你的意思是对{x[,1]=rchisq(30, 1,1)}循环10次是吗?这样能得到这10次的数据是独立的吗?

使用道具

报纸
suzhzh 发表于 2016-7-6 19:55:43 |只看作者 |坛友微信交流群
八神小弟 发表于 2016-7-6 19:44
谢谢你的回复,看了之后我有如下问题:
(1)程序for (i in 1:30){x[,1]=rchisq(30, 1,1)}中for (i in 1 ...
Typos, 1 should be i.

Yes, they are independent.

使用道具

地板
八神小弟 发表于 2016-7-6 20:37:50 |只看作者 |坛友微信交流群
suzhzh 发表于 2016-7-6 19:55
Typos, 1 should be i.

Yes, they are independent.
谢谢你的回复,问题如下
(1)for (i in 1:30){x[,1]=rchisq(30, 1,1)}是否应该改为for (i in 1:10){x[,i]=rchisq(30, 1,1)},这样就会生成10列数据,每列数据容量为30
(2)为什么这样能保证两两独立?我不是很理解,能否给予详细的解释,谢谢。

使用道具

7
suzhzh 发表于 2016-7-6 21:02:11 |只看作者 |坛友微信交流群
八神小弟 发表于 2016-7-6 20:37
谢谢你的回复,问题如下
(1)for (i in 1:30){x[,1]=rchisq(30, 1,1)}是否应该改为for (i in 1:10){x[, ...
1) Yes, I think I made another error.
2) Suggest you to read some books about the randomization umber generation.

使用道具

8
八神小弟 发表于 2016-7-6 21:25:43 |只看作者 |坛友微信交流群
suzhzh 发表于 2016-7-6 21:02
1) Yes, I think I made another error.
2) Suggest you to read some books about the randomization  ...
谢谢你的回复,我有2个问题
(1)若我有这样的程序(把10个变量简化成2个变量)
x1<-rchisq(30,1,1)
x2<-rchisq(30,1,1)
这样生成的x1,x2独立吗?
(2)能推荐几本写随机数生成的书吗?或者有关随机数生成(我没有百度到我想要的东西)
谢谢

使用道具

9
suzhzh 发表于 2016-7-7 09:34:43 |只看作者 |坛友微信交流群
八神小弟 发表于 2016-7-6 21:25
谢谢你的回复,我有2个问题
(1)若我有这样的程序(把10个变量简化成2个变量)
x1
For the 1) question, the answer is Yes.
for the 2) question, I have no list to recommend, but I would like you to google and you may get something. Many thanks.

使用道具

10
八神小弟 发表于 2016-7-7 13:37:35 |只看作者 |坛友微信交流群
suzhzh 发表于 2016-7-7 09:34
For the 1) question, the answer is Yes.
for the 2) question, I have no list to recommend, but I  ...
谢谢你的耐心解答,学习的路还有很长,希望能不断的进步,谢谢

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-21 17:00