I have this for loop that i need to repeat (like 1000 times), and count the number of times the p.value is higher the some value. I think I have the counting part under control, but I just can't figure out how to repeat the loop to get a output that i can use.
leads <-list(lead_one, lead_two, lead_three, lead_four, lead_five, lead_six, lead_seven, lead_eight, lead_nine, lead_ten)
for(i in 1:length(leads)){
(ks.test(sample(lead_en, 75), sample(leads[[i]], 75)))$p.value
}
Help?
Update (update #2: code should be reproducible now):
I’m sorry for not providing enough informations, I’m new to programming, and brand new to asking for help about programming. Let me try again. I want to run the ks.test on a vector of lead times (lead_en) vs. all the vectors of lead times in "leads". This I can do with the for loop posted above. Then I would like to run this for loop a number of times to count the times of a certain outcome.
I’ ve tried (without counter):
lead_en <- c(4, 5, 3, 4, 5, 6, 7, 3, 4, 2, 3)
lead_one <- c(3, 4, 5, 2, 2, 5, 7, 8, 3, 2, 6)
lead_two <- c(4, 2, 5, 6, 3, 1, 5, 7, 5)
lead_three <- c(4, 3, 5, 5, 6, 7, 9, 9, 3, 3, 3)
lead_four <- c(5, 3, 5, 6, 3, 4, 5, 6)
lead_five <- c(4, 5, 3, 5, 6)
lead_six <- c(2, 3, 6, 9, 9, 5, 5, 6, 7, 4, 3, 3)
lead_seven <- c(3, 4, 5, 5, 6, 3, 3)
lead_eight <- c(2, 3, 3, 3, 3, 4, 5)
lead_nine <- c(5, 6, 7, 3, 3, 4)
lead_ten <- c(5, 3, 4, 5, 6, 7, 7)
leads <-list(lead_one, lead_two, lead_three, lead_four, lead_five, lead_six, lead_seven, lead_eight, lead_nine, lead_ten)
d <- 100 # number of replications
res = matrix(rep(0, nrow=10, ncol=d))
for (k in 1:length(d)){
for(i in 1:length(leads)){
res[i, k] <- print(ks.test(sample(lead_en, 75), sample(leads[[i]], 75)))$p.value
}
}
Which does not work. I hope this clarifies what I’m trying to do.