Entering edit mode
3.1 years ago
Hien
•
0
Hello everyone,
I have a question related to set.seed()
functions in R environment. The question is as below:
set.seed(547) # **If this is commented, every run gives you different p-value. why?**
gene=800 # Notice that we pick another gene
NUMPERMS=1e4
permstats=c() # Need to initialize
for(i in 1:NUMPERMS) {
permsample = sample(1:38, size=27, replace=FALSE)
data1 = golub[gene, permsample]
data2 = golub[gene, -permsample]
permstats[i] = t.test(data1, data2)$statistic
}
## Actual t-statistic for gene at position 800
ts = t.test(golub[800, 1:27], golub[800, 28:38])$statistic
ts
hist(permstats)
abline(v=ts, col='red')
## Calculating the p-value
p_value = mean(ts < abs(permstats))
p_value
What is the function of set.seed(547)
in here? Normally, to remain the consistent, I use set.seed(111)
for running.
it's a random number (seed) and 547 has no special meaning there. Using the same seed helps in reproducing the results of a code. Since the code uses
sample
function, following is an example, how random sampling can be reproduced with using seed:Thank you for your help! I get the idea.