作者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