#This program will fit the best two-parameter models for each period and return the value of #estimated betas and sigmas and -2 log likelihood for each period #Also, the -2 log likelihood for each period will be summed over all four periods to get a final value of -2 log likelihood full.data<-matrix(scan("E:/GeneralGamma/fulldata.dat"), ncol=9,byrow=T) #fulldata.dat is file with full data on nine variables for 2314 records, need to update path #9 variables: publicID entry exit event p1 p2 p3 p4 period1234 # #Density Function for the Generalized Gamma Distribution dggamma <- function(beta, sigma, lambda, timet) { s <- lambda^(-2) r <- s * exp(( - beta * lambda)/sigma) # consider timet below exp(-500) at exp(-500) to avoid division by zero timet[timet0)*((b*(timet^(b-1))*dgamma(timet^b, shape=s, rate=r))) dens <- dens+(lambda<0)*((-b*(timet^(b-1))*dgamma(timet^b, shape=s, rate=r))) dens } #Survival Function for the Generalized Gamma Distribution sggamma <- function(beta, sigma, lambda, timet) { s <- lambda^(-2) r <- s * exp(( - beta * lambda)/sigma) # consider timet below exp(-500) at exp(-500) to avoid division by zero timet[timet0)*(1-pgamma(timet^b, shape=s, rate=r)) surv <- surv+(lambda<0)*pgamma(timet^b, shape=s, rate=r) surv[surv