function(bypass1 = 0) { #Begin program project() # #All inputs defined globally, set by input utility programs. #bypass = 1 bypasses calculation of lamda.f and lamda.m, allowing exogenously #specified values. # for(t in 1:(tt - 1)) { # #BEGIN UPDATE CALCULATIONS FOR YEAR t # # #SECTION 1: COMPUTE NUMBERS OF DEATHS AND MOVEMENTS # # #numbers of inactive females dying or becoming active # force.sum <- mu.f[, t] + upsilon.f[, t] # factor <- (xf[, t] * (1 - exp( - force.sum)))/force.sum xdf[, t] <- factor * mu.f[, t] # xyf[, t] <- factor * upsilon.f[, t] # # force.sum <- mu.m[, t] + upsilon.m[, t] # factor <- (xm[, t] * (1 - exp( - force.sum)))/force.sum # xdm[, t] <- factor * mu.m[, t] # xym[, t] <- factor * upsilon.m[, t] # # # #numbers of active females dying, becoming inactive, or becoming infected # # #lamda.f, lamda.m # pi <- sum(zm[, , t])/(sum(zm[, , t]) + sum(ym[, t])) # lamda.f[, t] <- iota.f[, t] + (kappa.f + theta.f[, t]) * pi # pi <- sum(zf[, , t])/(sum(zf[, , t]) + sum(yf[, t])) # lamda.m[, t] <- iota.m[, t] + (kappa.m + theta.m[, 1]) * pi # # # #numbers active who die, become active, or become infected # force.sum <- mu.f[, t] + tau.f[, t] + lamda.f[, t] # factor <- (yf[, t] * (1 - exp( - force.sum)))/force.sum # ydf[, t] <- factor * mu.f[, t] # yxf[, t] <- factor * tau.f[, t] # # #print(c(sum(force.sum), sum(factor), sum(yxf[, t]))) ################## yzf[, t] <- factor * lamda.f[, t] # # force.sum <- mu.m[, t] + tau.m[, t] + lamda.m[, t] # factor <- (ym[, t] * (1 - exp( - force.sum)))/force.sum # ydm[, t] <- factor * mu.m[, t] # yxm[, t] <- factor * tau.m[, t] # # #print(c(sum(force.sum), sum(factor), sum(yxm[, t]))) #################### yzm[, t] <- factor * lamda.m[, t] # # # #numbers infected who die of non-HIV related or of HIV-related causes # force.sum <- array(data = mu.f[, t], dim = c(aa, dd)) + alpha[, , t] # factor <- (zf[, , t] * (1 - exp( - force.sum)))/force.sum # zdf[, , t] <- factor * array(data = mu.f[, t], dim = dim(factor)) # zaf[, , t] <- factor * alpha[, , t] # # force.sum <- array(data = mu.m[, t], dim = c(aa, dd)) + alpha[, , t] # factor <- (zm[, , t] * (1 - exp( - force.sum)))/force.sum # zdm[, , t] <- factor * array(data = mu.m[, t], dim = dim(factor)) # zam[, , t] <- factor * alpha[, , t] # # # #numbers of births, uinfected and infected, break out by sex # ybirths <- sum(yf[, t] * beta.y[, t]) # zbirths <- sum(apply(zf[, , t], 1, sum) * beta.z[, t]) # # ubirths <- ybirths + (1 - zeta[t]) * zbirths # ibirths <- zeta[t] * zbirths # # ubf[t] <- sigma.f * ubirths # ubm[t] <- sigma.m * ubirths # ibf[t] <- sigma.f * ibirths # ibm[t] <- sigma.m * ibirths # # # #deaths of uninfected births, by sex # ubdf[t] <- ubf[t] * (1 - exp( - mu.fb[t])) # ubdm[t] <- ubm[t] * (1 - exp( - mu.mb[t])) # # # #deaths of infected births, by sex, from non-HIV-related and HIV-related causes # force.sum <- mu.fb[t] + alpha.b[t] # factor <- (1 - exp( - force.sum))/force.sum # # ibdf[t] <- ibf[t] * factor * mu.fb[t] # ibaf[t] <- ibf[t] * factor * alpha.b[t] # # force.sum <- mu.mb[t] + alpha.b[t] # factor <- (1 - exp( - force.sum))/force.sum # # ibdm[t] <- ibm[t] * factor * mu.mb[t] # ibam[t] <- ibm[t] * factor * alpha.b[t] # # # #SECTION 2: UPDATE ARRAYS FROM t TO t+1 # # #inactive population age > 0 # xf[2:aa, t + 1] <- xf[1:(aa - 1), t] - (xdf[1:(aa - 1), t] + xyf[1:(aa - 1), t]) + yxf[1:(aa - 1), t] # xm[2:aa, t + 1] <- xm[1:(aa - 1), t] - (xdm[1:(aa - 1), t] + xym[1:(aa - 1), t]) + yxm[1:(aa - 1), t] # # # #active uninfected population age > 0 # yf[2:aa, t + 1] <- yf[1:(aa - 1), t] - (ydf[1:(aa - 1), t] + yxf[1:(aa - 1), t] + yzf[1:(aa - 1), t]) + xyf[1:(aa - 1), t] # ym[2:aa, t + 1] <- ym[1:(aa - 1), t] - (ydm[1:(aa - 1), t] + yxm[1:(aa - 1), t] + yzm[1:(aa - 1), t]) + xym[1:(aa - 1), t] # # # #infected population duration 0, age > 0 # zf[2:aa, 1, t + 1] <- yzf[1:(aa - 1), t] # zm[2:aa, 1, t + 1] <- yzm[1:(aa - 1), t] # # # #infected population of duration > 0, age > 0 # zf[2:aa, 2:dd, t + 1] <- zf[1:(aa - 1), 1:(dd - 1), t] - (zdf[1:(aa - 1), 1:(dd - 1), t] + zaf[1:(aa - 1), 1:(dd - 1), t]) zm[2:aa, 2:dd, t + 1] <- zm[1:(aa - 1), 1:(dd - 1), t] - (zdm[1:(aa - 1), 1:(dd - 1), t] + zam[1:(aa - 1), 1:(dd - 1), t]) # # # #update age = 0 (inactive and infected only) # xf[1, t + 1] <- ubf[t] - ubdf[t] # xm[1, t + 1] <- ubm[t] - ubdm[t] # zf[1, 1, t + 1] <- ibf[t] - (ibdf[t] + ibaf[t]) # zm[1, 1, t + 1] <- ibm[t] - (ibdm[t] + ibam[t]) # # # #END UPDATE CALCULATIONS FOR YEAR t } # # #WRITE OUTPUT TO GLOBAL ARRAYS # # #birth, death and movement arrays # xdf <<- xdf # xdm <<- xdm # xyf <<- xyf # xym <<- xym # # ydf <<- ydf # ydm <<- ydm # yxf <<- yxf # yxm <<- yxm # yzf <<- yzf # yzm <<- yzm # # zdf <<- zdf # zdm <<- zdm # zaf <<- zaf # zam <<- zam # # ubf <<- ubf # ubm <<- ubm # # ubdf <<- ubdf # ubdm <<- ubdm # # ibf <<- ibf # ibm <<- ibm # # ibdf <<- ibdf # ibdm <<- ibdm # # ibaf <<- ibaf # ibam <<- ibam # # # #population state arrays # xf <<- xf # xm <<- xm # yf <<- yf # ym <<- ym # zf <<- zf # zm <<- zm # # # #forces of new infection lamda # lamda.f <<- lamda.f # lamda.m <<- lamda.m # # #end program project() # #write ascii copy to d:\aidsmodel\splustxt\project.txt # write.ascii(project) "All done" }