# Simulating a dataset with different event rates by a covariate

I want to simulate a dataset with 100 patients each in a 2 arms trial (trt=A, B). Let say the follow-up time is 100 days. Between day 50 and day 100, there will an expected event rate of toxicity of treatment of lamba= 0.05 in both treatment A and B. I want to assign a value of 1 to a patient when it occurs.

In another simulation, I will vary the event rate to 0.1 in A while maintaining the rate as 0.05 in B and perform some calculations. I think actually what I needed was a time-to-failure simulation but will be happy to know your suggestions. This is my earlier attempt to generate the data for trt A using a binomial distribution. The final dataset had too many events when transposed.

SUBJ=100
VISITS=100

sample<- array(data=NA, dim = c(VISITS,SUBJ))
for(subj in 1:SUBJ ){
for(tj in c(1:VISITS)){

p0 = 0
p1 = 0.05
p2 = 0.7
p <- ifelse( tj %in% c(1:49) , p0, ifelse(tj %in% c(50:100), p1, p2))
sample[tj,subj] <- rbinom(1, 1, p)
}
}

colnames(sample) <-  c(1001:(1000+SUBJ))
rownames(sample) <- as.character(1:VISITS)
sample1<- t(sample)