作者KevinXII ()
看板Statistics
标题[问题] 有关R的simulation
时间Tue Dec 11 11:41:08 2007
在Project中的R code遇到一点问题
题目是
You are to do a simulation study (using 1000 simulation) of various
randomization schemes and compare their abilities to balance patient
characteristics. The designs are:
(1) Simple randomization ("flip a coin")
(2) Blocked randomization with blocks of size 6
(3) Biased coin design
a. with p=2/3
b. with p=3/4
The performance of each of the schemes is to be assessed in a study of two
treatment (A and B) randomly assigned to 300 subjects in which
(a) 25% of the population is male; 75% of the population is female;
(b) 40% of the population is considered "high risk"; 60% of the population
is considered "low risk"
我写了一段程式
treat <- rbinom(300, 1, 0.5)
gender <- rbinom(300, 1, 0.75)
risk <- rbinom(300, 1, 0.40)
但是不知道怎麽样做1000次的simulation
请各位高手帮帮忙 谢谢@@"
题目有点长 不好意思
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 69.137.222.195
1F:推 chien533:我没看原文题目,但假设你是要把一千次模拟出来的结果存 12/12 02:42
2F:→ chien533:出来,那可以简单地用下面这个程式码: 12/12 02:43
3F:→ chien533:treat<-matrix(0,nrow=300,ncol=1000) 12/12 02:43
4F:→ chien533:for(i in 1:1000){ 12/12 02:44
5F:→ chien533:set.seed(i) 12/12 02:44
6F:→ chien533:treat[,i]<-rbinom(300,1,0.5) 12/12 02:44
7F:→ chien533:} 12/12 02:44
8F:→ KevinXII:感谢 帮助很大~~~ 12/12 09:41