sim_doctors <- function(num.doctors,num.meetings,starting_adopters, prob) { # vector to keep track of which doctors have adopted has_adopted <- rep(FALSE, num.doctors) # Set some to have adopted initially has_adopted[1:round(starting_adopters*num.doctors)] <- TRUE # matrix to keep track of adoptions over time adoptions_vs_time <- matrix(FALSE,nrow=num.doctors,ncol=num.meetings) for (meeting in 1:num.meetings) { # select 2 doctors at random meeting_pair <- sample(1:num.doctors,size=2,replace=FALSE) # check whether exactly one selected doctor has adopted if(has_adopted[meeting_pair[1]] != has_adopted[meeting_pair[2]]) { # With probability prob., update the vector of adopters if(rbinom(n=1,size=1,prob=prob)) { has_adopted[meeting_pair] <- TRUE } } # update adoptions_vs_time matrix adoptions_vs_time[,meeting] <- has_adopted } return(adoptions_vs_time) } sim1 <- sim_doctors(num.doctors=10,num.meetings=10,starting_adopters=0.1,prob=1.0)