#This program will fit the saturated Generalized Gamma regression model and return the value of #estimated betas, estimated sigmas, estimated lambdas, 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 for the #saturated model 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 # m2loglikgralgamma<-function(para) { beta <- para[1] sigma <- para[2] lambda <- para[3] #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